private void ExecuteCommand(PlayerCommand command) { switch (command) { case PlayerCommand.Top: { ScoreBoard.Instance.Print(); break; } case PlayerCommand.Restart: { PlayerHelper.ClearHelp(); this.cheats = 0; this.attempts = 0; Console.WriteLine(); break; } case PlayerCommand.Help: { this.cheats = PlayerHelper.PrintHelp(cheats, generatedNumber); break; } case PlayerCommand.Exit: { break; } case PlayerCommand.Other: if (IsValidInput()) { ProcessGame(); } else { ConsolePrinter.PrintWrongCommandMessage(); } break; default: { throw new InvalidOperationException("Invalid Input Command!"); } } }
public void Start() { PlayerCommand enteredCommand; do { ConsolePrinter.PrintWelcomeMessage(); this.generatedNumber = NumberGenerator.GenerateNumber(); this.isGameFinished = false; do { Console.Write("Enter your guess or command: "); playerInput = Console.ReadLine(); enteredCommand = CommandReader.ReadPlayerInput(playerInput); ExecuteCommand(enteredCommand); }while (enteredCommand != PlayerCommand.Exit && enteredCommand != PlayerCommand.Restart && this.isGameFinished != true); }while (enteredCommand != PlayerCommand.Exit); Console.WriteLine("\nGood bye!"); }
private void ProcessGame() { bool[] isBull = new bool[generatedNumber.Length]; CheckPlayerInputForBull(isBull); int bullsCount = CallculateBullsCount(isBull); int cowsCount = CallculateCowsCount(isBull); this.attempts++; if (bullsCount == generatedNumber.Length) { ConsolePrinter.PrintCongratulateMessage(attempts, cheats); FinishGame(); PlayerHelper.ClearHelp(); this.isGameFinished = true; this.cheats = 0; this.attempts = 0; } else { Console.WriteLine("Wrong number! Bulls: {0}, Cows: {1}", bullsCount, cowsCount); } }