Пример #1
0
 /// <summary>
 /// Initialises the binding list that holds the players with two new players.
 /// </summary>
 private void InitialisePlayers()
 {
     //initialise list and add two new players.
     players = new BindingList <Player>();
     players.Add(new Player("Player 1", form.GetScoresTotals()));
     players.Add(new Player("Player 2", form.GetScoresTotals()));
 }
Пример #2
0
        }//end ContinueGame

        /// <summary>
        /// Link the labels on the GUI form to the dice and players
        /// </summary>
        /// <param name="form"></param>
        private void LoadLabels(Form1 form)
        {
            Label[] diceLabels = form.GetDice();
            for (int i = 0; i < dice.Length; i++)
            {
                dice[i].Load(diceLabels[i]);
            }
            for (int i = 0; i < players.Count; i++)
            {
                players[i].Load(form.GetScoresTotals());
            }
        }
Пример #3
0
 /// <summary>
 /// This method initialise all the instance variables of Game
 /// in preparation for a game to begin in the correct state
 /// </summary>
 /// <param name="formOneObject"></param>
 public Game(Form1 formOneObject)
 {
     form      = formOneObject;
     dieLabels = form.GetDice();
     players   = new BindingList <Player>();
     players.Add(new Player("Player 1", form.GetScoresTotals()));
     for (int index = 0; index < 5; index++)
     {
         dice[index] = new Die(dieLabels[index]);
     }
     numRolls = 1;
 }//end Game
Пример #4
0
 public Game(Form1 formOneObj)
 {
     this.form          = formOneObj;
     currentPlayerIndex = DEFAULT_INDEX;
     playersFinished    = DEFAULT_FINISH;
     scoreLabels        = form.GetScoresTotals();
     players            = new BindingList <Player>()
     {
         new Player("Player 1", scoreLabels)
     };
     dice = new Die[NUM_OF_DICE];
     initialize();
     numRolls = DEFAULT_NUM_ROLL;
     form.playerBindingSource.DataSource = players;
     currentPlayer = Players[currentPlayerIndex];
 }
Пример #5
0
        public void RollDice()
        {
            for (int i = 0; i < dieLabels.Length; i++)
            {
                if (dice[i].Active)
                {
                    if (numRolls == 1)
                    {
                        foreach (Button scorebutton in scoreButtons)
                        {
                            if (scorebutton != null)
                            {
                                if (currentPlayer.IsAvailable((ScoreType)Array.IndexOf(scoreButtons, scorebutton)))
                                {
                                    form.EnableScoreButton((ScoreType)Array.IndexOf(scoreButtons, scorebutton));
                                }
                                else
                                {
                                    form.DisableScoreButton((ScoreType)Array.IndexOf(scoreButtons, scorebutton));
                                }
                            }
                        }
                        scoreLabels = form.GetScoresTotals();
                        foreach (Label scorelabel in scoreLabels)
                        {
                            scorelabel.Text = "";
                        }
                        form.message_label.Text = "Roll 2 or choose a combination to score";
                    }
                    else if (numRolls == 2)
                    {
                        form.message_label.Text = "Roll 3 or choose a combination to score";
                    }
                    else if (numRolls == 3)
                    {
                        form.message_label.Text      = @"Choose a combination to score. 
Your turn has ended - click OK";
                        form.rollDice_button.Enabled = false;
                    }
                    dice[i].Roll();
                    dieLabels[i].Text = dice[i].FaceValue.ToString();
                }
            }

            numRolls = numRolls + 1;
        }
Пример #6
0
        }//END LoadLabels

        /// <summary>
        /// Checks the numericUpDown1 value after new game is started and adjusts the players based off this value after
        /// the rolldice button is pressed.
        /// </summary>
        private void CheckNumPlayers()
        {
            if (players.Count < form.NumberPlayers())
            {
                for (int i = players.Count; i < form.NumberPlayers(); i++)
                {
                    string name = "Player " + (i + 1);
                    players.Add(new Player(name, form.GetScoresTotals()));
                }
            }
            else if (players.Count > form.NumberPlayers())
            {
                for (int i = players.Count - 1; i >= form.NumberPlayers(); i--)
                {
                    players.Remove(players[i]);
                }
            }
        }//END CheckNumPlayers
Пример #7
0
 public Game(Form1 form)
 {
     this.form          = form;
     players            = new BindingList <Player>();
     currentPlayerIndex = 0;
     dieLabels          = this.form.GetDice();
     dice = new Die[Form1.NUM_DICE];
     for (int i = 0; i < 5; i++)
     {
         dice[i] = new Die(dieLabels[i]);
     }
     players.Add(new Player("player1", form.GetScoresTotals()));
     currentPlayer   = players[currentPlayerIndex];
     playersFinished = 0;
     numRolls        = 0;
     form.EnableRollButton();
     for (int i = 0; i < Form1.NUM_BUTTONS + Form1.NUM_TOTALS; i++)
     {
         form.DisableScoreButton((ScoreType)i);
     }
     players[currentPlayerIndex].ShowScores();
 }
Пример #8
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