private void ButtonPlay_Click(object sender, EventArgs e)
        {
            // Check the text in buttonPlay
            // If it is "New Game", set up a new game for the player
            if (buttonPlay.Text.Equals("New Game"))
            {
                game.StartNewGame();
            }

            // Play new round
            game.PlayRound();

            // Update the round label in NumberGameForm
            labelRound.Text = (game.Round).ToString();

            // Retrieve number list
            numberList = game.NumberList;
            int[] numbers = numberList.Numbers;

            // Show number list on NumberGameForm
            for (int i = 0; i < numberList.Numbers.Length; i++)
            {
                groupLabelNumber.Controls[i].Text = numbers[i].ToString();
            }

            // Get the current round and total score
            int roundScore = game.RoundScore[game.Round - 1];

            labelRoundScore.Text = roundScore.ToString();
            labelTotalScore.Text = game.TotalScore.ToString();

            // Check whether the game is over (after 5 rounds)
            bool gameOver = game.IsGameOver();

            // If the game is over, change the text of buttonPlay to "New Game" and show the ResultForm
            // Otherwise, change buttonPlay to "New Round" as play a new round
            if (gameOver)
            {
                buttonPlay.Text = "New Game";

                ResultForm resultForm = new ResultForm(game);
                resultForm.Show();
            }
            else
            {
                buttonPlay.Text = "New Round";
            }
        }
Exemple #2
0
        static void PlayGame(NumberGame game)
        {
            game.StartNewGame();

            do
            {
                game.PlayRound();
                PrintRoundInfo(game);
                if (game.IsGameOver() == false)
                {
                    do
                    {
                        Console.WriteLine("\nPress 'Enter' to play new round ....");
                    } while (Console.ReadKey().Key != ConsoleKey.Enter);
                }
            } while (game.IsGameOver() == false);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            NumberGame numberGame = new NumberGame();

            int[] nums;

            Console.WriteLine("Welcome to the Number Game!");
            Console.WriteLine("Get a score of 100 or more and you win!");
            Console.WriteLine("Press any key to begin the game.");
            Console.ReadKey();

            for (int i = 0; i < 5; i++)
            {
                nums = numberGame.PlayRound();
                Console.WriteLine(nums[0] + " " + nums[1] + " " + nums[2] + " "
                                  + nums[3] + " " + nums[4]);
                Console.WriteLine("Current Score: " + numberGame.GenerateResult());
                Console.WriteLine("Press any key to continue.");
                Console.ReadKey();
            }

            Console.WriteLine("Your final score is: " + numberGame.GenerateResult());

            if (numberGame.GenerateResult() > 100)
            {
                Console.WriteLine("Congratulations! You Win!");
            }
            else if (numberGame.GenerateResult() == 100)
            {
                Console.WriteLine("Game Draw!");
            }
            else if (numberGame.GenerateResult() < 100)
            {
                Console.WriteLine("You Lose! Try Again.");
            }

            Console.WriteLine("Press any key to close this game.");
            Console.ReadKey();
        }