Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            // Game setup
            // A game has a dealer, players and a shuffled deck
            // The dealer and all players have a hand
            var dealer = new Dealer()
            {
                name  = "Dealer",
                hands = new List <Hand>()
                {
                    new Hand()
                }
            };

            var players = new List <Player>()
            {
                new Player()
                {
                    name = "Player", hands = new List <Hand>()
                    {
                        new Hand()
                    }
                }
            };

            var game = new Game(players, dealer, 1);

            // Deal from top of deck to all players
            game.Deal();

            // Show the cards and current scores
            ShowCurrentGameState(game, false);

            // Wait for user input
            ConsoleKeyInfo userKey;

            do
            {
                userKey = Console.ReadKey(true);

                // Hit
                if (userKey.Key == ConsoleKey.H)
                {
                    game.Hit(players[0].hands[0]);
                    ShowCurrentGameState(game, false);
                }
                // Stand
                else if (userKey.Key == ConsoleKey.S)
                {
                    game.Stand(dealer.hands[0]);
                    RevealDealerCards(dealer);
                    ShowCurrentGameState(game, true);
                    Environment.Exit(0);
                }
            } while (userKey.Key != ConsoleKey.Escape);
        }
Ejemplo n.º 2
0
        private void btnBet_Click(object sender, EventArgs e)
        {
            game.playerList[game.currentHand - 1] = game.playerList[0];
            if (game.playerList.Count() > 1)
            {
                game.playerList.RemoveAt(1);
            }
            disableBetting();
            int bet = Convert.ToInt32(lblPreviousBet.Text);

            if (bet > game.playerList[game.currentHand - 1].money)
            {
                MessageBoxButtons button = MessageBoxButtons.OK;
                MessageBox.Show("You must have the amount you are trying to bet", "Betting Error", button);
                enableBetting();
            }
            else if (bet < 1)
            {
                MessageBoxButtons button = MessageBoxButtons.OK;
                MessageBox.Show("You must bet a value greater than that.", "Betting Error", button);
                enableBetting();
            }
            else
            {
                game.playerList[game.currentHand - 1].doBet(bet);
                game.playerList[game.currentHand - 1].previousBet = bet;
                lblPlayerBetUser1.Text = bet.ToString();
                UpdatePlayerMoney(game.playerList[game.currentHand - 1]);
                //lblPlayerMoney.Text = game.player.money.ToString();
                updateMoneyLabels(game.playerList[game.currentHand - 1]);
                updateMoneyLabels(game.playerList[game.currentHand - 1]);
                game.Deal(false);
                displayCards();
                if (game.playerList[game.currentHand - 1].score == 21)
                {
                    PlayerBlackJack(game.playerList[game.currentHand - 1]);
                }
                else
                {
                    enableHitStand();
                }
            }
        }