Ajout de la persistance pour la carte villageois dans ConsoleApp
continuous-integration/drone/push Build is passing Details

Persistance
Loris OBRY 2 years ago
parent 00f030887b
commit 5b285829d1

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

@ -3,6 +3,7 @@ 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;
@ -10,31 +11,26 @@ using static System.Console;
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} ");
foreach (int i in tab) var serializer = new DataContractSerializer(typeof(Carte));
using (Stream s = File.Create(xmlFile))
{ {
Console.Write($"{i} "); serializer.WriteObject(s, villageois);
} }
Console.WriteLine();
} }
} }
} }

@ -0,0 +1 @@
<carte xmlns="http://schemas.datacontract.org/2004/07/Model" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><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>

@ -21,9 +21,14 @@ namespace Model
} }
[DataMember] [DataMember]
private readonly string nom; public string Nom {
[DataMember] get => nom;
public string Nom => nom; set {
nom = value;
OnPropertyChanged(nom);
}
}
private string nom;
[DataMember] [DataMember]
public string Description { public string Description {
get => description; get => description;
@ -78,7 +83,7 @@ namespace Model
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));
} }
@ -91,7 +96,7 @@ 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() public override int GetHashCode()
@ -102,7 +107,7 @@ namespace Model
if (object.ReferenceEquals(right, null)) return false; if (object.ReferenceEquals(right, null)) return false;
if (object.ReferenceEquals(right, this)) return true; if (object.ReferenceEquals(right, this)) return true;
if (this.GetType() != right.GetType()) return false; if (this.GetType() != right.GetType()) return false;
return this.Equals(right); return this.Equals(right as Carte);
} }
public bool Equals(Carte other) public bool Equals(Carte other)

Loading…
Cancel
Save