/// <summary> /// Loads and displays the pictureboxes into the player table layout /// panel /// </summary> private void DisplayPHand() { PlayerPanel.Controls.Clear(); Hand pHand = Crazy_Eights_Game.GetPlayerHand(); int handSize = pHand.GetCount(); for (int i = 0; i < handSize; i++) { PlayerPanel.Controls.Add(playerPBox[i]); } }
/// <summary> /// Updates the pictureboxes for the player with images for current /// players hand /// </summary> private void UpdatePHand() { PictureBox pBox; Hand pHand = Crazy_Eights_Game.GetPlayerHand(); int handSize = pHand.GetCount(); for (int i = 0; i < handSize; i++) { Card card = pHand.GetCard(i); pBox = new PictureBox(); pBox.SizeMode = PictureBoxSizeMode.AutoSize; pBox.Dock = DockStyle.Fill; pBox.Image = Images.GetCardImage(card); playerPBox[i] = pBox; playerPBox[i].Click += new EventHandler(PlayerPBox_Click); playerPBox[i].Tag = Crazy_Eights_Game.GetPlayerHand().GetCard(i); } }
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(); }