Exemple #1
0
 public void NextTurn()
 {
     if (playersFinished >= players.Count())
     {
         FinishGame();
         return;
     }
     numRolls            = 0;
     currentPlayerIndex += (currentPlayerIndex + 1 == players.Count + 1)?0:1;
     currentPlayerIndex *= (currentPlayerIndex + 1 == players.Count + 1)?0:1;
     form.ShowPlayerName(players[currentPlayerIndex].Name);
     form.DisableAndClearCheckBoxes();
     for (int i = 0; i < Form1.NUM_BUTTONS + Form1.NUM_TOTALS; i++)
     {
         form.DisableScoreButton((ScoreType)i);
     }
     players[currentPlayerIndex].ShowScores();
     form.ShowPlayerName(players[currentPlayerIndex].Name);
 }
Exemple #2
0
        }//END CheckNumPlayers

        /// <summary>
        /// Sets the player to next player and sets the buttons and checkbuttons to the correct set.
        /// </summary>
        private void SwitchPlayers()
        {
            currentPlayer = players[currentPlayerIndex];
            form.ShowPlayerName(currentPlayer.Name);
            currentPlayer.ShowScores();
            numRolls = 0;
            form.ShowMessage(ROLLMESSAGES[numRolls]);
            DisableAllButtons();
            form.EnableRollButton();
            form.DisableAndClearCheckBoxes();
            form.ShowOKButton();
        }//END SwitchPlayers
Exemple #3
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
Exemple #4
0
        public void NextTurn()
        {
            if (currentPlayer.IsFinished() == true)
            {
                // Runs a method that sets the Game Over GUI.
                gameOverControls();
            }

            // If the current player index is larger than the
            // number of players on the binding list it loops back to 0.
            if (currentPlayerindex > form.numberofplayers() - 2)
            {
                currentPlayerindex = 0;
            }
            else
            {
                currentPlayerindex++;
            }

            currentPlayer = players[currentPlayerindex];
            string name = Names[currentPlayerindex];

            playersFinished++;

            string message = "Roll 1";

            for (int i = 0; i < dice.Length; i++)
            {
                dieLabels[i].Text = "";
            }

            numRolls = 0;
            currentPlayer.ShowScores();
            form.DisableAllButtons();
            form.DisableAndClearCheckBoxes();
            form.EnableRollButtons();
            form.ShowPlayerName(name);
            form.ShowMessage(message);
            form.HideOKButton();
        }
Exemple #5
0
        /// <summary>
        /// Creates a new game and initiates the GUI desgin and starting buttons.
        /// </summary>
        /// <param name="form"></param>
        public Game(Form1 form)
        {
            form.clearScoreLabels();
            players.ResetBindings();
            players.Add(new Player(Names[0], form.GetScoreTotals()));

            string message = "Please Select the Number of Players";

            currentPlayerindex = 0;
            playersFinished    = 0;
            numRolls           = 0;

            this.form      = form;
            this.dieLabels = this.form.GetDice();

            for (int i = 0; i < dice.Length; i++)
            {
                dice[i] = new Die(dieLabels[i]);
            }
            currentPlayer = players[currentPlayerindex];


            for (int i = 0; i < dice.Length; i++)
            {
                dieLabels[i].Text = "";
            }

            string name = Names[currentPlayerindex];

            form.DisableAndClearCheckBoxes();
            form.DisableAllButtons();
            form.ShowPlayerName(name);
            form.EnableUpDown();
            form.EnableRollButtons();
            form.ShowMessage(message);
            form.HideOKButton();
            form.enablesave();
            form.disableload();
        }
Exemple #6
0
 /// <summary>
 /// Refreshes the die and resets the UI for the next turn.
 /// </summary>
 private void SetUiForNextTurn()
 {
     form.DisableAndClearCheckBoxes();
     DisableAllScoreButtons();
 }
Exemple #7
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();
            }
        }