public void Set_Deck(MyDeck myDeck, YourDeck yourDeck) { _myDeck = myDeck; _yourDeck = yourDeck; StartCoroutine(Start_Timer()); // 타이머 재생 }
private void ShuffleDeck() { MyDeck.reset(); CardsInDeck = MyDeck.CardsLeft(); MessageBoard = ""; DealHandsButtonVisible = true; }
private void Hit() { bool endOfRound = false; PlayerHand.AddCard(MyDeck.pick()); if (PlayerHand.handValue() > 21) { MessageBoard = "Busted! you lose."; DealerScore++; endOfRound = true; } if (PlayerHand.handValue() <= 21 && PlayerHand.CardsInHand.Count >= 5) { MessageBoard = "Player wins!"; PlayerScore++; endOfRound = true; } if (endOfRound) { DealHandsButtonVisible = true; HitButtonVisible = false; StayButtonVisible = false; ShuffleDeckButtonVisible = true; } CardsInDeck = MyDeck.CardsLeft(); }
private void DealHands() { if (CardsInDeck < 10) { DealHandsButtonVisible = false; ShuffleDeckButtonVisible = true; MessageBoard = "There are not enough cards\n" + "in the deck to play the hand."; } else { PlayerHand.clearHand(); DealerHand.clearHand(); PlayerHand.AddCard(MyDeck.pick()); PlayerHand.AddCard(MyDeck.pick()); DealerHand.AddCard(MyDeck.pick()); DealerHand.AddCard(MyDeck.pick()); HitButtonVisible = true; StayButtonVisible = true; ShuffleDeckButtonVisible = false; DealHandsButtonVisible = false; CardsInDeck = MyDeck.CardsLeft(); DealerHandValue = 0; PlayerHandValue = 0; MessageBoard = ""; } }
private void NewGame() { MyDeck.reset(); CardsInDeck = MyDeck.CardsLeft(); PlayerHand.clearHand(); DealerHand.clearHand(); ShuffleDeckButtonVisible = true; DealHandsButtonVisible = true; DealerHandValue = 0; PlayerHandValue = 0; PlayerScore = 0; DealerScore = 0; MessageBoard = ""; }
private void Stay() { PlayerHandValue = PlayerHand.handValue(); DealerHandValue = DealerHand.handValue(); bool dealerHas5CardsWithValueSmallerThan21 = false; int count = DealerHand.CardsInHand.Count; while (!dealerHas5CardsWithValueSmallerThan21 && DealerHandValue < 18) { DealerHand.AddCard(MyDeck.pick()); DealerHandValue = DealerHand.handValue(); count++; if (count == 5 && DealerHandValue <= 21) { dealerHas5CardsWithValueSmallerThan21 = true; } } string winner = (dealerHas5CardsWithValueSmallerThan21 || (DealerHandValue >= PlayerHandValue && DealerHandValue <= 21)) ? "Dealer wins!" : "Player wins!"; if (DealerHandValue == PlayerHandValue && !dealerHas5CardsWithValueSmallerThan21) { winner = "It's a draw."; } MessageBoard = $"{winner}"; if (winner == "Dealer wins!") { DealerScore++; } if (winner == "Player wins!") { PlayerScore++; } HitButtonVisible = false; StayButtonVisible = false; ShuffleDeckButtonVisible = true; DealHandsButtonVisible = true; CardsInDeck = MyDeck.CardsLeft(); }
/// <summary> /// Give a number of cards to a player /// </summary> /// <param name="playerId">Player that receives cards</param> /// <param name="count">Number of cards the player receives</param> private void GiveCard(int playerId, int count = 1) { if (MyDeck.Count < count) { throw new NotEnoughCardsException(); } Player player = Players[playerId]; for (int i = 0; i < count; i++) { if (player.Hand.Any(card => card.ToStringShort == MyDeck.Peek().ToStringShort) == false) { Card card = myDeck.Pop(); player.AddCard(card); } else { Card card = myDeck.Pop(); Discarded.Push(card); card.Deck = Discarded; GiveCard(playerId); } } }
/// <summary> /// Reshuffle the deck /// </summary> public void Reshuffle() { MyDeck.Shuffle(); }