private static bool PlayerOneWinsWar(DeckOfCards playerOne, DeckOfCards playerTwo) { var playerOneWins = false; //Console.WriteLine("WAR: {0}, {1}", cardPlayerOne.Name, cardPlayerTwo.Name); var moreCardsPlayerOne = playerOne.Deal(2); var moreCardsPlayerTwo = playerTwo.Deal(2); if (moreCardsPlayerOne.Cards[1].Beats(moreCardsPlayerTwo.Cards[1])) { playerOneWins = true; } else if (moreCardsPlayerTwo.Cards[1].Beats(moreCardsPlayerOne.Cards[1])) { // playerOneWins = false; } else { playerOneWins = PlayerOneWinsWar(playerOne, playerTwo); } if (playerOneWins) { playerOne.Add(moreCardsPlayerTwo.Cards); playerOne.Add(moreCardsPlayerOne.Cards); } else { playerTwo.Add(moreCardsPlayerTwo.Cards); playerTwo.Add(moreCardsPlayerOne.Cards); } return(playerOneWins); }
public void DealCards() { DeckOfCards deck = new DeckOfCards(); Assert.AreEqual(52, deck.Count); deck.Deal(5); Assert.AreEqual(5, deck.Count); deck.ResetDeck(); Assert.AreEqual(52, deck.Count); }
public void PlayTrick(DeckOfCards playerOne, DeckOfCards playerTwo) { try { var cardPlayerOne = playerOne.Deal(1).Cards[0]; var cardPlayerTwo = playerTwo.Deal(1).Cards[0]; var playerOneWins = false; if (cardPlayerOne.SameRankAs(cardPlayerTwo)) { playerOneWins = PlayerOneWinsWar(playerOne, playerTwo); } else if (cardPlayerOne.Beats(cardPlayerTwo)) { playerOneWins = true; } if (playerOneWins) { //Console.WriteLine("{0} beats {1} - cards to player 1", cardPlayerOne.Name, cardPlayerTwo.Name); playerOne.Add(cardPlayerOne); playerOne.Add(cardPlayerTwo); } else { //Console.WriteLine("{0} beats {1} - cards to player 2", cardPlayerTwo.Name, cardPlayerOne.Name); playerTwo.Add(cardPlayerOne); playerTwo.Add(cardPlayerTwo); } } catch { // move along } }
/// <summary> /// First deal of the game. /// </summary> public void DealGame() { ResetGame(); canBet = false; //betSlider.interactable = false; betButton.gameObject.SetActive(false); redoBetButton.gameObject.SetActive(false); //lastBet = (int)betSlider.value; betChips.Clear(); foreach (Transform chip in BetArea.transform) { betChips.Add(allChips.FindChipByName(chip.gameObject.name)); } lastBet = currentBet; player.PlaceBet(currentBet); standButton.gameObject.SetActive(true); hitButton.gameObject.SetActive(true); if (player.GetBets()[0] <= player.Credit) { doubleButton.gameObject.SetActive(true); } deck.BuildDeck(); deck.ShuffleDeck(); insuranceText.text = "Do you want insurance?"; insuranceBlackjack = false; for (int index = 0; index < handResultsText.Count; index++) { Destroy(handResultsText[index].gameObject); } handResultsText.Clear(); for (int index = 0; index <= 3; index++) { Card newCard = deck.Deal(); int temp = index % 2; if (index % 2 == 0) { player.AddToHand(newCard); } else { dealer.AddToHand(newCard); } } if (dealer.GetHand()[0].GetFaceValue() == 11) { if (player.Credit >= (lastBet / 2)) { insuranceText.transform.gameObject.SetActive(true); insuranceYesButton.gameObject.SetActive(true); insuranceNoButton.gameObject.SetActive(true); doubleButton.gameObject.SetActive(false); splitButton.gameObject.SetActive(false); standButton.gameObject.SetActive(false); hitButton.gameObject.SetActive(false); } else { InsuranceNo(); } } else if (player.Splitable() && !insuranceBlackjack && player.GetBets()[0] <= player.Credit) { splitButton.gameObject.SetActive(true); } else { splitButton.gameObject.SetActive(false); } UpdateCardValues(); }