public static void Run() { int[] guess; Help(); // Game = new MasterMind(new int[4] {0, 4, 3, 1}); while (true) { guess = ParseGuess(); // guess = new int[] {1,1,1,1}; Peg peg = Game.Guess(guess); PrintBordLine(guess, peg); if (peg.Won()) { Console.WriteLine("Congratulation you won"); break; } else if (Game.GuessCount == Game.RowCount) { Console.WriteLine("You Lost"); // foreach(int color in Game.Secret) { // Console.Write(color); // } Console.WriteLine("{0} was the answer", guessStr); break; } } Console.WriteLine("you spend {0} guesses", Game.GuessCount); }
public Peg Guess(int[] guess) { if (Status != GameStatus.Ongoing) { string msg = String.Format("Game Over, you have {0}", Status.ToString()); throw new MasterMindGameOverException(msg); } Entry newGuess = new Entry(guess, ColorCount); Peg newPeg = new Peg(newGuess, secret); Bord[GuessCount] = newGuess; Pegs[GuessCount] = newPeg; GuessCount++; if (newPeg.Won()) { Status = GameStatus.Won; } else if (GuessCount == RowCount) { Status = GameStatus.Lost; } return(newPeg); }