// Swap random card between opponent and player hand public void SwapCard() { // Grey out Swap Card button swapCardButton.interactable = false; // Pick random cards from both hands to be swapped. int randomPlayer = Random.Range(0, 3); int randomDealer = Random.Range(0, 3); // Swap cards. int tempCard = player.Draw(randomPlayer); player.InsertCard(randomPlayer, dealer.Draw(randomDealer)); dealer.InsertCard(randomDealer, tempCard); // Update hand score. if (player.ChanceHandValue() == 30) { playerHandScore.text = "CHANCE"; } else { playerHandScore.text = player.ChanceHandValue().ToString(); } dealerHandScore.text = ""; FindObjectOfType <AudioManager>().Play("cardSlide6"); }
// Starts a new round of chance. void StartRound() { endTurnButton.interactable = true; swapCardButton.interactable = true; nextRoundButton.interactable = false; // Emptying hands while (player.HasCards && dealer.HasCards) { player.Draw(0); dealer.Draw(0); } // If the deck has less than or equal to 6 cards, then we have reached // the end of the game, so we dont draw. if (deck.CardCount >= 6) { // Draw hands. for (int i = 0; i < 3; i++) { player.push(deck.Draw(0)); dealer.push(deck.Draw(0)); } // Update hand scores. if (player.ChanceHandValue() == 30) { playerHandScore.text = "CHANCE"; } else { playerHandScore.text = player.ChanceHandValue().ToString(); } dealerHandScore.text = ""; } else { // End game. CoverHand(); playerHandScore.text = ""; dealerHandScore.text = ""; if (roundWonByDealer > roundWonByPlayer) { winnerText.text = "Dealer wins the game!"; } else if (roundWonByPlayer > roundWonByDealer) { winnerText.text = "You win the game!"; } else { winnerText.text = "Tie game!"; } // Grey out buttons. swapCardButton.interactable = false; nextRoundButton.interactable = false; endTurnButton.interactable = false; } }
public void OnPointerClick(PointerEventData eventData) { switch (card.state) { case CardState.Stacked: if (card.state == CardState.Stacked) { if (TurnManager.IsCardDrawn()) { Tooltip.Show("Only one card can be drawn per turn"); break; } else { if (currentStack != null) { currentStack.Draw(); } } } Open(true); AudioSource.PlayClipAtPoint(cardPick, Vector3.zero); Player.instance.playerHand.PickCard(this); break; case CardState.Handed: if (!enemy) { CardPreviewer.instance.PreviewCard(this); } break; case CardState.Arena: if (enemy) { CardPreviewer.instance.PreviewCard(this); } else { Tap(); } break; case CardState.Tapped: CardPreviewer.instance.PreviewCard(this); break; case CardState.Dead: CardPreviewer.instance.PreviewCard(this); break; } }
public void Hit() { FindObjectOfType <AudioManager>().Play("cardSlide6"); player.push(deck.Draw(0)); Debug.Log("Player score = " + player.BlackjackSumValue()); playerHandScore.text = player.BlackjackSumValue().ToString(); if (player.BlackjackSumValue() > 21) { // Player is bust. hitButton.interactable = false; standButton.interactable = false; StartCoroutine(DealersTurn()); } }
public void TestInstantiation() { CardStack deck = CardStack.GetSortedStandardDeck( CardStackOrientation.FaceDown); List <Card> hand = deck.Draw(26); //create a player Player player; player = new Player( CardStack.FromList(hand, CardStackOrientation.FaceDown)); Assert.AreEqual(26, player.Hand.Count); //initial hand cannot be face up Assert.Throws <ArgumentException>(() => player = new Player(CardStack.FromList( hand, CardStackOrientation.FaceUp))); //initial hand must have exactly 26 cards hand.Add(new Card(CardSuit.Hearts, CardRank.Ace)); Assert.Throws <ArgumentException>(() => player = new Player(CardStack.FromList( hand, CardStackOrientation.FaceDown))); hand.RemoveAt(0); hand.RemoveAt(0); Assert.AreEqual(25, hand.Count); Assert.Throws <ArgumentException>(() => player = new Player(CardStack.FromList( hand, CardStackOrientation.FaceDown))); }
public void Draw(int amount = 1) { for (int i = 0; i < amount; i++) { hand.Add(drawPile.Draw()); } }
public static void Main(string[] args) { CardStack deck = CardStack.GetShuffledStandardDeck( CardStackOrientation.FaceDown); PrintCardStack(deck); Console.WriteLine(); CardStack discards = CardStack.GetEmptyStack( CardStackOrientation.FaceUp); List <Card> drawnCards = deck.Draw(10); Console.WriteLine("Drawn face down:"); PrintCardList(drawnCards); Console.WriteLine("Deck status:"); PrintCardStack(deck); Console.WriteLine(); //Create a new stack from drawn cards, face up CardStack drawnStack = CardStack.FromList(drawnCards, CardStackOrientation.FaceUp); Console.WriteLine("Stack from drawn cards:"); PrintCardStack(drawnStack); drawnStack.Sort(Card.COMPARE_SUIT_RANK); PrintCardStack(drawnStack); drawnStack.Sort(Card.COMPARE_RANK_SUIT); PrintCardStack(drawnStack); Console.WriteLine(); //flip the stack over Console.WriteLine("Flipped deck."); deck.Orientation = CardStackOrientation.FaceUp; PrintCardStack(deck); //PrintCardStack(discards); //foreach (Card card in drawnCardsDown) //{ // discards.AddCardFaceDown(card); //} //PrintCardStack(discards); //foreach (Card card in drawnCardsUp) //{ // discards.AddCardFaceDown(card); //} //PrintCardStack(discards); }
void StartRound() { // Empty the hands. while (player.HasCards) { player.Draw(0); } while (dealer.HasCards) { dealer.Draw(0); } // Draw the hands for (int i = 0; i < 2; i++) { player.push(deck.Draw(0)); dealer.push(deck.Draw(0)); } // Update text. winnerText.text = ""; dealerHandScore.text = ""; playerHandScore.text = player.BlackjackSumValue().ToString(); nextRoundButton.interactable = false; if (dealer.BlackjackSumValue() == 21) { winnerText.text = "Dealer has a blackjack!"; Stand(); } if (player.BlackjackSumValue() == 21) { winnerText.text = "Player has a blackjack!"; Stand(); } }
public void Draw() { hand.Add(deck.Draw()); }
public void TestDraw() { CardStack stack = CardStack.GetSortedStandardDeck( CardStackOrientation.FaceDown); List <Card> drawn; Card card; CardRank rankIndex; //draw a card (face down) and verify Assert.AreEqual(52, stack.Count); //starting with the expected count drawn = stack.Draw(1); Assert.AreEqual(51, stack.Count); //drew exactly one card Assert.AreEqual(1, drawn.Count); //drawn cards only contains one card = drawn[0]; //drew the expected card (Ace of Hearts) Assert.True(card.Equals(new Card(CardSuit.Hearts, CardRank.Ace))); //drawn card is no longer in stack CollectionAssert.DoesNotContain(stack.Contents, new Card(CardSuit.Hearts, CardRank.Ace)); //draw a card (face up) and verify stack.Flip(); Assert.AreEqual(51, stack.Count); //starting with the expected count drawn = stack.Draw(1); Assert.AreEqual(50, stack.Count); //drew exactly one card Assert.AreEqual(1, drawn.Count); //drawn cards only contains one card = drawn[0]; //drew the expected card (King of Clubs) Assert.True(card.Equals(new Card(CardSuit.Clubs, CardRank.King))); //drawn card is no longer in the stack CollectionAssert.DoesNotContain(stack.Contents, new Card(CardSuit.Clubs, CardRank.King)); //draw 5 cards (face down) and verify stack.Flip(); Assert.AreEqual(50, stack.Count); //starting with the expected count drawn = stack.Draw(5); Assert.AreEqual(45, stack.Count); //drew exactly five cards Assert.AreEqual(5, drawn.Count); //drawn cards contains exactly five //drew the expected cards in order (Deuce, 3, 4, 5, and 6 of Hearts) rankIndex = CardRank.Ace; foreach (Card c in drawn) { rankIndex++; //is this the card we expected to be here? Assert.AreEqual(rankIndex, c.Rank); //were there cards we didn't expect? Assert.LessOrEqual(rankIndex, CardRank.Six); } //drawn cards are no longer in the stack foreach (Card c in drawn) { CollectionAssert.DoesNotContain(stack.Contents, c); } //draw 5 cards (face up) and verify stack.Flip(); Assert.AreEqual(45, stack.Count); //starting with the expected count drawn = stack.Draw(5); Assert.AreEqual(40, stack.Count); //drew exactly five cards Assert.AreEqual(5, drawn.Count); //drawn cards contains exactly five //drew the expected cards in order (Queen, Jack, 10, 9, and 8 of // Clubs) rankIndex = CardRank.King; foreach (Card c in drawn) { rankIndex--; //is this the card we expected to be here? Assert.AreEqual(rankIndex, c.Rank); //were there cards we didn't expect? Assert.GreaterOrEqual(rankIndex, CardRank.Eight); } //drawn cards are no longer in the stack foreach (Card c in drawn) { CollectionAssert.DoesNotContain(stack.Contents, c); } //try to draw more than the remaining cards (face down) stack.Flip(); Assert.AreEqual(40, stack.Count); //starting with the expected count //draw shouldn't throw any exceptions or errors Assert.DoesNotThrow(() => drawn = stack.Draw(52)); Assert.Zero(stack.Count); //stack should be empty now Assert.AreEqual(40, drawn.Count); //drawn cards should be 40 //try to draw a card from the empty stack (face down) Assert.DoesNotThrow(() => drawn = stack.Draw(1)); Assert.Zero(stack.Count); //stack should still be empty Assert.Zero(drawn.Count); //drawn should be empty }