//Méthodes d'affichage static void AfficherPersonnel(List <Personnel> maListe) { Console.WriteLine("Voici la liste du personnel :\n"); foreach (Personnel i in maListe) { if (i is Monstre) { Monstre M = i as Monstre; Console.WriteLine(M); } if (i is Sorcier) { Sorcier S = i as Sorcier; Console.WriteLine(S); } } }
static List <Personnel> LecturePersonnel(StreamReader monStreamReader, List <Attraction> liste_attraction) { List <Personnel> liste_personnel = new List <Personnel>(); string ligne = monStreamReader.ReadLine(); //on stock la premiere ligne for (int j = 0; j < 17; j++) // tant qu'il y a pas d'espace vide { string[] temp = ligne.Split(';'); Typesexe type_sex = Typesexe.none; int matricule = -1; try { matricule = int.Parse(temp[1]); } catch (InvalidCastException e) { Console.WriteLine(e.Message); } try { type_sex = (Typesexe)Enum.Parse(typeof(Typesexe), temp[4]); } catch (InvalidCastException e) { Console.WriteLine(e.Message); } int c = -1; Attraction monAttraction = null; if (temp[0] != "Sorcier") { try { c = int.Parse(temp[7]); } catch (FormatException e) { Console.WriteLine(e.Message); } monAttraction = QuelEstAttraction(liste_attraction, c); } switch (temp[0]) { case "Sorcier": grade G = grade.none; try { G = (grade)Enum.Parse(typeof(grade), temp[6]); } catch (InvalidCastException e) { Console.WriteLine(e.Message); } List <string> liste_p = new List <string>(); string[] temp2 = temp[7].Split('-'); for (int i = 0; i < temp2.Length; i++) { liste_p.Add(temp2[i]); } Sorcier monSorcier = new Sorcier(matricule, temp[2], temp[3], type_sex, temp[5], G, liste_p); liste_personnel.Add(monSorcier); break; case "Monstre": int cagnotte_monstre = 0; try { cagnotte_monstre = int.Parse(temp[6]); } catch (InvalidCastException e) { Console.WriteLine(e.Message); } Monstre monMonstre = new Monstre(matricule, temp[2], temp[3], type_sex, temp[5], cagnotte_monstre, monAttraction); liste_personnel.Add(monMonstre); break; case "Demon": int cagnotte_demon = int.Parse(temp[6]); int force = int.Parse(temp[8]); Demon monDemon = new Demon(matricule, temp[2], temp[3], type_sex, temp[5], cagnotte_demon, monAttraction, force); liste_personnel.Add(monDemon); break; case "Fantome": int cagnotte_fantome = int.Parse(temp[6]); Fantome monFantome = new Fantome(matricule, temp[2], temp[3], type_sex, temp[5], cagnotte_fantome, monAttraction); liste_personnel.Add(monFantome); break; case "LoupGarou": int cagnotte_loup = int.Parse(temp[6]); float indiceCruaute = float.Parse(temp[8]); LoupGarou monLoup = new LoupGarou(matricule, temp[2], temp[3], type_sex, temp[5], cagnotte_loup, monAttraction, indiceCruaute); liste_personnel.Add(monLoup); break; case "Vampire": int cagnotte_vamp = int.Parse(temp[6]); float indiceLuminosite = float.Parse(temp[8]); Vampire monVamp = new Vampire(matricule, temp[2], temp[3], type_sex, temp[5], cagnotte_vamp, monAttraction, indiceLuminosite); liste_personnel.Add(monVamp); break; case "Zombie": CouleurZ maCouleur = (CouleurZ)Enum.Parse(typeof(CouleurZ), temp[8]); int degreDecomposition = int.Parse(temp[9]); int cagnotte_zomb = int.Parse(temp[6]); Zombie monZomb = new Zombie(matricule, temp[2], temp[3], type_sex, temp[5], cagnotte_zomb, monAttraction, maCouleur, degreDecomposition); liste_personnel.Add(monZomb); break; } ligne = monStreamReader.ReadLine(); } monStreamReader.Close(); return(liste_personnel); }