コード例 #1
0
 /// <summary>
 /// Checks the user input to see whether to start a new game or exit
 /// the program.
 /// </summary>
 /// <param name="userInput">The result of the user input.</param>
 private void CheckUserInput(DialogResult userInput)
 {
     if (userInput == DialogResult.Yes)
     {
         form.StartNewGame();
     }
     else
     {
         Application.Exit();
     }
 }
コード例 #2
0
        }//end Game

        /// <summary>
        /// This method updates currentPlayer and CurrentPlayerIndex
        /// and end game is all player finished all combinations
        /// </summary>
        public void NexTurn()
        {
            currentPlayer   = players[(currentPlayerIndex) % players.Count];
            playersFinished = 0;

            form.ShowPlayerName(currentPlayer.Name);
            form.DisableAndClearCheckBoxes();
            form.EnableRollButton();
            numRolls = 1;

            currentPlayer.ShowScores();

            //check end game and finish the game
            foreach (Player player in players)
            {
                if (player.IsFinished())
                {
                    playersFinished++;
                }
            }
            if (playersFinished == players.Count)
            {
                string name       = "";
                int    grandTotal = 0;
                foreach (Player player in players)
                {
                    if (player.GrandTotal > grandTotal)
                    {
                        grandTotal = player.GrandTotal;
                        name       = player.Name;
                    }
                }
                DialogResult newGame = MessageBox.Show("Game has ended and the winner is " + name + ".\nDo you want to start a new game?", "Game finished",
                                                       MessageBoxButtons.YesNo);
                if (newGame == DialogResult.Yes)
                {
                    form.StartNewGame();
                }
                else
                {
                    form.Close();
                }
            }
            currentPlayerIndex++;
        }//end NextTurn
コード例 #3
0
ファイル: Game.cs プロジェクト: schwartz914/CAB201_Yahtzee
        }//END DisableAllButtons

        /// <summary>
        /// Finishes the game and asks if the user wants  to play again
        /// </summary>
        private void FinishGame()
        {
            string text;
            string playerWinners = "";

            if (players.Count > 1)
            {
                int highScore = 0;
                for (int i = 0; i < players.Count; i++)
                {
                    if (players[i].GrandTotal > highScore)
                    {
                        highScore = players[i].GrandTotal;
                    }
                }
                for (int i = 0; i < players.Count; i++)
                {
                    if (players[i].GrandTotal == highScore)
                    {
                        playerWinners += players[i].Name + ", ";
                    }
                }
                text = string.Format("The Winner is {0} with a score of: {1}", playerWinners, highScore);
                MessageBox.Show(text);
            }
            else
            {
                text = string.Format("Congratulations {0}, you finished with a score of: {1}", players[0].Name, players[0].GrandTotal);
                MessageBox.Show(text);
            }
            DialogResult result = MessageBox.Show("Would you like to Play Again?", "Play Again?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                form.StartNewGame();
            }
            else if (result == DialogResult.No)
            {
                MessageBox.Show("Thanks for Playing!");
                Application.Exit();
            }
        }//END FinishGame
コード例 #4
0
        private void FinishGame()
        {
            List <int> scores = new List <int>();

            foreach (Player player in players)
            {
                scores.Add(player.GrandTotal);
            }
            int max   = int.MinValue;
            int index = 0;
            int j     = 0;

            foreach (int s in scores)
            {
                if (s > max)
                {
                    index = j;
                    max   = s;
                }
                j++;
            }
            form.DisableAndClearCheckBoxes();
            form.DisableRollButton();
            for (int i = 0; i < Form1.NUM_BUTTONS + Form1.NUM_TOTALS; i++)
            {
                form.DisableScoreButton((ScoreType)i);
            }
            string builder = (index >= scores.Count) ? string.Format("There was a tie with {0} points.\nPlay Again?", scores.Max()):string.Format("The Winner is {0} with a score of {1},\nPlay Again?", players[index].Name, scores.Max().ToString());

            switch (MessageBox.Show(builder, "Game Over", MessageBoxButtons.YesNo, MessageBoxIcon.None, MessageBoxDefaultButton.Button1,
                                    MessageBoxOptions.DefaultDesktopOnly, false))
            {
            case DialogResult.Yes:
                form.StartNewGame();
                break;

            case DialogResult.No:
                form.Close();
                break;
            }
        }
コード例 #5
0
ファイル: Game.cs プロジェクト: TimVGithub/Yahtzee
        //---------------------------------------------------------------------------------------------------------------------------------------------------

        public void NextTurn()
        {
            //If game is finished display the winner and handle the start of a new game
            if (playersFinished == players.Count)
            {
                if (timesOKButtonClicked == 0)
                {
                    DisplayWinner(DetermineWinner());
                }
                else
                {
                    form.StartNewGame();
                }

                timesOKButtonClicked += 1;

                //Else, iterate through players as appropriate
            }
            else
            {
                switch (currentPlayerIndex)
                {
                case 0:
                    if (players.Count == 1)
                    {
                        currentPlayerIndex = 0;
                    }
                    else
                    {
                        currentPlayerIndex = 1;
                    }
                    break;

                case 1:
                    if (players.Count == 2)
                    {
                        currentPlayerIndex = 0;
                    }
                    else
                    {
                        currentPlayerIndex = 2;
                    }
                    break;

                case 2:
                    if (players.Count == 3)
                    {
                        currentPlayerIndex = 0;
                    }
                    else
                    {
                        currentPlayerIndex = 3;
                    }
                    break;

                case 3:
                    if (players.Count == 4)
                    {
                        currentPlayerIndex = 0;
                    }
                    else
                    {
                        currentPlayerIndex = 4;
                    }
                    break;

                case 4:
                    if (players.Count == 5)
                    {
                        currentPlayerIndex = 0;
                    }
                    else
                    {
                        currentPlayerIndex = 5;
                    }
                    break;

                default:
                    currentPlayerIndex = 0;
                    break;
                }

                currentPlayer = players[currentPlayerIndex];
                numRolls      = 0;
                currentPlayer.ShowScores();
                form.ShowPlayerName(players[currentPlayerIndex].Name);
                form.ShowMessage(messages[3]);
                form.EnableRollButton();
            }
        }