Пример #1
0
 private void YesRadio_CheckedChanged(object sender, EventArgs e)
 {
     Pig_Single_Die_Game.SetUpGame();    // Reset the game
     RollBtn.Enabled      = true;        // Enable the roll button again
     GameTerminal.Enabled = false;       // Disable the play again choice
     FormUpdate();
     yesButton.Checked = false;
 }
Пример #2
0
 /// <summary>
 /// Initialize the Pig Game Form.
 /// </summary>
 public Pig_Game_Form()
 {
     InitializeComponent();
     Pig_Single_Die_Game.SetUpGame();
     pigLabelWhosTurnTo.Text  = Pig_Single_Die_Game.GetFirstPlayersName();
     Pig_rollOrHoldLabel.Text = "Roll die";
     holdButton.Enabled       = false;
 }
Пример #3
0
        /// <summary>
        /// "Help" function to update the form with the game value
        /// </summary>
        void FormUpdate()
        {
            diePictureBox.Image     = Images.GetDieImage(Pig_Single_Die_Game.GetFaceValue());    // Set the image to the die value
            TotalPointsPlayer1.Text = Pig_Single_Die_Game.GetPointsTotal("Player 1").ToString(); // Set the Player 1 points label to player 1's points
            TotalPointsPlayer2.Text = Pig_Single_Die_Game.GetPointsTotal("Player 2").ToString(); // Set the Player 2 points label to player 2's points

            textLine1.Text = Pig_Single_Die_Game.GetThisPlayer();                                // Set the information text's first line to the player name
            textLine2.Text = (HoldBtn.Enabled) ? "Roll or Hold" : "Roll Die";                    // Set the information text's second line to the player's available action
        }
Пример #4
0
 /// <summary>
 /// Reset the form for a new game.
 /// </summary>
 private void Reset()
 {
     playerOneTextBox.Text             = (0).ToString();
     playerTwoTextBox.Text             = (0).ToString();
     pigLabelWhosTurnTo.Text           = Pig_Single_Die_Game.GetNextPlayersName();
     yesAnotherGameRadioButton.Checked = false;
     anotherGameGroupBox.Enabled       = false;
     rollButton.Enabled = true;
 }
Пример #5
0
        }//end of HoldButton_Click

        /// <summary>
        /// Setup game, updates WhoseTurnToLabel, updates textbox, unchecks YesOption button
        /// Disables groupbox.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void YesOption_CheckedChanged(object sender, EventArgs e)
        {
            Pig_Single_Die_Game.SetUpGame();
            WhoseTurnToLabel.Text       = "Player 1";
            PlayerOneTotalTextBox.Text  = "";
            PlayerTwoTotalTextBox.Text  = "";
            YesOption.Checked           = false;
            AnotherGameGroupBox.Enabled = false;
        }//end of YesOption_Checked
Пример #6
0
 /// <summary>
 /// Count the points in real time as player rolls the die.
 /// </summary>
 private void CountPoints()
 {
     if (pigLabelWhosTurnTo.Text == "Player 1")
     {
         playerOneTextBox.Text = (Int32.Parse(playerOneTextBox.Text) + Pig_Single_Die_Game.GetFaceValue()).ToString();
     }
     else
     {
         playerTwoTextBox.Text = (Int32.Parse(playerTwoTextBox.Text) + Pig_Single_Die_Game.GetFaceValue()).ToString();
     }
 }
Пример #7
0
        }// end EndGameRound

        /// <summary>
        /// Resets GUI controls/message for a new game
        /// </summary>
        private void ResetGame()
        {
            lblWhoseTurn.Text = Pig_Single_Die_Game.GetFirstPLayersName();

            EnableRollButton();

            DisableHoldButton();

            txtPlayerOneTotal.Text = "0";

            txtPlayerTwoTotal.Text = "0";

            optAnotherGameYes.Checked = false;
        }// end ResetGame
Пример #8
0
        public PigGameForm()
        {
            InitializeComponent();

            Pig_Single_Die_Game.SetUpGame();

            SetDieImage();

            lblWhoseTurn.Text = Pig_Single_Die_Game.GetFirstPLayersName().ToString();

            SetRollMessage();

            SetPlayerScores();
        }
Пример #9
0
        }//end of RollButton_Click

        /// <summary>
        /// Updates textbox, changes player, updates WhoseTurnToLabel.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HoldButton_Click(object sender, EventArgs e)
        {
            if (Pig_Single_Die_Game.current_player == 1)
            {
                PlayerOneTotalTextBox.Text         = Pig_Single_Die_Game.GetPointsTotal().ToString();
                Pig_Single_Die_Game.current_player = 2;
                WhoseTurnToLabel.Text = "Player 2";
            }
            else if (Pig_Single_Die_Game.current_player == 2)
            {
                PlayerTwoTotalTextBox.Text         = Pig_Single_Die_Game.GetPointsTotal().ToString();
                Pig_Single_Die_Game.current_player = 1;
                WhoseTurnToLabel.Text = "Player 1";
            }
        }//end of HoldButton_Click
Пример #10
0
        }// end SetPlayerScores

        /// <summary>
        /// Displays end turn message as messagebox.
        /// Players reverted score is displayed.
        /// </summary>
        private void EndTurn()
        {
            string currentPlayer, revertedScore;

            SetPlayerScores();

            currentPlayer = lblWhoseTurn.Text.ToString();

            revertedScore = Pig_Single_Die_Game.GetPointsTotal(currentPlayer).ToString();

            // Finish this part

            MessageBox.Show("Sorry you have thrown a 1." +
                            "\nYour turn is over." +
                            "\nYour score reverts to " + revertedScore);

            SwitchPlayers();
        } // end EndTurn()
Пример #11
0
        /// <summary>
        /// Call the PlayGame function and determine the outcome of the round. Allow another turn if player did not roll a 1 or call the next player if player did roll a 1.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void rollButton_Click(object sender, EventArgs e)
        {
            int points = Pig_Single_Die_Game.GetPointsTotal(pigLabelWhosTurnTo.Text);

            if (!Pig_Single_Die_Game.PlayGame())
            {
                SetupRound();
                CountPoints();
            }
            else
            {
                SetupRound();
                UpdatePoints(points);
                Program.showOKMessageBox("Sorry, you've thrown a 1.\nYour turn is over.\nYour score reverts to " + points + ".");
                pigLabelWhosTurnTo.Text = Pig_Single_Die_Game.GetNextPlayersName();
            }

            if (Pig_Single_Die_Game.HasWon())
            {
                WonGame();
            }
        }
Пример #12
0
 /// <summary>
 /// Rolls die through .PlayGame(), updates image, changes player, checks for wins
 /// Updates WhosTurnToLabel, updates textbox, enables groupbox.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void RollButton_Click(object sender, EventArgs e)
 {
     if (Pig_Single_Die_Game.current_player == 1)
     {
         Pig_Single_Die_Game.PlayGame();
         PictureBox.Image           = Images.GetDieImage(Pig_Single_Die_Game.GetFaceValue());
         PlayerOneTotalTextBox.Text = Pig_Single_Die_Game.overall_points.ToString();
         if (Pig_Single_Die_Game.did_roll_one == 1)
         {
             MessageBox.Show("You have thrown a 1.\n Your turn is over!\n Your overall_points reverts to " + Pig_Single_Die_Game.GetPointsTotal() + "!");
             Pig_Single_Die_Game.current_player = 2;
             WhoseTurnToLabel.Text = "Player 2";
         }
         if (Pig_Single_Die_Game.HasWon())
         {
             MessageBox.Show("Player 1 has won!\n Well done!");
             AnotherGameGroupBox.Enabled = true;
         }
     }
     else if (Pig_Single_Die_Game.current_player == 2)
     {
         Pig_Single_Die_Game.PlayGame();
         PictureBox.Image           = Images.GetDieImage(Pig_Single_Die_Game.GetFaceValue());
         PlayerTwoTotalTextBox.Text = Pig_Single_Die_Game.overall_points.ToString();
         if (Pig_Single_Die_Game.did_roll_one == 1)
         {
             MessageBox.Show("You have thrown a 1.\n Your turn is over!\n Your overall_points reverts to " + Pig_Single_Die_Game.GetPointsTotal() + "!");
             Pig_Single_Die_Game.current_player = 1;
             WhoseTurnToLabel.Text            = "Player 1";
             Pig_Single_Die_Game.did_roll_one = 0;
         }
         if (Pig_Single_Die_Game.HasWon())
         {
             MessageBox.Show("Player 2 has won!\n Well done!");
             AnotherGameGroupBox.Enabled = true;
         }
     }
 }//end of RollButton_Click
Пример #13
0
 private void RollButton_Click(object sender, EventArgs e)
 {
     HoldBtn.Enabled = true;             // Enabled the hold button once a die has been thrown
     if (Pig_Single_Die_Game.PlayGame()) // If a 1 has been thrown
     {
         HoldBtn.Enabled = false;        // Disable the hold button
         FormUpdate();
         MessageBox.Show("Sorry you have thrown a 1.\nYour turn is over!\nYour score reverts to " + Pig_Single_Die_Game.GetPointsTotal(Pig_Single_Die_Game.GetNextPlayer()));
     }
     else
     {
         FormUpdate();
         if (Pig_Single_Die_Game.CheckWin())   // If a player has won the game
         {
             MessageBox.Show(Pig_Single_Die_Game.GetThisPlayer() + " has won!\nWell done.");
             // Disable gameplay buttons until the user makes a choice whether to play again
             RollBtn.Enabled = false;
             HoldBtn.Enabled = false;
             // Enable the user to make a choice whether to play again
             GameTerminal.Enabled = true;
         }
     }
 }
Пример #14
0
        } // end ExitProgram()

        // Event handlers

        private void btnRoll_Click(object sender, EventArgs e)
        {
            bool playGame = Pig_Single_Die_Game.PlayGame();

            SetDieImage();

            if (playGame == false)
            {
                EndTurn();
            }
            else
            {
                EnableHoldButton();

                SetRollOrHoldMessage();

                SetPlayerScores();

                if (Pig_Single_Die_Game.HasWon())
                {
                    VictoryMessage();
                }
            }
        }// end btnRoll_Click
Пример #15
0
 /// <summary>
 /// Render the die images.
 /// </summary>
 private void renderImage()
 {
     pigPictureBox.Image    = Images.GetDieImage(Pig_Single_Die_Game.GetFaceValue());
     pigPictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
 }
Пример #16
0
 /// <summary>
 /// On player hold, continue the game as the next player.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void holdButton_Click(object sender, EventArgs e)
 {
     Pig_rollOrHoldLabel.Text = "Roll die";
     holdButton.Enabled       = false;
     pigLabelWhosTurnTo.Text  = Pig_Single_Die_Game.GetNextPlayersName();
 }
Пример #17
0
 private void HoldButton_Click(object sender, EventArgs e)
 {
     Pig_Single_Die_Game.SetThisPlayer(Pig_Single_Die_Game.GetNextPlayer());     // Move to next player
     HoldBtn.Enabled = false;
     FormUpdate();
 }
Пример #18
0
        // Created Methods

        /// <summary>
        /// Sets the die image based on the values rolled
        /// </summary>
        private void SetDieImage()
        {
            picDie.Image = Images.GetDieImage(Pig_Single_Die_Game.GetFaceValue());
        } // end SetDieImage
Пример #19
0
 public Pig_Game_Form()
 {
     InitializeComponent();
     Pig_Single_Die_Game.SetUpGame();
     PictureBox.Image = Images.GetDieImage(Pig_Single_Die_Game.GetFaceValue());
 }
Пример #20
0
        } // end SetDieImage

        /// <summary>
        /// Switches between players - called after each turn
        /// </summary>
        private void SwitchPlayers()
        {
            lblWhoseTurn.Text = Pig_Single_Die_Game.GetNextPlayersName();

            SetRollMessage();
        }// end SwitchPlayers
Пример #21
0
 public Pig_Game_Form()
 {
     InitializeComponent();
     Pig_Single_Die_Game.SetUpGame();
     FormUpdate();
 }
Пример #22
0
        }// end EnableHoldButton

        /// <summary>
        /// Displays player scores from the Game class on the form
        /// </summary>
        private void SetPlayerScores()
        {
            txtPlayerOneTotal.Text = Pig_Single_Die_Game.GetPointsTotal("Player 1").ToString();

            txtPlayerTwoTotal.Text = Pig_Single_Die_Game.GetPointsTotal("Player 2").ToString();
        }// end SetPlayerScores