private void StartGame()
        {
            ClearTheBoard();

            _game = new Game();

            ComputerMove();
            ComputerMove();

            switch (CheckGameStatus())
            {
                case GameStatus.Exit:
                    Environment.Exit(0);
                    break;
                case GameStatus.Restart:
                    ClearTheBoard();
                    return;
            }

            MyMove();
            MyMove();

            switch (CheckGameStatus())
            {
                case GameStatus.Exit:
                    Environment.Exit(0);
                    break;
                case GameStatus.Restart:
                    ClearTheBoard();
                    return;
            }
        }
        public MainWindow() {
            InitializeComponent();
            g = new Game();

            comboBox1.ItemsSource = Enum.GetValues(typeof(Rank));
            comboBox2.ItemsSource = Enum.GetValues(typeof(Suit));
            (new UI_Sketch()).Show();
            //this.Close();
        }
Example #3
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;
                }
            }
        }
Example #4
0
 static void Main(string[] args)
 {
     Game game = new Game();
     game.GameStart();
     game.Play();
     if (game.Lost)
         Console.WriteLine("You lose! Too bad!");
     if (game.Won)
         Console.WriteLine("You win! Nice going!");
     if (game.Draw)
         Console.WriteLine("It's a draw! Oh well.");
     Console.ReadLine();
 }
 private static void TestGameClass()
 {
     Game game = new Game();
     game.ComputerMove();
     PrintStatusAndReturnWhetherGameHasEnded(game);
     game.UserMove();
     PrintStatusAndReturnWhetherGameHasEnded(game);
     game.ComputerMove();
     PrintStatusAndReturnWhetherGameHasEnded(game);
     game.UserMove();
     PrintStatusAndReturnWhetherGameHasEnded(game);
     game.ComputerMove();
     PrintStatusAndReturnWhetherGameHasEnded(game);
     game.UserMove();
     PrintStatusAndReturnWhetherGameHasEnded(game);
     game.ComputerMove();
     PrintStatusAndReturnWhetherGameHasEnded(game);
     game.ComputerMove();
     PrintStatusAndReturnWhetherGameHasEnded(game);
 }
        static void Main(string[] args)
        {
            Game game = new Game();

            game.ComputerMove();
            game.ComputerMove();
            if (PrintStatusAndReturnWhetherGameHasEnded(game))
                return;

            game.UserMove();
            game.UserMove();
            if (PrintStatusAndReturnWhetherGameHasEnded(game))
                return;

            while (true)
            {
                Console.Write("Would you like to draw another card? (Y/N) ");
                string input = Console.ReadLine();
                if (input == "Y" || input == "y")
                {
                    game.UserMove();
                    if (PrintStatusAndReturnWhetherGameHasEnded(game))
                        return;
                }
                else if (game.ComputerScore > game.UserScore)
                {
                    Console.WriteLine("Computer won :-(");
                    return;
                }
                game.ComputerMove();
                if (PrintStatusAndReturnWhetherGameHasEnded(game))
                    return;
            }

            //TestCardClass();
            //TestDeckClass();
            //TestGameClass();
        }
Example #7
0
        static void Main(string[] args)
        {
            Game g = new Game();
            while (!g.GameOver && g.ContinuePlay) {
                g.Play();
                Console.WriteLine("\n\n Game ended.");
                Console.ReadKey(true);
                Console.Clear();
            }

            switch (g.State) {
                case Game.GameState.CasinoOwner:
                    Console.WriteLine("\n GET OUT. GET OUT OF THIS PLACE. LEAVE, YOU DIRTY," +
                                      "\n ROTTEN, CHEATER. Probably hiding cards under your sleeve," +
                                      "\n or something else equally evil. You expect US to believe" +
                                      "\n that someone can get this 'lucky'? Bull." +
                                      "\n\n\n\n Bull.");
                    break;
                case Game.GameState.CardCounter:
                    Console.WriteLine("\n [You get up from the table, and all eyes are on you.]\n" +
                                      "\n \"What?\" you say, as jealous men and women stare down" +
                                      "\n the cause of their demise. The dealer makes a phone call" +
                                      "\n and you decide it's better to leave sooner rather than later.");
                    break;
                case Game.GameState.Rich:
                    Console.WriteLine("\n Wow. Just wow.\n" +
                                      "\n Good for you, buddy. Buy your friend a drink?" +
                                      "\n Hell, buy everyone drinks. Right?");
                    break;
                case Game.GameState.Over:
                    Console.WriteLine("\n Well done! You came out with more money" +
                                      "\n than you put in! Good thinking to quit" +
                                      "\n while you're ahead.");
                    break;
                case Game.GameState.Even:
                    Console.WriteLine("\n Well, you managed to break even.\n" +
                                      "\n Go home to your wife and kids, and try" +
                                      "\n not to gamble anymore with grocery money" +
                                      "\n unless you can actually play Blackjack.");
                    break;
                case Game.GameState.Under:
                    Console.WriteLine("\n You lost money! Quick! - to the slots!\n" +
                                      "\n On second thought, don't. Baby Billy needs" +
                                      "\n groceries, you selfish bum.");
                    break;
                case Game.GameState.Broke:
                    Console.WriteLine("\n You ran out of cash. You should feel bad.\n" +
                                      "\n Now you have to go back home to your wife" +
                                      "\n and explain why she can't buy groceries" +
                                      "\n for your family for TWO MONTHS because" +
                                      "\n you just HAD to go out gambling.\n" +
                                      "\n Asshole.");
                    break;
                default:
                    break;
            }

            Console.WriteLine("\n\n");
            Console.WriteLine(" Wins:Losses => {0}:{1}", g.NumWins, g.NumLosses);
            Console.WriteLine(" Largest win => {0}", g.LargestWin);
            Console.WriteLine(" Largest loss => {0}", g.LargestLoss);

            Console.ReadKey(true);
        }
 private static bool PrintStatusAndReturnWhetherGameHasEnded(Game game)
 {
     if (game.ComputerWon)
     {
         Console.WriteLine("Computer won :-(");
         return true;
     }
     else if (game.UserWon)
     {
         Console.WriteLine("You won :-))))");
         return true;
     }
     return false;
 }