private Card getCard(Player player) { Card card = player.Cards.ElementAt(0); player.Cards.Remove(card); _bounty.Add(card); return card; }
public void War(Player player1, Player player2) { //test war code. Show cards. Create Auto Play loop p1LeftCard.ImageUrl = p1MainCard.ImageUrl; p2LeftCard.ImageUrl = p2MainCard.ImageUrl; int counter = 2; bool facedown = true; while (counter > 0) { try { player1.ThrowCard(warPile, facedown); player2.ThrowCard(warPile, facedown); facedown = !facedown; if(counter==2) { p1MainCard.ImageUrl = warPile[2].relPath; p2MainCard.ImageUrl = warPile[3].relPath; } else { p1RightCard.ImageUrl = warPile[4].relPath; p2RightCard.ImageUrl = warPile[5].relPath; } counter--; } catch { //investigate loop behavior GameOver(player1, player2); } } Compare(warPile, player1, player2); }
public string PerformBattle(Player player1, Player player2) { Card player1Card = getCard(player1); Card player2Card = getCard(player2); performEvaluation(player1, player2, player1Card, player2Card); return _sb.ToString(); }
private void awardWinner(Player player) { if (_bounty.Count == 0) return; displayBountyCards(); player.Cards.AddRange(_bounty); _bounty.Clear(); _sb.Append("<br/><strong>"); _sb.Append(player.Name); _sb.Append("wins!</strong><br/>"); }
public string Deal(Player player1, Player player2) { while (_deck.Count > 0) { //deal cared to each player dealCard(player1); dealCard(player2); } return _sb.ToString(); }
public Game(string player1Name, string player2Name) { _player1 = new Player() { Name = player1Name }; _player2 = new Player() { Name = player2Name }; }
private void performEvaluation(Player player1, Player player2, Card card1, Card card2) { displayBattleCards(card1, card2); if (card1.CardValue() == card2.CardValue()) war(player1, player2); if (card1.CardValue() > card2.CardValue()) awardWinner(player1); else awardWinner(player2); }
private void dealCard(Player player) { Card card = _deck.ElementAt(_random.Next(_deck.Count)); player.Cards.Add(card); _deck.Remove(card); _sb.Append("<br/>"); _sb.Append(player.Name); _sb.Append(" is dealth the "); _sb.Append(card.Kind); _sb.Append(" of "); _sb.Append(card.Suit); }
public void GameOver(Player player1, Player player2) { switch (player1.hand.Count()) { case 0: resultsLabel.Text += "That's it. Player 1 is out of Cards. <br><br> Player 2 wins the Game of War"; break; default: resultsLabel.Text += "That's it. Player 2 is out of Cards. <br><br> Player 1 wins the Game of War"; break; } }
public void War(Player player1, Player player2) { //test war code. Show cards. Create Auto Play loop int counter = 2; bool facedown = true; while (counter > 0) { try { player1.ThrowCard(warPile, facedown); player2.ThrowCard(warPile, facedown); facedown = !facedown; counter--; } catch { //investigate loop behavior GameOver(player1, player2); } } Compare(warPile, player1, player2); }
public Game(string player1Name, string player2Name) { _player1 = new Player() { Name = player1Name}; _player2 = new Player() { Name = player2Name }; _bounty = new List<Card>(); }
private void war(Player player1, Player player2) { _sb.Append("<br/>***************WAR*******************<br/>"); getCard(player1); Card warCard1 = getCard(player1); getCard(player1); getCard(player2); Card warCard2 = getCard(player2); getCard(player2); performEvaluation(player1, player2, warCard1, warCard2); }
public static void Deal(this List<Card> deck, Player player1, Player player2) { int i = 0; int counter = 1; while (i < deck.Count) { switch (counter%2) { case (1): player1.hand.Add(deck[i]); deck.RemoveAt(i); break; case (0): player2.hand.Add(deck[i]); deck.RemoveAt(i); break; } counter++; } }
private void PrintRoundResults(Player player, List<Card> warPile) { resultsLabel.Text = player.name + " wins the"; foreach (var card in warPile) { resultsLabel.Text += " " + card.name; if (card != warPile[(warPile.Count - 1)]) { resultsLabel.Text += "<br />and <br />"; } } var winnerCardCount = player.hand.Count + warPile.Count; //resultsLabel.Text += "Card count (" + player.name + "): " + winnerCardCount + "<br />"; if (player.name == "Player 1") { p1cardCountLabel.Text = winnerCardCount.ToString(); p2cardCountLabel.Text = (52 - winnerCardCount).ToString(); } else { p2cardCountLabel.Text = winnerCardCount.ToString(); p1cardCountLabel.Text = (52 - winnerCardCount).ToString(); } }
private void PrintPlayerCards(Player Player1, Player Player2) { StringBuilder sb = new StringBuilder(); sb.Append("Player 1 Cards: <br />"); foreach (var card in Player1.hand) { sb.Append(card.name + "<br />"); } sb.Append("<br /> <br />"); sb.Append("Player 2 Cards: <br />"); foreach (var card in Player2.hand) { sb.Append(card.name + "<br />"); } unshuffledLabel.Text = sb.ToString(); }
private void Compare(List<Card> warPile, Player player1, Player player2) { var p1Compare = warPile[warPile.Count - 2].value; var p2Compare = warPile[warPile.Count - 1].value; if (p1Compare > p2Compare) { PrintRoundResults(player1, warPile); player1.Wins(warPile); } else if (p1Compare < p2Compare) { PrintRoundResults(player2, warPile); player2.Wins(warPile); } else { War(player1, player2); } }
protected void warButton_Click(object sender, EventArgs e) { Player1 = (Player)Session["Player1"]; Player2 = (Player)Session["Player2"]; int count = 1000; bool gameOver = false; while (count > 0 && !gameOver) { gameOver = PlayRound(); //Response.Redirect("Default.aspx"); count--; } }