From 582abdf7c7ce95ca9a493013f6683fa53d533b8e Mon Sep 17 00:00:00 2001 From: Leana BESSON Date: Thu, 11 May 2023 11:02:33 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20m=C3=A9thode=20RechercherEspece,=20Rech?= =?UTF-8?q?ercherRace,=20SelectionnerRace.=20Modification=20SelectionnerEs?= =?UTF-8?q?pece?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Solution/Wikipet's/Model/Espece.cs | 66 ++++++++++++++++++++++-- Solution/Wikipet's/Model/Especetheque.cs | 30 +++++++---- Solution/Wikipet's/Model/Race.cs | 22 ++++---- 3 files changed, 93 insertions(+), 25 deletions(-) diff --git a/Solution/Wikipet's/Model/Espece.cs b/Solution/Wikipet's/Model/Espece.cs index 1179416..0ec7739 100644 --- a/Solution/Wikipet's/Model/Espece.cs +++ b/Solution/Wikipet's/Model/Espece.cs @@ -36,11 +36,15 @@ namespace Model internal void AffficherListeRace() { Console.WriteLine("\nLISTE DES RACES : "); - foreach (Race race in ListeRaces) + if (ListeRaces != null) { - Console.WriteLine("\t" + race.Nom + " (" + race.NomScientifique + ")"); + foreach (Race race in ListeRaces) + { + Console.WriteLine("\t" + race.Nom + " (" + race.NomScientifique + ")"); + } + Console.WriteLine("\n"); } - Console.WriteLine("\n"); + else Console.WriteLine("\tAucune race connue.\n"); } public void AfficherEspece() @@ -51,7 +55,61 @@ namespace Model Console.WriteLine("\tPoids moyen : " + PoidsMoyen); Console.WriteLine("\tTaille moyenne : " + TailleMoyenne); - AffficherListeRace(); + 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) + { + foreach (Race race in ListeRaces) + { + if (race.Nom == choix) + { + return race; + } + } + 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"); + } + } } } } diff --git a/Solution/Wikipet's/Model/Especetheque.cs b/Solution/Wikipet's/Model/Especetheque.cs index 2339f0c..0fbb440 100644 --- a/Solution/Wikipet's/Model/Especetheque.cs +++ b/Solution/Wikipet's/Model/Especetheque.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -26,28 +27,37 @@ namespace Model Console.WriteLine("\n"); } + public Espece? RechercherEspece(string choix) + { + foreach (Espece espece in ListeEspeces) + { + if (espece.Nom == choix) + { + return espece; + } + } + return null; + } + public void SelectionnerEspece() { Console.Clear(); - AfficherListeEspece(); string choix = ""; while (choix != "-1") { + AfficherListeEspece(); + Console.Write("\n\tEntrer le nom de l'espèce à sélectionner (-1 pour annuler) : "); choix = Console.ReadLine(); - bool trouver = false; - foreach (Espece espece in ListeEspeces) + Espece espece = RechercherEspece(choix); + + if (espece != null) { - if (espece.Nom == choix) - { - espece.AfficherEspece(); - trouver = true; - } + espece.AfficherEspece(); } - - if(!trouver) Console.WriteLine("\tChoix incorrect"); + else Console.WriteLine("\tChoix incorrect"); } } } diff --git a/Solution/Wikipet's/Model/Race.cs b/Solution/Wikipet's/Model/Race.cs index 4797ef3..6771a76 100644 --- a/Solution/Wikipet's/Model/Race.cs +++ b/Solution/Wikipet's/Model/Race.cs @@ -37,17 +37,17 @@ namespace Model public void AfficherRace() { - Console.WriteLine("Nom : " + Nom); - Console.WriteLine("Nom scientifique : " + NomScientifique); - Console.WriteLine("Espérance de vie : " + EsperanceVie); - Console.WriteLine("Poids moyen : " + PoidsMoyen); - Console.WriteLine("Taille moyenne : " + TailleMoyenne); - Console.WriteLine("Comportement : " + Comportement); - Console.WriteLine("Sante : " + Sante); - Console.WriteLine("Education : " + Education); - Console.WriteLine("Entretien : " + Entretien); - Console.WriteLine("Cout : " + Cout); - Console.WriteLine("Conseil : " + Conseil); + 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("\tSante : " + Sante); + Console.WriteLine("\tEducation : " + Education); + Console.WriteLine("\tEntretien : " + Entretien); + Console.WriteLine("\tCout : " + Cout); + Console.WriteLine("\tConseil : " + Conseil + "\n\n"); } } }