using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Runtime.InteropServices.JavaScript.JSType; namespace Model { public class Espece { public string Nom { get; } public string NomScientifique { get; } public string Image { get; } public string EsperanceVie { get; } public string PoidsMoyen { get; } public string TailleMoyenne { get; } public HashSet? ListeRaces { get; } = new HashSet(); public string Comportement { get; } public string Sante { get; } public string Education { get; } public string Entretien { get; } public string Cout { get; } public string Conseil { get; } public Espece(string nom = "", string nomScientifique = "", string image = "", string esperanceVie = "", string poidsMoyen = "", string tailleMoyenne = "", HashSet? races = null, string comportement = "", string sante = "", string education = "", string entretien = "", string cout = "", string conseil = "") { Nom = nom; NomScientifique = nomScientifique; Image = image; EsperanceVie = esperanceVie; PoidsMoyen = poidsMoyen; TailleMoyenne = tailleMoyenne; ListeRaces = races; Comportement = comportement; Sante = sante; Education = education; Entretien = entretien; Cout = cout; Conseil = conseil; } internal void AffficherListeRace() { Console.WriteLine("\nLISTE DES RACES : "); if (ListeRaces != null) { foreach (Race race in ListeRaces) { Console.WriteLine("\t" + race.Nom + " (" + race.NomScientifique + ")"); } Console.WriteLine("\n"); } else Console.WriteLine("\tAucune race connue.\n"); } public void AfficherEspece() { Console.WriteLine("\n" + Nom); Console.WriteLine("\tNom scientifique : " + NomScientifique); Console.WriteLine("\tEspérance de vie : " + EsperanceVie); Console.WriteLine("\tPoids moyen : " + PoidsMoyen); Console.WriteLine("\tTaille moyenne : " + TailleMoyenne); Console.WriteLine("\tComportement : " + Comportement); Console.WriteLine("\tSanté : " + Sante); Console.WriteLine("\tEducation : " + Education); Console.WriteLine("\tEntretien : " + Entretien); Console.WriteLine("\tCout : " + Cout); Console.WriteLine("\tConseil : " + Conseil); AffficherListeRace(); while (true) { Console.WriteLine("\n\t1- Sélectionner une race"); Console.WriteLine("\t9- Retour"); Console.Write("\n\tEntrer votre choix : "); int decision = Convert.ToInt32(Console.ReadLine()); switch (decision) { case 1: SelectionnerRace(); break; case 9: return; default: Console.WriteLine("\tChoix incorrect\n"); break; } } } public Race? RechercherRace(string choix) { if (ListeRaces != null && choix != "") { foreach (Race race in ListeRaces) { if (race.Nom == choix) { return race; } } Console.WriteLine("\n"); } return null; } public void SelectionnerRace () { string choix = ""; while (choix != "-1") { Console.Write("\n\tEntrer le nom de la race à sélectionner (-1 pour annuler) : "); choix = Console.ReadLine(); if (choix != "-1") { Race race = RechercherRace(choix); if (race != null) { race.AfficherRace(); } else Console.WriteLine("\tChoix incorrect\n"); } } } } }