/// <summary> /// Event for handling the clicking of the end attack button /// </summary> /// <param name="sender"> The button that sent the event </param> /// <param name="e"> The EventArgs </param> private void btnEndAttack_Click(object sender, EventArgs e) { //If the human player is the attacker if (humanPlayer == attacker) { //The defence was successful DefenceSuccess(); //Draw a card from the computer's hand Card cpuCard = cpuPlayer.selectCard(river); //If the computer's hand is empty and the deck is empty then the human player loses if (attacker.GetHand().Count == 0 && talon.Count == 0) { //Show the loser form this.Hide(); frmLoser lose = new frmLoser(); lose.ShowDialog(); this.Close(); } //Add the drawn card to the river river.Add(cpuCard); //Redraw the form Redraw(); } else { //The attack was successful AttackSuccess(); } }
/// <summary> /// Event for handling the clicking of the end defence button /// </summary> /// <param name="sender"> The button that sent the event </param> /// <param name="e"> The EventArgs </param> private void btnEndDefence_Click(object sender, EventArgs e) { //Set the attacker as the card adder cardAdder = attacker; attacker = null; //The card that was played most recently Card addCard = river[river.Count - 1]; //Add the card to the adder adder.Add(addCard); //Set the adder rank adderRank = addCard.rank; //Remove the card from the river river.Remove(addCard); //A collection of playable cards Cards playable = new Cards(); //Loop through allthe cards in the cardAdder's hand foreach (Card card in cardAdder.GetHand()) { //If the card is playable if (card.rank == adderRank || (river.Count != 0 && card.isPlayable(river))) { //Add the card to list of playable cards playable.Add(card); } } //Loop until the river is full or there are no more playable cards while ((river.Count / 2) + adder.Count < 6 && playable.Count > 0) { //Add the card to the adder adder.Add(playable[0]); //Remove the card from the computer's hand cardAdder.GetHand().Remove(playable[0]); //Remove the card from the playable cards playable.Remove(playable[0]); //If the cardAdder's hand is empty and the deck is empty then the human player loses if (cardAdder.GetHand().Count == 0 && talon.Count == 0) { //Show the Loser form this.Hide(); frmLoser lose = new frmLoser(); lose.ShowDialog(); this.Close(); } } //The attacker was successful AttackSuccess(); //If the attacker's hand is not empty if (attacker.GetHand().Count != 0) { //Draw a card from the computer's hand Card cpuCard = cpuPlayer.selectCard(river); //If the computer's hand is empty and the deck is empty then the human player loses if (attacker.GetHand().Count == 0 && talon.Count == 0) { //Show the Loser form this.Hide(); frmLoser lose = new frmLoser(); lose.ShowDialog(); this.Close(); } //Add the drawn card to the river river.Add(cpuCard); } //Redraw the form Redraw(); }
/// <summary> /// The event that will be wired to playable Cardboxes /// </summary> /// <param name="sender"> The object that the event is fired from </param> /// <param name="e"> The EventArgs object </param> private void Cardbox_Click(object sender, EventArgs e) { //Initialize the sender as a Cardbox CardBox.CardBox box = sender as CardBox.CardBox; //If the human player is the attacker if (attacker == humanPlayer) { //Add the card to the river river.Add(box.Card); //Remove the card from the player's hand humanPlayer.GetHand().Remove(box.Card); //If the player's hand is empty and the deck is empty then the human player wins if (humanPlayer.GetHand().Count == 0 && talon.Count == 0) { //Show the Winner form this.Hide(); frmWinner win = new frmWinner(); win.ShowDialog(); this.Close(); } else { try { //Draw a card from the computer's hand Card cpuCard = cpuPlayer.selectCard(river); //If the computer's hand is empty and the deck is empty then the human player loses if (defender.GetHand().Count == 0 && talon.Count == 0) { //Show the Loser form this.Hide(); frmLoser lose = new frmLoser(); lose.ShowDialog(); this.Close(); } //Add the computer's card to the river river.Add(cpuCard); //If the number of cards in the river equals 12 if (river.Count == 12) { //The defender was successful DefenceSuccess(); } } catch (OperationCanceledException) { //Set the human player as the cardAdder cardAdder = humanPlayer; attacker = null; //Move the played card to the adder adder.Add(box.Card); //Set the rank of the adder adderRank = box.Card.rank; //Remove the card from the river river.Remove(box.Card); } } } //If the human player is the defender else if (defender == humanPlayer) { //Add the card to the river river.Add(box.Card); //Remove the card from the player hand humanPlayer.GetHand().Remove(box.Card); //If the human player's hand is empty and the deck is empty then the human player wins if (humanPlayer.GetHand().Count == 0 && talon.Count == 0) { //Show the Winner form this.Hide(); frmWinner win = new frmWinner(); win.ShowDialog(); this.Close(); } //if the river count equals 12 if (river.Count == 12) { //The defender was successful DefenceSuccess(); } else { try { //Draw a card from the computer's hand Card cpuCard = cpuPlayer.selectCard(river); //If the computer's hand is empty and the deck is empty then the human player loses if (attacker.GetHand().Count == 0 && talon.Count == 0) { //Show the Loser form this.Hide(); frmLoser lose = new frmLoser(); lose.ShowDialog(); this.Close(); } //Add the computer's card to the river river.Add(cpuCard); } catch (OperationCanceledException) { //The defender was successful DefenceSuccess(); } } } //If the human player is the cardAdder else if (cardAdder == humanPlayer) { //Add the card to the adder adder.Add(box.Card); //Remove the card from the player hand humanPlayer.GetHand().Remove(box.Card); //If the human player's hand is empty and the deck is empty then the human player wins if (humanPlayer.GetHand().Count == 0 && talon.Count == 0) { //Show the Winner form this.Hide(); frmWinner win = new frmWinner(); win.ShowDialog(); this.Close(); } //If the human player has played 6 cards if (river.Count / 2 + adder.Count == 6) { //The attacker was successful AttackSuccess(); } } //Redraw the form Redraw(); }