} //end RefreshTheFormThenPause private void dealButton_Click(object sender, EventArgs e) { dealButton.Enabled = false; // deal 8 to each if handsize is 0, or deal 1 and pass if (Crazy_Eights_Game.DealStart()) { for (int i = 0; i <= 7; i++) { Crazy_Eights_Game.DealOneCardTo(0); //deals one card to dealer Crazy_Eights_Game.DealOneCardTo(1); //deals one card to user } // end for //displays images of dealer and users hands DisplayGuiHand(Crazy_Eights_Game.GetHand(0), cTableLayoutPanel, 0); DisplayGuiHand(Crazy_Eights_Game.GetHand(1), pTableLayoutPanel, 1); DisplayDrawPile(); discardPile.Image = Images.GetCardImage(Crazy_Eights_Game.DealOneCard()); } else { // check for max hand size, then a tied game, and deal if not if (!Crazy_Eights_Game.MaxHand(1)) { Crazy_Eights_Game.DealOneCardTo(1); DisplayGuiHand(Crazy_Eights_Game.GetHand(1), pTableLayoutPanel, 1); } else if (Crazy_Eights_Game.MaxHand(0)) { MessageBox.Show("Neither player can play, game is a tie!", "Game Over"); this.Close(); } else { MessageBox.Show("Handsize limit reached, passing turn.", "Deal"); } // end if // pass turn to CPU CpuGo(); } // end if } // end dealButton_Click
} // end dealButton_Click /// <summary> /// Performs the CPU's turn then passes back to the player /// </summary> private void CpuGo() { RefreshTheFormThenPause(); Card discard = Crazy_Eights_Game.CurrentDiscard(); Suit discardSuit = discard.GetSuit(); // check for player selected crazy eight suit if (discard.GetFaceValue() == FaceValue.Eight) { discardSuit = eightsuit; } // end if // reset the discard suit for players next turn if the CPU played something if (Crazy_Eights_Game.ComputerTurn(discardSuit)) { eightsuit = Crazy_Eights_Game.CurrentDiscard().GetSuit(); discardSuit = Crazy_Eights_Game.CurrentDiscard().GetSuit(); } // end if // check for tied game if (Crazy_Eights_Game.MaxHand(1) && Crazy_Eights_Game.MaxHand(0) && !Crazy_Eights_Game.PlayerHasMove(discardSuit)) { MessageBox.Show("Neither player can play, game is a tie!", "Game Over"); this.Close(); } // end if DisplayGuiHand(Crazy_Eights_Game.GetHand(0), cTableLayoutPanel, 0); DisplayDiscardPile(); // Checks for empty hand after turn if (Crazy_Eights_Game.EmptyHand(0) && !Crazy_Eights_Game.EmptyHand(1)) { MessageBox.Show("Computer Wins!", "Game Over"); this.Close(); } // end if // Pass back to player if (!Crazy_Eights_Game.PlayerHasMove(discardSuit)) { dealButton.Enabled = true; } // end if } // end CpuGo