From 5fb07c1b3ff3bb1cfcfe5454b2bb4e091d132049 Mon Sep 17 00:00:00 2001 From: Benjamin BACHELARD Date: Thu, 27 Apr 2023 11:58:33 +0200 Subject: [PATCH] benjamin, ajout liste animaux, liste espece, ajout animaux --- essai1/Console/Console.csproj | 1 - essai1/Console/Program.cs | 73 +++++++++++++++++++++++++++++++++-- essai1/Model/Animal.cs | 10 +---- essai1/Model/Espece.cs | 17 +++++++- essai1/Model/System.cs | 18 ++++++--- 5 files changed, 99 insertions(+), 20 deletions(-) diff --git a/essai1/Console/Console.csproj b/essai1/Console/Console.csproj index b4654f0..6abd0f7 100644 --- a/essai1/Console/Console.csproj +++ b/essai1/Console/Console.csproj @@ -8,7 +8,6 @@ - diff --git a/essai1/Console/Program.cs b/essai1/Console/Program.cs index 95223db..a1d06cd 100644 --- a/essai1/Console/Program.cs +++ b/essai1/Console/Program.cs @@ -1,4 +1,5 @@ using Model; +using System.Runtime.InteropServices; namespace MyProject; class Program @@ -16,7 +17,7 @@ class Program { Console.WriteLine("Menus principal"); Console.WriteLine("1- Les espèces"); - Console.WriteLine("2- Le animaux"); + Console.WriteLine("2- Vos animaux"); Console.WriteLine("9- Quitter"); Console.Write("Entrer votre choix : "); @@ -51,6 +52,7 @@ class Program switch (choix) { case 1: + afficherEspece(); break; case 9: return; @@ -64,7 +66,7 @@ class Program { Console.WriteLine("Menus des animaux"); Console.WriteLine("1- Afficher les animaux"); - Console.WriteLine("2- "); + Console.WriteLine("2- Ajouter des animaux"); Console.WriteLine("9- Quitter"); Console.Write("Entrer votre choix : "); @@ -73,6 +75,10 @@ class Program switch (choix) { case 1: + afficherAnimaux(); + break; + case 2: + ajouterAnimaux(); break; case 9: return; @@ -82,6 +88,67 @@ class Program } } + + + + + + + + private static void afficherAnimaux() + { + HashSet listeAnimaux = new HashSet(); + listeAnimaux.Add(new("pouet")); + listeAnimaux.Add(new("stella")); + Console.WriteLine(); + foreach (Animal listeAnimau in listeAnimaux) + { + Console.WriteLine(listeAnimau.Nom); + } + } + private static void ajouterAnimaux() + { + HashSet listeAnimaux = new HashSet(); + afficherEspece(); + Console.Write("ecrir le nom de l'animal de votre choix (ou R pour retour) :"); + string nom = Convert.ToString(Console.ReadLine()); + if (nom == "R") + return; + Console.WriteLine(nom); + + Console.Write("ecrir le prenom de l'animal (ou R pour retour) :"); + string nomAnimal = Convert.ToString(Console.ReadLine()); + + listeAnimaux.Add(new(nomAnimal)); + afficherAnimaux(); + } + + private static void afficherEspece() + { + HashSet listeEspece = new HashSet(); + listeEspece.Add(new("chien")); + listeEspece.Add(new("chat")); + listeEspece.Add(new("furet")); + listeEspece.Add(new("poisson")); + listeEspece.Add(new("hamster")); + Console.WriteLine(); + foreach (Espece lEspece in listeEspece) + { + Console.WriteLine(lEspece.Nom); + } + Console.WriteLine(); + Console.Write("ecrir le nom de l'espece pour plus d'info (ou R pour retour) :"); + string nom = Convert.ToString(Console.ReadLine()); + if (nom == "R") + return; + Console.WriteLine(nom); + + } + + + + + private static void testdebase() { HashSet animaux = new HashSet(); @@ -89,8 +156,8 @@ class Program animaux.Add(new("Chat", "Les chats sont les meilleurs animaux pour faire de la ronron thérapie.")); animaux.Add(new("Hamster", "Les hamster meurent facilement.")); - Race boxer = new("Boxer"); + //chien.afficherInfoUtile(); } diff --git a/essai1/Model/Animal.cs b/essai1/Model/Animal.cs index 6f7da51..9f70040 100644 --- a/essai1/Model/Animal.cs +++ b/essai1/Model/Animal.cs @@ -15,15 +15,7 @@ namespace Model } - public void AfficherlisteRace() - { - /* - for (int i = 0; i < nb_animal; i++) { - Console.WriteLine(Nom); - } - */ - } - public void afficherInfoUtile() + public void afficherInfo() { Console.WriteLine(Info); } diff --git a/essai1/Model/Espece.cs b/essai1/Model/Espece.cs index f9de2f1..05603a5 100644 --- a/essai1/Model/Espece.cs +++ b/essai1/Model/Espece.cs @@ -9,8 +9,8 @@ namespace Model public class Espece { public string Nom { get; set; } - public string Info { get; set; } - public string Conseil { get; set; } + public string Info; + public string Conseil; public HashSet Races { get; set; } = new HashSet(); public Espece(string nom, string info = "Aucune information", string conseil = "Aucun conseil") @@ -19,5 +19,18 @@ namespace Model Info = info; Conseil = conseil; } + /* + public static void ListeInfo() + { + Console.WriteLine(Nom); + Console.WriteLine(Info); + Console.WriteLine(Conseil); + + Console.WriteLine(); + foreach (Race lRaces in Races) + { + Console.WriteLine(lRaces.Nom); + } + }*/ } } diff --git a/essai1/Model/System.cs b/essai1/Model/System.cs index 8740ca9..cba22f8 100644 --- a/essai1/Model/System.cs +++ b/essai1/Model/System.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Drawing; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -12,13 +13,13 @@ namespace Model { public bool theme_color = true; HashSet listeAnimaux = new HashSet(); - //HashSet listeAnimaux = new HashSet(); - public System() { } + + HashSet listeEspece = new HashSet(); + + public void ChangeColor() { - if (theme_color == true) - theme_color = false; - else theme_color = true; + theme_color = !theme_color; } public void RechercheAnimal(string nom) { @@ -28,6 +29,13 @@ namespace Model return; } + } + public void AfficherListeAnimaux() { + foreach (Animal aAnimal in listeAnimaux) + { + Console.WriteLine(aAnimal); + } + } public void Retour() {