public List <Demon> trierDemonParForce() { List <Demon> listDemon = new List <Demon>(); for (int i = 0; i < toutLePersonnel.Count; i++) { if (toutLePersonnel[i] is Demon) { Demon D = (Demon)toutLePersonnel[i]; listDemon.Add(D); } } listDemon.Sort(delegate(Demon X, Demon Y) { return(X.FORCE.CompareTo(Y.FORCE)); }); return(listDemon); }
private void AjoutD_Click(object sender, RoutedEventArgs e) { int m = 0; Int32.TryParse(MatriculeD.Text, out m); Dem.MATRICULE = m; Dem.NOM = NomD.Text; Dem.PRENOM = PrenomD.Text; Dem.FONCTION = fonctionD.Text; int c = 0; Int32.TryParse((cagnotteD.Text), out c); Dem.CAGNOTTE = c; Dem.AFFECTATION = affectationD.Text; c = 0; Int32.TryParse((ForceD.Text), out c); Dem.FORCE = c; MainWindow.MyVariables.P.AjouterPersonnel(Dem); Dem = new Demon(0, "", "", (TypeSexe)Enum.Parse(typeof(TypeSexe), "male"), "", 0, "", 0); MessageBox.Show("Personnel ajouté !"); }
//Lis un fichier puis convertis les données ou les attractions selon le document données par Mme.Branchet et les types public void LectureFichier(string nomFichier) { StreamReader monStreamReader = new StreamReader(nomFichier); string ligne = monStreamReader.ReadLine(); while (ligne != null) { string[] temp = ligne.Split(';'); if (temp[0] == "Sorcier") { List <string> listeTemp = new List <string>(); listeTemp.Add(temp[7]); Sorcier S = new Sorcier(Convert.ToInt32(temp[1]), temp[2], temp[3], (TypeSexe)Enum.Parse(typeof(TypeSexe), temp[4]), temp[5], (Grade)Enum.Parse(typeof(Grade), temp[6]), listeTemp); toutLePersonnel.Add(S); } else if (temp[0] == "Monstre") { Monstre M = new Monstre(Convert.ToInt32(temp[1]), temp[2], temp[3], (TypeSexe)Enum.Parse(typeof(TypeSexe), temp[4]), temp[5], temp[7], Convert.ToInt32(temp[6])); toutLePersonnel.Add(M); } else if (temp[0] == "Vampire") { Vampire V = new Vampire(Convert.ToInt32(temp[1]), temp[2], temp[3], (TypeSexe)Enum.Parse(typeof(TypeSexe), temp[4]), temp[5], Convert.ToInt32(temp[6]), temp[7], Convert.ToDouble(temp[8])); toutLePersonnel.Add(V); } else if (temp[0] == "Zombie") { Zombie Z = new Zombie(Convert.ToInt32(temp[1]), temp[2], temp[3], (TypeSexe)Enum.Parse(typeof(TypeSexe), temp[4]), temp[5], Convert.ToInt32(temp[6]), temp[7], Convert.ToInt32(temp[9]), (CouleurZ)Enum.Parse(typeof(CouleurZ), temp[8])); toutLePersonnel.Add(Z); } else if (temp[0] == "Demon") { Demon D = new Demon(Convert.ToInt32(temp[1]), temp[2], temp[3], (TypeSexe)Enum.Parse(typeof(TypeSexe), temp[4]), temp[5], Convert.ToInt32(temp[6]), temp[7], Convert.ToInt32(temp[8])); toutLePersonnel.Add(D); } else if (temp[0] == "Fantome") { Fantome F = new Fantome(Convert.ToInt32(temp[1]), temp[2], temp[3], (TypeSexe)Enum.Parse(typeof(TypeSexe), temp[4]), temp[5], Convert.ToInt32(temp[6]), temp[7]); toutLePersonnel.Add(F); } else if (temp[0] == "LoupGarou") { LoupGarou LG = new LoupGarou(Convert.ToInt32(temp[1]), temp[2], temp[3], (TypeSexe)Enum.Parse(typeof(TypeSexe), temp[4]), temp[5], Convert.ToInt32(temp[6]), temp[7], Convert.ToDouble(temp[8])); toutLePersonnel.Add(LG); } else if (temp[0] == "RollerCoaster") { RollerCoaster RC = new RollerCoaster(Convert.ToBoolean(temp[4]), Convert.ToInt32(temp[1]), Convert.ToInt32(temp[3]), temp[2], temp[5], Convert.ToInt32(temp[7]), (TypeCategorie)Enum.Parse(typeof(TypeCategorie), temp[6]), Convert.ToDouble(temp[8])); attractions.Add(RC); } else if (temp[0] == "Spectacle") { List <DateTime> listeTemp = new List <DateTime>(); string[] temp2 = temp[8].Split(' '); for (int k = 0; k < temp2.Length; k++) { listeTemp.Add(Convert.ToDateTime(temp2[k])); } Spectacle Sp = new Spectacle(Convert.ToBoolean(temp[4]), Convert.ToInt32(temp[1]), Convert.ToInt32(temp[3]), temp[2], temp[5], listeTemp, Convert.ToInt32(temp[7]), temp[6]); attractions.Add(Sp); } else if (temp[0] == "DarkRide") { DarkRide Dr = new DarkRide(Convert.ToBoolean(temp[4]), Convert.ToInt32(temp[1]), Convert.ToInt32(temp[3]), temp[2], temp[5], TimeSpan.Parse(temp[6]), Convert.ToBoolean(temp[7])); attractions.Add(Dr); } else if (temp[0] == "Boutique") { Boutique B = new Boutique(Convert.ToBoolean(temp[4]), Convert.ToInt32(temp[1]), Convert.ToInt32(temp[3]), temp[2], temp[5], (TypeBoutique)Enum.Parse(typeof(TypeBoutique), temp[6])); AjouterAttraction((Attraction)B); } ligne = monStreamReader.ReadLine(); } monStreamReader.Close(); //Une fois que tout est créé on ajoute dans les attractions le personnel correspondant for (int i = 0; i < toutLePersonnel.Count(); i++) { for (int j = 0; j < attractions.Count(); j++) { if (toutLePersonnel[i] is Monstre) { if ((toutLePersonnel[i] as Monstre).AFFECTATION == Convert.ToString(attractions[j].Identifiant)) { attractions[j].AjouterEquipe(toutLePersonnel[i] as Monstre); } } } } }
/// <summary> /// Lis un ficher dont le chemin est fourni et en interprete le contenu en creant les personnels et attractions decrit en format CSV /// </summary> /// <param name="chemin">chemin relatif du fichier a lire</param> public void ReadCSV(string chemin) { try { StreamReader monStreamReader = new StreamReader(chemin); string ligne; while ((ligne = monStreamReader.ReadLine()) != null) { string[] temp = ligne.Split(';'); int temp1 = Int32.Parse(temp[1]); if (temp[0] == "Sorcier") { string[] listeValues = temp[7].Split('-'); List <string> powers = new List <string>(); foreach (string value in listeValues) { powers.Add(value); } Sorcier so = new Sorcier(temp1, temp[2], temp[3], temp[4], temp[5], temp[6], powers); AjoutPersonnel(so); } else if (temp[0] == "Boutique" || temp[0] == "RollerCoaster" || temp[0] == "DarkRide" || temp[0] == "Spectacle") { int temp3 = Int32.Parse(temp[3]); bool temp4 = Boolean.Parse(temp[4]); switch (temp[0]) { case "Boutique": Boutique b; if (temp4) { b = new Boutique(temp1, temp[2], temp3, temp4, temp[5], temp[6]); } else { b = new Boutique(temp1, temp[2], temp3, temp4, "", temp[6]); } AjoutAttraction(b);; break; case "RollerCoaster": int temp7_rc = Int32.Parse(temp[7]); float temp8_rc = float.Parse(temp[8]); RollerCoaster rc = new RollerCoaster(temp1, temp[2], temp3, temp4, temp[5], temp[6], temp7_rc, temp8_rc); AjoutAttraction(rc); break; case "Spectacle": int temp7_s = Int32.Parse(temp[7]); List <DateTime> tempList = new List <DateTime>(); string[] listeDate = temp[8].Split(' '); foreach (string value in listeDate) { tempList.Add(DateTime.Parse(value)); } Spectacle sp = new Spectacle(temp1, temp[2], temp3, temp4, temp[5], temp[6], temp7_s, tempList); AjoutAttraction(sp); break; case "DarkRide": TimeSpan temp6_d = TimeSpan.Parse(temp[6]); bool temp7_d = Boolean.Parse(temp[7]); DarkRide dr = new DarkRide(temp1, temp[2], temp3, temp4, temp[5], temp6_d, temp7_d); AjoutAttraction(dr); break; } } else { int temp6 = Int32.Parse(temp[6]); int temp7; try { temp7 = Int32.Parse(temp[7]); } catch (FormatException) { temp7 = -1; } switch (temp[0]) { case "Monstre": foreach (Attraction i in attractions) { if (i.Id == temp7) { Monstre m = new Monstre(temp1, temp[2], temp[3], temp[4], temp[5], temp6, i); AjoutPersonnel(m); } } if (temp7 == -1) { Monstre m = new Monstre(temp1, temp[2], temp[3], temp[4], temp[5], temp6, null); AjoutPersonnel(m); } break; case "Demon": int temp8; try { temp8 = Int32.Parse(temp[8]); } catch (FormatException) { temp8 = -1; } foreach (Attraction i in attractions) { if (i.Id == temp7) { Demon d = new Demon(temp1, temp[2], temp[3], temp[4], temp[5], temp6, i, temp8); //Console.WriteLine(d.ToString()); AjoutPersonnel(d); } } if (temp7 == -1) { Demon d = new Demon(temp1, temp[2], temp[3], temp[4], temp[5], temp6, null, temp8); //Console.WriteLine(d.ToString()); AjoutPersonnel(d); } break; case "Fantome": foreach (Attraction i in attractions) { if (i.Id == temp7) { Fantome f = new Fantome(temp1, temp[2], temp[3], temp[4], temp[5], temp6, i); AjoutPersonnel(f); } } if (temp7 == -1) { Fantome f = new Fantome(temp1, temp[2], temp[3], temp[4], temp[5], temp6, null); AjoutPersonnel(f); } break; case "Zombie": int temp9; try { temp9 = Int32.Parse(temp[9]); } catch (FormatException) { temp9 = -1; } foreach (Attraction i in attractions) { if (i.Id == temp7) { Zombie z = new Zombie(temp1, temp[2], temp[3], temp[4], temp[5], temp6, i, temp[8], temp9); AjoutPersonnel(z); } } if (temp7 == -1) { Zombie z = new Zombie(temp1, temp[2], temp[3], temp[4], temp[5], temp6, null, temp[8], temp9); AjoutPersonnel(z); } break; case "Vampire": float temp8_v; try { temp8_v = float.Parse(temp[8]); } catch (FormatException) { temp8_v = -1; } foreach (Attraction i in attractions) { if (i.Id == temp7) { Vampire v = new Vampire(temp1, temp[2], temp[3], temp[4], temp[5], temp6, i, temp8_v); AjoutPersonnel(v); } } if (temp7 == -1) { Vampire v = new Vampire(temp1, temp[2], temp[3], temp[4], temp[5], temp6, null, temp8_v); AjoutPersonnel(v); } break; case "LoupGarou": float temp8_lg; try { temp8_lg = float.Parse(temp[8]); } catch (FormatException) { temp8_lg = -1; } foreach (Attraction i in attractions) { if (i.Id == temp7) { LoupGarou lg = new LoupGarou(temp1, temp[2], temp[3], temp[4], temp[5], temp6, i, temp8_lg); AjoutPersonnel(lg); } } if (temp7 == -1) { LoupGarou lg = new LoupGarou(temp1, temp[2], temp[3], temp[4], temp[5], temp6, null, temp8_lg); AjoutPersonnel(lg); } break; } } } monStreamReader.Close(); } catch (Exception) { Console.WriteLine("Fichier corrompu"); } }
static void Peuplement(Parc P) { Zombie Z1 = new Zombie(48, "Grave", "Chase", (TypeSexe)Enum.Parse(typeof(TypeSexe), "male"), "neant", 58, "523", 4, (CouleurZ)Enum.Parse(typeof(CouleurZ), "bleuatre")); Zombie Z2 = new Zombie(489, "Debault", "Blaine", (TypeSexe)Enum.Parse(typeof(TypeSexe), "male"), "neant", 148, "428", 9, (CouleurZ)Enum.Parse(typeof(CouleurZ), "bleuatre")); Zombie Z3 = new Zombie(487, "Moore", "Liv", (TypeSexe)Enum.Parse(typeof(TypeSexe), "femelle"), "neant", 189, "623", 1, (CouleurZ)Enum.Parse(typeof(CouleurZ), "grisatre")); Zombie Z4 = new Zombie(4988, "Babineaux", "Dale", (TypeSexe)Enum.Parse(typeof(TypeSexe), "femelle"), "neant", 239, "112", 3, (CouleurZ)Enum.Parse(typeof(CouleurZ), "grisatre")); P.AjouterPersonnel(Z1); P.AjouterPersonnel(Z2); P.AjouterPersonnel(Z3); P.AjouterPersonnel(Z4); Vampire V1 = new Vampire(751, "Cullen", "Edward", (TypeSexe)Enum.Parse(typeof(TypeSexe), "male"), "neant", 489, "623", 0.8); Vampire V2 = new Vampire(759, "Cullen", "Bella", (TypeSexe)Enum.Parse(typeof(TypeSexe), "femelle"), "neant", 51, "428", 0.3); P.AjouterPersonnel(V1); P.AjouterPersonnel(V2); Demon D1 = new Demon(6666, "Hell", "belzebuth", (TypeSexe)Enum.Parse(typeof(TypeSexe), "autre"), "neant", 588, "parc", 5); Demon D2 = new Demon(6667, "Hell", "Lucifer", (TypeSexe)Enum.Parse(typeof(TypeSexe), "male"), "neant", 22, "684", 1); P.AjouterPersonnel(D1); P.AjouterPersonnel(D2); LoupGarou LG1 = new LoupGarou(7896, "black", "jacob", (TypeSexe)Enum.Parse(typeof(TypeSexe), "male"), "neant", 555, "684", 5); LoupGarou LG2 = new LoupGarou(7896, "White", "Seth", (TypeSexe)Enum.Parse(typeof(TypeSexe), "male"), "neant", 499, "parc", 4); P.AjouterPersonnel(LG1); P.AjouterPersonnel(LG2); Fantome F1 = new Fantome(1, "XIV", "louis", (TypeSexe)Enum.Parse(typeof(TypeSexe), "male"), "neant", 1200, "parc"); Fantome F2 = new Fantome(88999, "hallyday", "johnny", (TypeSexe)Enum.Parse(typeof(TypeSexe), "male"), "neant", 2, "684"); P.AjouterPersonnel(F1); P.AjouterPersonnel(F2); List <string> P1 = new List <string>(); P1.Add("maitrise des elements"); P1.Add("parle aux animaux"); Sorcier S1 = new Sorcier(789, "apprentie", "Sabrina", (TypeSexe)Enum.Parse(typeof(TypeSexe), "femelle"), "neant", (Grade)Enum.Parse(typeof(Grade), "giga"), P1); P.AjouterPersonnel(S1); DarkRide DR1 = new DarkRide(true, 125, 3, "Immeuble hanté", "fantome", TimeSpan.Parse("12"), true); DarkRide DR2 = new DarkRide(true, 12465, 3, "camping hanté", "zombie", TimeSpan.Parse("12"), true); P.AjouterAttraction(DR1); P.AjouterAttraction(DR2); RollerCoaster R1 = new RollerCoaster(true, 36987, 4, "super hulk", "zombie", 12, (TypeCategorie)Enum.Parse(typeof(TypeCategorie), "assise"), 128); RollerCoaster R2 = new RollerCoaster(false, 387, 3, "Space mountain", "neant", 9, (TypeCategorie)Enum.Parse(typeof(TypeCategorie), "bobsleigh"), 111); P.AjouterAttraction(R1); P.AjouterAttraction(R2); Boutique B1 = new Boutique(false, 48, 1, "souvenirs effrayants", "neant", (TypeBoutique)Enum.Parse(typeof(TypeBoutique), "souvenir")); Boutique B2 = new Boutique(false, 498, 2, "miam miam", "neant", (TypeBoutique)Enum.Parse(typeof(TypeBoutique), "nourriture")); P.AjouterAttraction(B1); P.AjouterAttraction(B2); List <DateTime> listeTemp = new List <DateTime>(); listeTemp.Add(Convert.ToDateTime("10:15")); listeTemp.Add(Convert.ToDateTime("15:15")); Spectacle Sp1 = new Spectacle(true, 789456, 4, "vampires sanglants", "vampire", listeTemp, 200, "bloddy room"); List <DateTime> listeTemp2 = new List <DateTime>(); listeTemp2.Add(Convert.ToDateTime("12:15")); listeTemp2.Add(Convert.ToDateTime("16:15")); Spectacle Sp2 = new Spectacle(true, 789456, 8, "Zombie degoutants", "zombie", listeTemp2, 245, "cimetiere"); P.AjouterAttraction(Sp1); P.AjouterAttraction(Sp2); }