コード例 #1
0
 private void ShuffleDeck()
 {
     MyDeck.reset();
     CardsInDeck            = MyDeck.CardsLeft();
     MessageBoard           = "";
     DealHandsButtonVisible = true;
 }
コード例 #2
0
        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();
        }
コード例 #3
0
        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    = "";
            }
        }
コード例 #4
0
        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    = "";
        }
コード例 #5
0
        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();
        }