private static void DisplayGame(CardHand playerOneHand, CardHand playerTwoHand) { GamePlay += String.Format("Round: {2} <br/> Player one has {0} cards and Player two has {1} cards <br />", playerOneHand.CurrentHand.Count, playerTwoHand.CurrentHand.Count, RoundCount); GamePlay += String.Format("Battle Cards: {0} of {1} versus {2} of {3} <br />", playerOneHand.CurrentHand[0].CardName, playerOneHand.CurrentHand[0].Suit, playerTwoHand.CurrentHand[0].CardName, playerTwoHand.CurrentHand[0].Suit); }
private static void AddWarCardsToBounty(CardHand playerHand) { for (int addToBounty = 0; addToBounty < 3; addToBounty++) { if (playerHand.CurrentHand.Count > 1) { currentBounty.Add(playerHand.CurrentHand[0]); playerHand.CurrentHand.RemoveAt(0); } } }
//OR internal static void PlayThisManyRounds(CardHand playerOneHand, CardHand playerTwoHand, int roundsToPlay) { Winner = null; RoundCount = 1; while (RoundCount <= roundsToPlay && Winner == null) { PlayRound(playerOneHand, playerTwoHand); CheckForGameWinner(playerOneHand, playerTwoHand); } CheckShortGameWinner(playerOneHand, playerTwoHand); }
public static void PlayGame(CardHand playerOneHand, CardHand playerTwoHand) { GameStartTime = DateTime.Now; Winner = null; RoundCount = 1; while (Winner == null) { PlayRound(playerOneHand, playerTwoHand); CheckForGameWinner(playerOneHand, playerTwoHand); } GameEndTime = DateTime.Now; }
private static void CheckForGameWinner(CardHand playerOne, CardHand playerTwo) { Winner = null; if (playerOne.CurrentHand.Count == 0) { Winner = playerTwo.FullName; } if (playerTwo.CurrentHand.Count == 0) { Winner = playerOne.FullName; } }
protected void GamePlay20Button_Click(object sender, EventArgs e) { int roundCount = 20; CardDeck newDeck = new CardDeck(); CardHand PlayerOneHand = new CardHand(Player1Name.Text); CardHand PlayerTwoHand = new CardHand(Player2Name.Text); WarGame.Deal(newDeck, PlayerOneHand, PlayerTwoHand); WarGame.PlayThisManyRounds(PlayerOneHand, PlayerTwoHand, roundCount); GameResultsLabel.Text = WarGame.GamePlay; WarGame.GamePlay = ""; GamePlay20Button.Focus(); }
//If playing a round count based game. Check at the end of the last round private static void CheckShortGameWinner(CardHand playerOneHand, CardHand playerTwoHand) { if (playerOneHand.CurrentHand.Count > playerTwoHand.CurrentHand.Count) { GamePlay += String.Format("{0} won with {1} card to {2}'s {3} cards", playerOneHand.FullName, playerOneHand.CurrentHand.Count, playerTwoHand.FullName, playerTwoHand.CurrentHand.Count); } else if (playerTwoHand.CurrentHand.Count > playerOneHand.CurrentHand.Count) { GamePlay += String.Format("<strong>{0} won with {1} cards to {2}'s {3} cards</strong>", playerTwoHand.FullName, playerTwoHand.CurrentHand.Count, playerOneHand.FullName, playerOneHand.CurrentHand.Count); } else { GamePlay += "<strong>Nobody Won. It was a tie. :( </strong>"; } }
private static void War(CardHand playerOne, CardHand playerTwo) { GamePlay += "<h3><strong> WAR!!! </strong> </h3><br/>"; if (playerOne.CurrentHand.Count > 0 && playerTwo.CurrentHand.Count > 0) { AddWarCardsToBounty(playerOne); AddWarCardsToBounty(playerTwo); PlayCard(playerOne, playerTwo); CompareCards(playerOne, playerTwo); } else { CheckForGameWinner(playerOne, playerTwo); } }
private static void CompareCards(CardHand playerOne, CardHand playerTwo) { if (currentBounty[currentBounty.Count - 2].Value > currentBounty[currentBounty.Count - 1].Value) { PlayerWonRound(playerOne, playerTwo); } else if (currentBounty[currentBounty.Count - 1].Value > currentBounty[currentBounty.Count - 2].Value) { PlayerWonRound(playerTwo, playerOne); } else { War(playerOne, playerTwo); } }
protected void GamePlayButton_Click(object sender, EventArgs e) { //Need: add time taken CardDeck newDeck = new CardDeck(); CardHand PlayerOneHand = new CardHand(Player1Name.Text); CardHand PlayerTwoHand = new CardHand(Player2Name.Text); WarGame.Deal(newDeck, PlayerOneHand, PlayerTwoHand); WarGame.PlayGame(PlayerOneHand, PlayerTwoHand); WarGame.GamePlay += String.Format("<br/><strong> {0} has won the game!</strong> <br/> Rounds played: {1} <br/>", WarGame.Winner, WarGame.RoundCount - 1); WarGame.GamePlay += "This Game Took " + WarGame.GameEndTime.Subtract(WarGame.GameStartTime).ToString(@"ss\.ffff") + " seconds"; GameResultsLabel.Text = WarGame.GamePlay; WarGame.ResetGamePlay(); GamePlay20Button.Focus(); }
private static void PlayCard(CardHand playerOne, CardHand playerTwo) { if (playerOne.CurrentHand.Count > 0 && playerTwo.CurrentHand.Count > 0) { DisplayGame(playerOne, playerTwo); currentBounty.Add(playerOne.CurrentHand[0]); currentBounty.Add(playerTwo.CurrentHand[0]); playerOne.CurrentHand.RemoveAt(0); playerTwo.CurrentHand.RemoveAt(0); DisplayBounty(); RoundCount += 1; } else { CheckForGameWinner(playerOne, playerTwo); }; }
public static void Deal(CardDeck currentDeck, CardHand PlayerOne, CardHand PlayerTwo) { int _randomCard = random.Next(0, currentDeck.Deck.Count); CardHand _currentHandToDeal = PlayerOne; for (int _cardsRemaining = currentDeck.Deck.Count; _cardsRemaining > 0; _cardsRemaining--) { _currentHandToDeal.CurrentHand.Add(currentDeck.Deck[_randomCard]); GamePlay += String.Format("{0} was dealt a {1} of {2} <br/>", _currentHandToDeal.FullName, currentDeck.Deck[_randomCard].CardName, currentDeck.Deck[_randomCard].Suit); currentDeck.Deck.RemoveAt(_randomCard); _currentHandToDeal = (_currentHandToDeal == PlayerOne) ? PlayerTwo : PlayerOne; _randomCard = random.Next(0, currentDeck.Deck.Count); } GamePlay += "<br/>"; }
private static void PlayRound(CardHand playerOne, CardHand playerTwo) { //Anti Up PlayCard(playerOne, playerTwo); CompareCards(playerOne, playerTwo); }
private static void PlayerWonRound(CardHand Winner, CardHand Loser) { Winner.CurrentHand.AddRange(currentBounty); DisplayHandWinner(Winner.FullName); currentBounty.Clear(); }