using System; using System.Collections.Generic; using System.Runtime.CompilerServices; namespace BasicComputerGames.Bagels { public class Game : GameBase { public void GameLoop() { DisplayIntroText(); int points = 0; do { var result =PlayRound(); if (result) ++points; } while (TryAgain()); Console.WriteLine(); Console.WriteLine($"A {points} point Bagels buff!!"); Console.WriteLine("Hope you had fun. Bye."); } private const int Length = 3; private const int MaxGuesses = 20; private bool PlayRound() { var secret = BagelNumber.CreateSecretNumber(Length); Console.WriteLine("O.K. I have a number in mind."); for (int guessNo = 1; guessNo <= MaxGuesses; ++guessNo) { string strGuess; BagelValidation isValid; do { Console.WriteLine($"Guess #{guessNo}"); strGuess = Console.ReadLine(); isValid = BagelNumber.IsValid(strGuess, Length); PrintError(isValid); } while (isValid != BagelValidation.Valid); var guess = new BagelNumber(strGuess); var fermi = 0; var pico = 0; (pico, fermi) = secret.CompareTo(guess); if(pico + fermi == 0) Console.Write("BAGELS!"); else if (fermi == Length) { Console.WriteLine("You got it!"); return true; } else { PrintList("Pico ", pico); PrintList("Fermi ", fermi); } Console.WriteLine(); } Console.WriteLine("Oh, well."); Console.WriteLine($"That's {MaxGuesses} guesses. My Number was {secret}"); return false; } private void PrintError(BagelValidation isValid) { switch (isValid) { case BagelValidation.NonDigit: Console.WriteLine("What?"); break; case BagelValidation.NotUnique: Console.WriteLine("Oh, I forgot to tell you that the number I have in mind has no two digits the same."); break; case BagelValidation.WrongLength: Console.WriteLine($"Try guessing a {Length}-digit number."); break; case BagelValidation.Valid: break; } } private void PrintList(string msg, int repeat) { for(int i=0; i