Exemplo n.º 1
0
        }//END NextTurn

        public void RollDice()
        {
            //Used to check the number of players on the first roll and adjusts to the value of numericUpDown1
            CheckNumPlayers();
            for (int i = 0; i < dice.Length; i++)
            {
                if (dice[i].Active)
                {
                    dice[i].Roll();
                }
            }
            numRolls++;
            if (numRolls == 1)
            {
                form.ShowMessage(ROLLMESSAGES[numRolls]);
                form.EnableCheckBoxes();
                EnableScoreButtons();
                DisableUsedButtons();
            }
            else if (numRolls == 2)
            {
                form.ShowMessage(ROLLMESSAGES[numRolls]);
            }
            else if (numRolls == 3)
            {
                form.ShowMessage(ROLLMESSAGES[numRolls]);
                form.DisableRollButton();
            }
        }//END RollDice
Exemplo n.º 2
0
        /// <summary>
        /// Presents the designated message for the action that the player has taken.
        /// </summary>
        public void ShowMessage()
        {
            switch (numRolls)
            {
            case FIRST_ROLL:
                form.ShowMessage("Roll 1");
                break;

            case SECOND_ROLL:
                form.ShowMessage("Roll 2 or choose a combination to score");
                break;

            case THIRD_ROLL:
                form.ShowMessage("Roll 3 or choose a combination to score");
                break;

            default:
                form.ShowMessage("Choose a combination to Score");
                form.DisableRollButton();
                break;
            }
        }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 4
0
        }//end NextTurn

        /// <summary>
        /// This method will roll all of the active dice
        /// and show unscored buttons
        /// </summary>
        public void RollDice()
        {
            string[] messages = new string[4] {
                "Roll 1", "Roll 2 or choose a combination to score",
                "Roll 3 or choose a combination to score", "Choose a combination to score"
            };
            for (int index = 0; index < 5; index++)
            {
                if (dice[index].Active)
                {
                    dice[index].Roll();
                }
            }

            form.ShowMessage(messages[numRolls]);
            numRolls++;
            if (numRolls > 3)
            {
                form.DisableRollButton();
            }

            //enable unscored buttons
            for (int index = (int)ScoreType.Ones; index <= (int)ScoreType.Sixes; index++)
            {
                if (currentPlayer.IsAvailable((ScoreType)index))
                {
                    form.EnableScoreButton((ScoreType)index);
                }
            }

            for (int index = (int)ScoreType.ThreeOfAKind; index <= (int)ScoreType.Yahtzee; index++)
            {
                if (currentPlayer.IsAvailable((ScoreType)index))
                {
                    form.EnableScoreButton((ScoreType)index);
                }
            }
        }//end RollDice
Exemplo n.º 5
0
        //---------------------------------------------------------------------------------------------------------------------------------------------------

        public void RollDice()
        {
            currentPlayer = players[currentPlayerIndex];
            for (int i = 0; i < NUMBER_OF_DICE; i++)
            {
                if (dice[i].Active)
                {
                    dice[i].Roll();
                    faceValues[i] = dice[i].FaceValue;
                }
                else
                {
                }
            }
            numRolls += 1;

            if (numRolls == 1)
            {
                form.ShowMessage(messages[numRolls - 1]);
                form.EnableCheckBoxes();

                //If a scoring combination is available for currentPlayer, enable it.
                if (currentPlayer.IsAvailable(ScoreType.Ones))
                {
                    form.EnableScoreButton(ScoreType.Ones);
                }
                if (currentPlayer.IsAvailable(ScoreType.Twos))
                {
                    form.EnableScoreButton(ScoreType.Twos);
                }
                if (currentPlayer.IsAvailable(ScoreType.Threes))
                {
                    form.EnableScoreButton(ScoreType.Threes);
                }
                if (currentPlayer.IsAvailable(ScoreType.Fours))
                {
                    form.EnableScoreButton(ScoreType.Fours);
                }
                if (currentPlayer.IsAvailable(ScoreType.Fives))
                {
                    form.EnableScoreButton(ScoreType.Fives);
                }
                if (currentPlayer.IsAvailable(ScoreType.Sixes))
                {
                    form.EnableScoreButton(ScoreType.Sixes);
                }
                if (currentPlayer.IsAvailable(ScoreType.ThreeOfAKind))
                {
                    form.EnableScoreButton(ScoreType.ThreeOfAKind);
                }
                if (currentPlayer.IsAvailable(ScoreType.FourOfAKind))
                {
                    form.EnableScoreButton(ScoreType.FourOfAKind);
                }
                if (currentPlayer.IsAvailable(ScoreType.FullHouse))
                {
                    form.EnableScoreButton(ScoreType.FullHouse);
                }
                if (currentPlayer.IsAvailable(ScoreType.SmallStraight))
                {
                    form.EnableScoreButton(ScoreType.SmallStraight);
                }
                if (currentPlayer.IsAvailable(ScoreType.LargeStraight))
                {
                    form.EnableScoreButton(ScoreType.LargeStraight);
                }
                if (currentPlayer.IsAvailable(ScoreType.Chance))
                {
                    form.EnableScoreButton(ScoreType.Chance);
                }
                if (currentPlayer.IsAvailable(ScoreType.Yahtzee))
                {
                    form.EnableScoreButton(ScoreType.Yahtzee);
                }
            }
            else if (numRolls == 2)
            {
                form.ShowMessage(messages[numRolls - 1]);
            }
            else if (numRolls == 3)
            {
                form.ShowMessage(messages[numRolls - 1]);
                form.DisableRollButton();
                form.DisableAndClearCheckBoxes();
            }
        }