private void YesRadio_CheckedChanged(object sender, EventArgs e) { Pig_Double_Dice_Game.SetUpGame(); // Reset the game RollBtn.Enabled = true; // Enable the roll button again GameTerminal.Enabled = false; // Disable the play again choice UpdateForm(); YesButton.Checked = false; }
}//end of HoldButton /// <summary> /// Setup game, updates WhoseTurnToLabel, updates textbox, unchecks YesOption button /// Disables groupbox. /// </summary> private void YesOption_CheckedChanged(object sender, EventArgs e) { Pig_Double_Dice_Game.SetUpGame(); PlayerOneTotalTextBox.Text = ""; PlayerTwoTotalTextBox.Text = ""; WhoseTurnToLabel.Text = "Player 1"; YesOption.Checked = false; AnotherGameGroupBox.Enabled = false; }//end of YesOption
public Pig_With_Two_Dice_Form() { InitializeComponent(); PictureBox[] pictureBoxes; pictureBoxes = new PictureBox[Pig_Double_Dice_Game.NUM_OF_PLAYERS] { PictureBox, PictureBox2 }; Pig_Double_Dice_Game.SetUpGame(); }
/// <summary> /// "Help" function to update the form with the game value /// </summary> void UpdateForm() { diePictureBox1.Image = Images.GetDieImage(Pig_Double_Dice_Game.GetFaceValue(0)); // Set the image to the die value diePictureBox2.Image = Images.GetDieImage(Pig_Double_Dice_Game.GetFaceValue(1)); // Set the image to the die value TotalPointsPlayer1.Text = Pig_Double_Dice_Game.GetPointsTotal("Player 1").ToString(); // Set the Player 1 points label to player 1's points TotalPointPlayer2.Text = Pig_Double_Dice_Game.GetPointsTotal("Player 2").ToString(); // Set the Player 2 points label to player 2's points textLine1.Text = Pig_Double_Dice_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 }
}//end of RollButton /// <summary> /// Updates textbox, changes player, updates WhoseTurnToLabel. /// </summary> private void HoldButton_Click(object sender, EventArgs e) { if (Pig_Double_Dice_Game.current_player == 1) { PlayerOneTotalTextBox.Text = Pig_Double_Dice_Game.GetPointsTotal().ToString(); Pig_Double_Dice_Game.current_player = 2; WhoseTurnToLabel.Text = "Player 2"; } else if (Pig_Double_Dice_Game.current_player == 2) { PlayerTwoTotalTextBox.Text = Pig_Double_Dice_Game.GetPointsTotal().ToString(); Pig_Double_Dice_Game.current_player = 1; WhoseTurnToLabel.Text = "Player 1"; } }//end of HoldButton
}//end of NoOption /// <summary> /// Rolls die through .PlayGame(), updates image, changes player, checks for wins /// Updates WhosTurnToLabel, updates textbox, enables groupbox. /// </summary> private void RollDice() { if (Pig_Double_Dice_Game.current_player == 1) { Pig_Double_Dice_Game.PlayGame(); PictureBox.Image = Images.GetDieImage(Pig_Double_Dice_Game.GetFaceValue(0)); PictureBox2.Image = Images.GetDieImage(Pig_Double_Dice_Game.GetFaceValue(1)); PlayerOneTotalTextBox.Text = Pig_Double_Dice_Game.overall_points.ToString(); if (Pig_Double_Dice_Game.did_roll_one == 1) { MessageBox.Show("You have thrown a 1.\n Your turn is over!\n Your overall_points reverts to " + Pig_Double_Dice_Game.GetPointsTotal() + "!"); Pig_Double_Dice_Game.current_player = 2; WhoseTurnToLabel.Text = "Player 2"; RollButton.Enabled = true; } if (Pig_Double_Dice_Game.HasWon()) { MessageBox.Show("Player 1 has won!\n Well done!"); AnotherGameGroupBox.Enabled = true; } } else if (Pig_Double_Dice_Game.current_player == 2) { Pig_Double_Dice_Game.PlayGame(); PictureBox.Image = Images.GetDieImage(Pig_Double_Dice_Game.GetFaceValue(0)); PictureBox2.Image = Images.GetDieImage(Pig_Double_Dice_Game.GetFaceValue(1)); PlayerTwoTotalTextBox.Text = Pig_Double_Dice_Game.overall_points.ToString(); if (Pig_Double_Dice_Game.did_roll_one == 1) { MessageBox.Show("You have thrown a 1.\n Your turn is over!\n Your overall_points reverts to " + Pig_Double_Dice_Game.GetPointsTotal() + "!"); Pig_Double_Dice_Game.current_player = 1; WhoseTurnToLabel.Text = "Player 1"; Pig_Double_Dice_Game.did_roll_one = 0; RollButton.Enabled = true; } if (Pig_Double_Dice_Game.HasWon()) { MessageBox.Show("Player 2 has won!\n Well done!"); AnotherGameGroupBox.Enabled = true; } } }//end RollDice
/// <summary> /// "Help" function that is called at the end of the timer, updates buttons according the game rules and links the GUI with the game logic library /// </summary> private void Roll() { HoldBtn.Enabled = true; // Enabled the hold button once a die has been thrown if (Pig_Double_Dice_Game.PlayGame()) { // If a 1 has been thrown HoldBtn.Enabled = false; // Disable the hold button UpdateForm(); MessageBox.Show("Sorry you have thrown a 1.\nYour turn is over!\nYour score reverts to " + Pig_Double_Dice_Game.GetPointsTotal(Pig_Double_Dice_Game.GetNextPlayersName())); } else { UpdateForm(); if (Pig_Double_Dice_Game.HasWon()) { // If a player has won the game MessageBox.Show(Pig_Double_Dice_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; } } }
private void HoldButton_Click(object sender, EventArgs e) { Pig_Double_Dice_Game.SetThisPlayer(Pig_Double_Dice_Game.GetNextPlayersName()); // Move to next player HoldBtn.Enabled = false; UpdateForm(); }
/// <summary> /// Initialise Form /// </summary> public Pig_with_Two_Dice_Form() { InitializeComponent(); Pig_Double_Dice_Game.SetUpGame(); UpdateForm(); }