private void timer1_Tick(object sender, EventArgs e) { if (time_count == 10) { time_count = 0; timer1.Stop(); if (Pig_Double_Die_Game.PlayGame() == true) { MessageBox.Show("Sorry you have thrown a 1\n Your turn is over!\n"); if (Pig_Double_Die_Game.current_player == "Player 1") { Whose_Turn_to_label.Text = "Player 2 Roll Die"; Pig_Double_Die_Game.current_player = "Player 2"; Pig_Double_Die_Game.current_dice_sum = 0; } else { Whose_Turn_to_label.Text = "Player 1 Roll Die"; Pig_Double_Die_Game.current_player = "Player 1"; Pig_Double_Die_Game.current_dice_sum = 0; } } else { } } else { time_count++; pictureBox1.Image = Games.Images.GetDieImage(Pig_Double_Die_Game.GetFaceValue()[0]); pictureBox2.Image = Games.Images.GetDieImage(Pig_Double_Die_Game.GetFaceValue()[1]); } }
/// <summary> /// Initialize Pig with Two Dice Form /// </summary> public Pig_with_Two_Dice_Form() { InitializeComponent(); Pig_Double_Die_Game.SetUpGame(); pigLabelWhosTurnTo.Text = Pig_Double_Die_Game.GetFirstPlayersName(); Pig_rollOrHoldLabel.Text = "Roll die"; holdButton.Enabled = false; }
/// <summary> /// Reset the game after a match. /// </summary> private void Reset() { playerOneTextBox.Text = (0).ToString(); playerTwoTextBox.Text = (0).ToString(); pigLabelWhosTurnTo.Text = Pig_Double_Die_Game.GetNextPlayersName(); yesAnotherGameRadioButton.Checked = false; anotherGameGroupBox.Enabled = false; rollButton.Enabled = true; }
//Display the dice images private void renderImage() { PictureBox[] pictureBoxes = new PictureBox[2] { pigPictureBox, pigPictureBox2 }; for (int i = 0; i < dice.Length; i++) { pictureBoxes[i].Image = Images.GetDieImage(Pig_Double_Die_Game.GetFaceValue(i)); pictureBoxes[i].SizeMode = PictureBoxSizeMode.StretchImage; } }
/// <summary> /// Count the points a player has in real time. /// </summary> private void CountPoints() { for (int i = 0; i < dice.Length; i++) { if (pigLabelWhosTurnTo.Text == "Player 1") { playerOneTextBox.Text = (Int32.Parse(playerOneTextBox.Text) + Pig_Double_Die_Game.GetFaceValue(i) * POINT_MULTIPLIER).ToString(); } else { playerTwoTextBox.Text = (Int32.Parse(playerTwoTextBox.Text) + Pig_Double_Die_Game.GetFaceValue(i) * POINT_MULTIPLIER).ToString(); } } }
private void Hold_button2_Click(object sender, EventArgs e) { if (Pig_Double_Die_Game.current_dice_sum == 0) { } else { if (Pig_Double_Die_Game.current_player == "Player 1") { Player_1_textbox.Text = Pig_Double_Die_Game.GetPointsTotal("Player 1").ToString(); Pig_Double_Die_Game.current_player = "Player 2"; Whose_Turn_to_label.Text = "Player 2 Roll Die"; if (Pig_Double_Die_Game.HasWon() == true) { MessageBox.Show("Player 1 has won!"); Yes_Another_pig_radioButton1.Enabled = true; No_another_Pig_radioButton2.Enabled = true; } Pig_Double_Die_Game.current_dice_sum = 0; } else { Player_2_textbox.Text = Pig_Double_Die_Game.GetPointsTotal("Player 2").ToString(); Pig_Double_Die_Game.current_player = "Player 1"; Whose_Turn_to_label.Text = "Player 1 Roll Die"; if (Pig_Double_Die_Game.HasWon() == true) { MessageBox.Show("Player 2 has won!"); Yes_Another_pig_radioButton1.Enabled = true; No_another_Pig_radioButton2.Enabled = true; } Pig_Double_Die_Game.current_dice_sum = 0; } } }
/// <summary> /// Play the game when the dice animation is clicked and determine the outcome of the round. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void playGame() { enableButtons(true); int points = Pig_Double_Die_Game.GetPointsTotal(pigLabelWhosTurnTo.Text); if (!Pig_Double_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_Double_Die_Game.GetNextPlayersName(); } if (Pig_Double_Die_Game.HasWon()) { WonGame(); } }
/// <summary> /// Get the next players turn when the hold button is clicked. /// </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_Double_Die_Game.GetNextPlayersName(); }