Merge remote-tracking branch 'origin/Persistance'

master
Loris OBRY 2 years ago
commit c42ce1290d

@ -11,4 +11,8 @@
<ProjectReference Include="..\Model\Model.csproj" /> <ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Persistance\" />
</ItemGroup>
</Project> </Project>

@ -3,38 +3,38 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Schema; using System.Xml.Schema;
using static System.Console; using static System.Console;
using System.Runtime.Serialization.Json;
using System.Xml;
namespace ConsoleApp namespace ConsoleApp
{ {
internal class FileName class Program
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
/* int a = 0; Carte villageois = new Carte("Villageois", "Il peut seulement voter", "Il doit se concentrer sur les autres joueurs", 2, "villageois", "La carte de base");
int[] tab = new int[3] { 1, 2, 3 }; Carte loup_garou = new Carte("Loup-Garou", "Il peut se reveiller chaque nuit pour voter avec les autres de son clan qui ils vont manger", "Il doit se faire passer pour un role du village, voter pour un de ses compagnons pour gagner la confiance peut etre un moyen", 4, "loup-garou", "Le loup-garou est un rôle très appréciable à jouer");
int[] tab2 = new int[tab.Length];
tab.CopyTo(tab2, 0);
tab2[1] = 0;
DisplayTab("Tableau 1 :", tab);
DisplayTab("Tableau 2 :", tab2);
*/
Carte C = new Carte("Villageois", "Aucuns", "Doit voter inteligemment", null, "lien", "une carte peu apprécié mais necesaire"); Carte voyante = new Carte("Voyante", "La voyante est capable de voir le role d'un joueur, et ce, chaque nuit", "Elle ne doit pas se faire découvrir, surtout en debut de partie, donner des indices subtiles sans braquer tout les soupçons des loup-garou vers vous est l'objectif", 4, "villageois", "Une carte tres interessante et difficile a la fois, ce role emmene souvent à faire des sacrifices");
} string relativePath = "..\\..\\..\\Persistance";
static void DisplayTab(string name, int[] tab)
{ string xmlFile = Path.Combine(relativePath, "villageois.xml");
Console.Write($"{name} "); XmlWriterSettings settings = new XmlWriterSettings() { Indent = true };
foreach (int i in tab) var serializer = new DataContractSerializer(typeof(Carte));
using (TextWriter tw = File.CreateText(xmlFile))
{ {
Console.Write($"{i} "); using (XmlWriter writer = XmlWriter.Create(tw, settings))
{
serializer.WriteObject(writer, villageois);
}
} }
Console.WriteLine();
} }
} }
} }

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<carte xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Model">
<Description>La carte de base</Description>
<LienImage>villageois</LienImage>
<Nom>Villageois</Nom>
<Note>2</Note>
<Pouvoir>Il peut seulement voter</Pouvoir>
<Strategie>Il doit se concentrer sur les autres joueurs</Strategie>
</carte>

@ -55,4 +55,8 @@
<ProjectReference Include="..\Model\Model.csproj" /> <ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Persistance\" />
</ItemGroup>
</Project> </Project>

@ -6,9 +6,12 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.ComponentModel; using System.ComponentModel;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Net.Http.Headers;
using System.Runtime.Serialization;
namespace Model namespace Model
{ {
[DataContract(Name = "carte")]
public class Carte : INotifyPropertyChanged public class Carte : INotifyPropertyChanged
{ {
public event PropertyChangedEventHandler? PropertyChanged; public event PropertyChangedEventHandler? PropertyChanged;
@ -17,8 +20,16 @@ namespace Model
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
} }
private readonly string nom; [DataMember]
public string Nom => nom; public string Nom {
get => nom;
set {
nom = value;
OnPropertyChanged(nom);
}
}
private string nom;
[DataMember]
public string Description { public string Description {
get => description; get => description;
set { set {
@ -27,6 +38,7 @@ namespace Model
} }
} }
private string description; private string description;
[DataMember]
public string Pouvoir { public string Pouvoir {
get => pouvoir; get => pouvoir;
set set
@ -36,6 +48,7 @@ namespace Model
} }
} }
private string pouvoir; private string pouvoir;
[DataMember]
public string Strategie public string Strategie
{ {
get => strategie; get => strategie;
@ -46,7 +59,7 @@ namespace Model
} }
} }
private string strategie; private string strategie;
private int? note; [DataMember]
public int? Note public int? Note
{ {
get get
@ -63,12 +76,14 @@ namespace Model
OnPropertyChanged(nameof(Note)); OnPropertyChanged(nameof(Note));
} }
} }
private int? note;
[DataMember]
public string LienImage public string LienImage
{ {
get => lienImage; get => lienImage;
set set
{ {
if (!string.IsNullOrEmpty(lienImage)) lienImage = "notfound"; if (string.IsNullOrEmpty(value)) lienImage = "notfound";
else lienImage = value; else lienImage = value;
OnPropertyChanged(nameof(LienImage)); OnPropertyChanged(nameof(LienImage));
} }
@ -81,7 +96,23 @@ namespace Model
this.pouvoir = pouvoir; this.pouvoir = pouvoir;
this.strategie = strategie; this.strategie = strategie;
this.note = note; this.note = note;
this.lienImage = LienImage; this.lienImage = lienImage;
}
public override int GetHashCode()
=> Nom.GetHashCode();
public override bool Equals(object right)
{
if (object.ReferenceEquals(right, null)) return false;
if (object.ReferenceEquals(right, this)) return true;
if (this.GetType() != right.GetType()) return false;
return this.Equals(right as Carte);
}
public bool Equals(Carte other)
{
return (this.nom == other.nom);
} }
} }
} }

Loading…
Cancel
Save