public void Turn(ref Deck p1, ref Deck p2, Card p1Card, Card p2Card, out bool war) { war = false; //P1 wins if (p1Card > p2Card) { Console.WriteLine("Player one wins!"); WinAdjust(ref p1, ref p2, p1Card, p2Card); } //P2 wins else if (p1Card < p2Card) { Console.WriteLine("Player two wins! "); WinAdjust(ref p2, ref p1, p2Card, p1Card); } //War -- same number on draw else { war = true; Console.WriteLine("**WAR!**"); Console.WriteLine(""); //Current cards on board p1wardeck = new List <Card>(); p2wardeck = new List <Card>(); //add current card to war deck p1wardeck.Add(p1Card); p2wardeck.Add(p2Card); p1.RemoveCard(p1Card); p2.RemoveCard(p2Card); //End loop when cards are not equal or a deck is empty while (p1Card == p2Card && !(p2.IsEmpty() || p1.IsEmpty())) { //Flip next three cards, compare last one for (int i = 0; i < 3; i++) { //If list has card, add to war deck and remove from normal deck if (!p1.IsEmpty()) { p1Card = p1.DrawCard(); p1wardeck.Add(p1Card); p1.RemoveCard(p1Card); } if (!p2.IsEmpty()) { p2Card = p2.DrawCard(); p2wardeck.Add(p2Card); p2.RemoveCard(p2Card); } } } Console.WriteLine("Player one's war deck: "); for (int i = 0; i < p1wardeck.Count; i++) { Console.WriteLine(p1wardeck[i]); } Console.WriteLine(""); Console.WriteLine("Player two's war deck: "); for (int i = 0; i < p2wardeck.Count; i++) { Console.WriteLine(p2wardeck[i]); } Console.WriteLine(""); //p1 wins war if (p1Card > p2Card) { Console.WriteLine("Player one wins!"); //get own cards back for (int i = 0; i < p1wardeck.Count; i++) { p1.AddCard(p1wardeck[i]); } //take p2's cards for (int i = 0; i < p2wardeck.Count; i++) { p1.AddCard(p2wardeck[i]); } } //p2 wins war else { Console.WriteLine("Player two wins!"); //get own cards back for (int i = 0; i < p2wardeck.Count; i++) { p2.AddCard(p2wardeck[i]); } //take p1's cards for (int i = 0; i < p1wardeck.Count; i++) { p2.AddCard(p1wardeck[i]); } } } p1.PrintDeck(); p2.PrintDeck(); }
private void flipCards_Click(object sender, EventArgs e) { bool war; Card p1CurrCard, p2CurrCard; warLbl.Hide(); game.DrawCards(ref p1, ref p2, out p1CurrCard, out p2CurrCard); UpdateCards(p1CurrCard, p2CurrCard); game.Turn(ref p1, ref p2, p1CurrCard, p2CurrCard, out war); if (war) { List <Card> p1warcards, p2warcards; game.GetWarCards(out p1warcards, out p2warcards); for (int i = 0; i < p1warcards.Count; i++) { } p1war11Pbx.Load(GetCardImageString(p1warcards[1])); p2war11Pbx.Load(GetCardImageString(p2warcards[1])); p1war12Pbx.Load(GetCardImageString(p1warcards[2])); p2war12Pbx.Load(GetCardImageString(p2warcards[2])); p1war13Pbx.Load(GetCardImageString(p1warcards[3])); p2war13Pbx.Load(GetCardImageString(p2warcards[3])); warLbl.Show(); } //warLbl.Hide(); Refresh(); if (p2.IsEmpty()) { DialogResult newgame = MessageBox.Show("Player one wins! New Game?", "Game Over", MessageBoxButtons.YesNo); if (newgame == DialogResult.Yes) { System.Windows.Forms.Application.Restart(); } else { flipCards.Enabled = false; } } else if (p1.IsEmpty()) { DialogResult newgame = MessageBox.Show("Player two wins! New Game?", "Game Over", MessageBoxButtons.YesNo); if (newgame == DialogResult.Yes) { System.Windows.Forms.Application.Restart(); } else { flipCards.Enabled = false; } } }