private void DeckPB_Click(object sender, EventArgs e) { bool canDraw = Crazy_Eights_Game.AddFromDeck(); if (!canDraw) { InstructionText.Text = canDrawText; } if (canDraw) { Crazy_Eights_Game.DeckDiscardSwap(); Crazy_Eights_Game.ComputerTurn(); } Crazy_Eights_Game.DeckDiscardSwap(); //in case computer draws and now resets deck RefreshScreen(); }
} // 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
private void PlayerPBox_Click(object sender, EventArgs e) { //Get the selected card from the picture box int whichCard; PictureBox whichClicked = (PictureBox)sender; whichCard = Crazy_Eights_Game.WhichCard((Card)whichClicked.Tag); Card Selected = Crazy_Eights_Game.GetPlayerHand().GetCard(whichCard); if (Crazy_Eights_Game.IsEight(Selected)) //If the selected card is an eight, load suit selection form { SuitSelection suitSelection = new SuitSelection(); DialogResult result = suitSelection.ShowDialog(); Card card = new Card(); if (result == DialogResult.OK) { card = suitSelection.GetSelection(); } Crazy_Eights_Game.PlayerTurn(Selected, card); Crazy_Eights_Game.ComputerTurn(); InstructionText.Text = yourTurnText; } else { bool check = Crazy_Eights_Game.PlayerTurn(Selected); if (check) { Crazy_Eights_Game.ComputerTurn(); InstructionText.Text = yourTurnText; } else //If no card is played, change instruction text { InstructionText.Text = wrongCard; } } RefreshScreen(); }