diff --git a/fichier1/fichier1/Model/Partie.cs b/fichier1/fichier1/Model/Partie.cs index 4cc3a31fe3035d99ae0923b8222864b519bf6ada..c13c7ed1b6ab12cff157aed3b87d5e87238502c3 100644 --- a/fichier1/fichier1/Model/Partie.cs +++ b/fichier1/fichier1/Model/Partie.cs @@ -6,16 +6,20 @@ using System.Text; namespace fichier1.Model { - public class Partie : IObservable<MainForm> + public class Partie : IObservable<Partie> { private List<string[]> correction; private List<string[]> decoupage; private int motCourant; private readonly BddContext context; + private List<IObserver<Partie>> observers; + public int nbMots; public Partie(int nbMots, float complexite, BddContext context) { + this.nbMots = nbMots; this.context = context; + this.observers = new List<IObserver<Partie>>(); } public void genererMots(int nb, float complexite) @@ -41,42 +45,70 @@ namespace fichier1.Model public void formaterPropositions() { - + decoupage = new List<string[]>(); + for (int i = 0; i < correction.Count; i++) + { + string mot = ""; + for (int j = 0; j < correction[i].Length; j++) + { + mot += correction[i][j]; + } + string[] m = new string[1]; + m[0] = mot; + decoupage.Add(m); + } } public string[] getMot(int nb) { - return null; + return decoupage[nb]; } public void setMot(int nb, string[] mot) { - + decoupage[nb] = mot; } public int compterPoints() { + // TODO: return 0; } public string[] getCorrection(int nb) { - return null; + return correction[nb]; } public string[] getMotCourant() { - return null; + return getMot(motCourant); } public void validerMotCourant(string[] mot) { - + setMot(motCourant, mot); + motCourant++; + if (motCourant < correction.Count) + { + foreach(IObserver<Partie> obs in observers) + { + obs.OnNext(this); + } + } + else + { + foreach (IObserver<Partie> obs in observers) + { + obs.OnCompleted(); + } + } } - public IDisposable Subscribe(IObserver<MainForm> observer) + public IDisposable Subscribe(IObserver<Partie> observer) { - throw new NotImplementedException(); + observers.Add(observer); + return null; } } }