コード例 #1
0
        public GameState Deal(double bet)
        {
            //Clear last game. Make new game with old balance.
            NewGame(_defaultPlayer.Balance);

            //Try to set new bet balance
            TryPlaceBet(bet);

            //Check if insufficient funds
            if (_gameState.CurrentState == State.LowBalance)
            {
                return(null);
            }

            //Shuffle a new deck
            _deckService.NewDeck();

            //At the beginning of each hand the dealer deals two cards,
            //first to the player and then to himself.
            DealFirstHands();

            //Check for BlackJack
            if (HandLogic.HasBlackJack(_defaultPlayer))
            {
                EndGame();
            }

            //Setup a new GameState
            _gameState = new GameState(_defaultPlayer, _dealer, State.Open);

            return(_gameState);
        }
コード例 #2
0
        public GameState Hit()
        {
            //throw Exception if Hit() is called when game state is not open.
            if (_gameState.CurrentState != State.Open)
            {
                throw new GameStateException($"Can not call Hit() if game State is not Open. " +
                                             $"Current state is {_gameState.CurrentState.ToString()}");
            }

            //If the game has no winner, give a card to the player
            AddCardToHand(_defaultPlayer);

            //Check for player blackjack or bust
            if (HandLogic.HasBlackJack(_defaultPlayer) || HandLogic.IsBust(_defaultPlayer))
            {
                //Init the end game
                EndGame();
            }

            return(_gameState);
        }