Beispiel #1
0
        private static void Main(string[] args)
        {
            // Configure console window settings
            Console.Title = "♠ Blackjack Game" + new string(' ', 11) + "...by Konstantin Tarkus ([email protected])";
            Console.BufferWidth = Console.WindowWidth = 70;
            Console.BufferHeight = Console.WindowHeight = 26;
            Console.CursorVisible = false;

            // Initialize and configure a new game
            var game = new Game();
            game.Player.BalanceChanged += OnBalanceChanged;
            game.LastStateChanged += OnLastStateChanged;
            game.AllowedActionsChanged += OnAllowedActionsChanged;
            game.Dealer.Hand.Changed += OnHandChanged;
            game.Player.Hand.Changed += OnHandChanged;
            game.Play(balance: 500, bet: 5);

            while (true)
            {
                var key = Console.ReadKey(true);

                switch (key.Key)
                {
                    case ConsoleKey.Add:
                    case ConsoleKey.UpArrow:
                        game.Player.Bet += 5;
                        break;
                    case ConsoleKey.Subtract:
                    case ConsoleKey.DownArrow:
                        game.Player.Bet -= 5;
                        break;
                    case ConsoleKey.Enter:
                        if ((game.AllowedActions & GameAction.Deal) == GameAction.Deal)
                        {
                            game.Deal();
                        }
                        else
                        {
                            game.Stand();
                        }

                        break;
                    case ConsoleKey.Spacebar:
                        if ((game.AllowedActions & GameAction.Deal) == GameAction.Deal)
                        {
                            game.Deal();
                        }
                        else
                        {
                            game.Hit();
                        }

                        break;
                }
            }
        }
 // Signal for dealer to do his turn.
 private async void StandButton_Click(object sender, RoutedEventArgs e)
 {
     await blackjackInstance.Stand(views, totals, notifications, buttons);
 }