From 4533fcd7f962849513de186ab4d7ee330832b14d Mon Sep 17 00:00:00 2001
From: HUONG THOMAS <thomas.huong@etu.unistra.fr>
Date: Tue, 30 Mar 2021 11:50:48 +0200
Subject: [PATCH] genererMots

---
 fichier1/fichier1/Model/Partie.cs | 36 +++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/fichier1/fichier1/Model/Partie.cs b/fichier1/fichier1/Model/Partie.cs
index 3bb0a3c..0c38885 100644
--- a/fichier1/fichier1/Model/Partie.cs
+++ b/fichier1/fichier1/Model/Partie.cs
@@ -1,23 +1,42 @@
-using System;
+using fichier1.Data;
+using System;
 using System.Collections.Generic;
+using System.Linq;
 using System.Text;
 
 namespace fichier1.Model
 {
-    class Partie
+    public class Partie : IObservable<MainForm>
     {
         private  List<string[]> correction;
         private List<string[]> decoupage;
         private int motCourant;
+        private readonly BddContext context;
 
-        public Partie(int nbMots, float complexite)
+        public Partie(int nbMots, float complexite, BddContext context)
         {
-
+            this.context = context;
         }
 
-        public List<string[]> genererMots(int nb, float complexite)
+        public void genererMots(int nb, float complexite)
         {
-            return null;
+            correction = new List<string[]>();
+
+            Random rnd = new Random();
+
+            Prefixe[] prefixe = context.Set<Prefixe>().ToArray();
+            Radical[] radical = context.Set<Radical>().ToArray();
+            Suffixe[] suffixe = context.Set<Suffixe>().ToArray();
+
+            for(int i = 0; i < nb; i++)
+            {
+                string[] mot = new string[3];
+                mot[0] = prefixe[rnd.Next(0, prefixe.Length)].Pre;
+                mot[1] = radical[rnd.Next(0, radical.Length)].Rad;
+                mot[2] = suffixe[rnd.Next(0, suffixe.Length)].Suf;
+
+                correction.Add(mot);
+            }
         }
 
         public void formaterPropositions()
@@ -54,5 +73,10 @@ namespace fichier1.Model
         {
 
         }
+
+        public IDisposable Subscribe(IObserver<MainForm> observer)
+        {
+            throw new NotImplementedException();
+        }
     }
 }
-- 
GitLab