示例#1
0
        private void onePlayerButton_Click(object sender, EventArgs e)
        {
            this.Hide();

            onePlayerGame game1 = new onePlayerGame();

            game1.StartPosition = FormStartPosition.CenterScreen;
            game1.Show();

            bettingWindow betWindow = new bettingWindow();

            betWindow.StartPosition = FormStartPosition.CenterScreen;
            betWindow.Show();
        }
        //Starts game after the player's bets have been placed
        //Deals initial cards, then adds their value to the player's hand total
        //-------------------------------------------->Chip total is not being updated, need to fix <---------------------------------------------------
        private void dealButton_Click(object sender, EventArgs e)
        {
            bettingWindow betWindow = new bettingWindow();

            var playerFirstCard = deck[12];

            utilities.displayCard(playerFirstCard, 405, 375, playerCard1, this);
            deck.Remove(playerFirstCard);

            var playerSecondCard = deck[11];

            utilities.displayCard(playerSecondCard, 455, 375, playerCard2, this);
            deck.Remove(playerSecondCard);

            player1.handTotal           = player1.handTotal + playerFirstCard.cardValue + playerSecondCard.cardValue;
            playerHandTotalTextBox.Text = "Hand Total: " + player1.handTotal;

            var dealerFirstCard = deck[random.Next(deck.Count - 1)];

            utilities.displayCard(dealerFirstCard, 405, 5, dealerCard1, this);
            deck.Remove(dealerFirstCard);

            var dealerSecondCard = deck[random.Next(deck.Count - 1)];

            utilities.displayCard(dealerSecondCard, 455, 5, dealerCard2, this);
            deck.Remove(dealerSecondCard);

            dealer.handTotal            = dealer.handTotal + dealerFirstCard.cardValue + dealerSecondCard.cardValue;
            dealerHandTotalTextBox.Text = "Hand Total: " + dealer.handTotal;

            dealButton.Enabled             = false;
            playerHandTotalTextBox.Enabled = false;
            dealerHandTotalTextBox.Enabled = false;

            //Condition if both the player and dealer are dealt 21
            if (player1.handTotal == 21 && dealer.handTotal == 21)
            {
                MessageBox.Show("Push! Waged chips have been returned");

                player1.chipTotal = player1.chipTotal + betWindow.bet;

                utilities.reset(this);
                utilities.resetHandTotals(this);
                deck.Clear();
                utilities.createDeck(this);

                betWindow.StartPosition = FormStartPosition.CenterScreen;
                betWindow.Show();
            }

            //Condition if player is dealt 21 and the dealer is not
            if (player1.handTotal == 21 && dealer.handTotal != 21)
            {
                MessageBox.Show("Blackjack, you win!");

                player1.chipTotal = player1.chipTotal + (betWindow.bet * 2);

                utilities.reset(this);
                utilities.resetHandTotals(this);
                deck.Clear();
                utilities.createDeck(this);

                betWindow.StartPosition = FormStartPosition.CenterScreen;
                betWindow.Show();
            }

            //Condition if dealer is dealt 21 and player is not
            if (dealer.handTotal == 21 && player1.handTotal != 21)
            {
                MessageBox.Show("Dealer has blackjack, you lose!");

                utilities.reset(this);
                utilities.resetHandTotals(this);
                deck.Clear();
                utilities.createDeck(this);

                betWindow.StartPosition = FormStartPosition.CenterScreen;
                betWindow.Show();
            }
        }