コード例 #1
0
ファイル: Program.cs プロジェクト: jenspettersson/Generation
        private static void GameLoop(DiceGame diceGame)
        {
            diceGame.StartGame();
            Console.WriteLine($"First roll is: {diceGame.CurrentRoll}");

            while (true)
            {
                Console.Write($"Press UP to guess higher and DOWN to guess lower: ");
                var  guess  = Console.ReadKey();
                bool result = false;
                switch (guess.Key)
                {
                case ConsoleKey.UpArrow:
                    result = diceGame.GuessHigher();
                    break;

                case ConsoleKey.DownArrow:
                    result = diceGame.GuessLower();
                    break;

                default:
                    WriteLine("\nYou have to press UP or DOWN", ConsoleColor.DarkYellow);
                    continue;
                }

                Console.WriteLine($"\nLast roll was: {diceGame.CurrentRoll}");

                if (!diceGame.IsRunning)
                {
                    break;
                }

                if (result)
                {
                    WriteLine("You guessed right!", ConsoleColor.Green);
                }
                else
                {
                    WriteLine("Result was same as last", ConsoleColor.Yellow);
                }
            }
        }
 public void SetUp()
 {
     _diceGame = new DiceGame(new FakeDice(4, 4));
     _diceGame.StartGame();
     _diceGame.GuessHigher();
 }