Ejemplo n.º 1
0
        public void RollDice()
        {
            playersFinished = 0;
            foreach (Player player in players)
            {
                playersFinished += (player.IsFinished()) ? 1 : 0;
            }
            if (playersFinished >= players.Count())
            {
                NextTurn();
            }
            numRolls++;
            form.ShowPlayerName(players[currentPlayerIndex].Name);
            form.EnableCheckBoxes();
            foreach (Die die in dice)
            {
                if (die.Active)
                {
                    die.Roll();
                }
            }
            switch (numRolls)
            {
            case 0:
                form.ShowMessage("First Roll");
                break;

            case 1:
                form.ShowMessage("Roll Again or Choose a Score Bellow");
                break;

            case 2:
                form.ShowMessage("Final Roll, Please Choose a Score");
                break;
            }
            for (int i = 0; i < Form1.NUM_BUTTONS + Form1.NUM_TOTALS; i++)
            {
                if (players[currentPlayerIndex].IsAvailable((ScoreType)i))
                {
                    form.EnableScoreButton((ScoreType)i);
                }
                else
                {
                    form.DisableScoreButton((ScoreType)i);
                }
            }
            players[currentPlayerIndex].IsFinished();
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
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
Ejemplo 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
Ejemplo n.º 5
0
        /// <summary>
        /// Continue the game after loading a saved game
        ///
        /// Assumes game was saved at the start of a player's turn before they had rolled dice.
        /// </summary>
        private void ContinueGame()
        {
            LoadLabels(form);
            for (int i = 0; i < dice.Length; i++)
            {
                //uncomment one of the following depending how you implmented Active of Die
                // dice[i].SetActive(true);
                // dice[i].Active = true;
            }

            form.ShowPlayerName(currentPlayer.Name);
            form.EnableRollButton();
            form.EnableCheckBoxes();
            // can replace string with whatever you used
            form.ShowMessage("Roll 1");
            currentPlayer.ShowScores();
        }//end ContinueGame
Ejemplo n.º 6
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();
        }
Ejemplo n.º 7
0
        public Game(Form1 form1)
        {
            form               = form1;
            playersFinished    = 0;
            currentPlayerIndex = 0;
            players            = new BindingList <Player>();
            dieLabels          = form.GetDice();
            numRolls           = 0;
            int numPlayers = form.NumberPlayers();

            for (int i = 0; i < numPlayers; i++)
            {
                string name = "Player " + (i + 1);
                players.Add(new Player(name, form.GetScoresTotals()));
            }

            currentPlayer = players[currentPlayerIndex];
            form.ShowPlayerName(currentPlayer.Name);
            form.ShowMessage(ROLLMESSAGES[numRolls]);
            for (int i = 0; i < dice.Length; i++)
            {
                dice[i] = new Die(dieLabels[i]);
            }
        }//END Game
Ejemplo n.º 8
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;
            }
        }
Ejemplo n.º 9
0
        //---------------------------------------------------------------------------------------------------------------------------------------------------

        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();
            }
        }