From bf055106bb89ab98b85da288cb0b0eb47a019038 Mon Sep 17 00:00:00 2001 From: Augustin AFFOGNON Date: Wed, 26 Oct 2022 16:32:44 +0200 Subject: [PATCH] Console Jeu Individuel --- Sources/BowlingApp/Afficheur.cs | 7 +- Sources/BowlingApp/Match.cs | 87 ++++++++++++++++--- Sources/BowlingApp/bowling.db | Bin 45056 -> 45056 bytes Sources/BowlingMaping/JoueurDbDataManager.cs | 2 +- 4 files changed, 80 insertions(+), 16 deletions(-) diff --git a/Sources/BowlingApp/Afficheur.cs b/Sources/BowlingApp/Afficheur.cs index f3871c1..668c6bd 100644 --- a/Sources/BowlingApp/Afficheur.cs +++ b/Sources/BowlingApp/Afficheur.cs @@ -56,7 +56,12 @@ namespace BowlingApp public static void InviteQuilleTombe(int i) { Console.WriteLine($"Entrez le nombre de quilles tombés du lancer {i}"); - } + } + + public static void InviteNomJoueur(string pseudo) + { + Console.WriteLine($"Tour {pseudo}"); + } #endregion } } diff --git a/Sources/BowlingApp/Match.cs b/Sources/BowlingApp/Match.cs index 4508018..618c45a 100644 --- a/Sources/BowlingApp/Match.cs +++ b/Sources/BowlingApp/Match.cs @@ -56,44 +56,70 @@ namespace BowlingApp manager.AddPartie(partie); } } - } - + } + /// /// Match en Individuel /// /// - public static void JeuIndividuel(Saissiseur saissiseur) + public static async void JeuIndividuel(Saissiseur saissiseur) { // Création des parties pour chaque joueur - Manager manager = new Manager(new EquipeDbDataManager(), new PartieDbDataManager(), new JoueurDbDataManager()); - + Manager manager = new Manager(new EquipeDbDataManager(), new PartieDbDataManager(), new JoueurDbDataManager()); + + Afficheur.InviteNrb("Joueur"); int nbrj = saissiseur.CollecteNbr(); List joueurs = new List(); - - - // Création des joueurs + List partiees = new List(); + bool verit = false; + int nbPartie = 1; // Nombre de partie pour chaque joueur + // Création des joueurs et leur partie for (int j = 0; j < nbrj; j++) { - Afficheur.InviteNom($"Joueur {j + 1}"); + Afficheur.InviteNom($"Joueur {j + 1}"); string nomJoueur = saissiseur.CollecteNom(); Joueur joueur = new Joueur(nomJoueur); + Partie partie = new Partie(joueur); + + joueurs.Add(joueur); + partiees.Add(partie); + // verit = await manager.AddJoueur(joueur); } - + Console.WriteLine(verit); + + for (int p = 0; p < nbPartie; p++) + { + // Lancement pour chaque partie avce 10 frames + for (int j = 0; j < 10; j++) // + { + + for (int i = 0; i < partiees.Count; i++) // on lance les parties à tour de rôle + { + Frame frame = new Frame(j + 1); + Afficheur.InviteNomJoueur(joueurs[i].Pseudo); + LancerFrame(partiees.ElementAt(i), saissiseur, frame); + // await manager.UpdatePartie(joueurs.ElementAt(i).Parties.ElementAt(p)); + + } + } + } for (int i = 0; i < joueurs.Count; i++) { - Partie partie = new Partie(joueurs[i]); - manager.AddJoueur(joueurs[i]); - LancerBoulle(partie, saissiseur); - manager.AddPartie(partie); + joueurs[i].AddPartie(partiees[i]); + verit = await manager.AddJoueur(joueurs[i]); } + + + } + /// /// Match en Solo /// @@ -141,6 +167,39 @@ namespace BowlingApp partie.AddFrame(frame);//ajout du frame à la partie Console.WriteLine(partie.GetScore());//affichage du score à la fin de chaque frame } + } + + + + /// + /// Faire des lancers avec des frames spécifiques + /// + /// + /// + /// + private static void LancerFrame(Partie partie, Saissiseur saissiseur, Frame frame) + { + Afficheur.AfficheNumFrame(frame.Numero); + + Afficheur.InviteQuilleTombe(1); + frame.Lancer(saissiseur.CollectQuilleTomber()); + + if (!frame.IsStrike) + { + Afficheur.InviteQuilleTombe(2); + frame.Lancer(saissiseur.CollectQuilleTomber()); + } + //Faire le troisième du dernier frame lancer si le premier est un strike ou le deuxième est un spare + if (frame.Numero == 10 && (frame.IsStrike || frame.IsSpare)) + { + Afficheur.InviteQuilleTombe(3); + frame.Lancer(saissiseur.CollectQuilleTomber()); + } + partie.AddFrame(frame);//ajout du frame à la partie + Console.WriteLine(partie.GetScore());//affichage du score à la fin de chaque frame + partie.AddFrame(frame); + + } #endregion } diff --git a/Sources/BowlingApp/bowling.db b/Sources/BowlingApp/bowling.db index ed4a7e814be3a4529470a013210d48ccf0b93a80..7574a630a8e54e44b4545356d477f43a92f82792 100644 GIT binary patch delta 499 zcmZp8z|`=7X~S)QTMjN}W=Tf3qQu-9bK8We!#bMrS4tBLgENT|)z1BQpgZ92v}KJIk?=x z91b9dgUbzx?TW;9L1H^2v7M0Ej!0|=B(^;g+YZFutW^7miP?iMdNO-Mtq9*lzHYu& zzIwh&zGA*yzI47szG$E`5A)ivGBYxAcz{WFFzE&+UBRRam~;k{PGHgzOgex``_0q) zav4Q9_<`a1hyOeOC;qqmFZdtx-{S{|CqF9-GXo>X2~foi T{!2jnck#1?u{}}l1@Negz#GlLW!LQ8s4=DG7Z}Y!A zHb!PUUYW`41+_qt89bY1YF{uh+wo1G%-#SJ5$4-Gy)Tzhh@Jl)1OFfX@BE+m-}1lU pf6RXmD0zZ^^1b8URP(L)!oV diff --git a/Sources/BowlingMaping/JoueurDbDataManager.cs b/Sources/BowlingMaping/JoueurDbDataManager.cs index 69ea32a..000aa9e 100644 --- a/Sources/BowlingMaping/JoueurDbDataManager.cs +++ b/Sources/BowlingMaping/JoueurDbDataManager.cs @@ -67,7 +67,7 @@ namespace BowlingMaping entity.PartieEntities.Add(partieEntity); } context.Joueurs.Add(entity); - result = await context.SaveChangesAsync() == 1; + result = await context.SaveChangesAsync() > 0; } catch (Exception ex) {