Пример #1
0
        public bool DealPlayerCard(ushort playerNumber)
        {
            if (_players.ContainsKey(playerNumber) == false)
            {
                return(false);
            }
            if (_players[playerNumber].IsPlayable == false)
            {
                return(false);
            }
            if (_players[playerNumber].IsBust)
            {
                return(false);
            }

            _gameStatus = GameStatusEnum.PlayersTurn;
            CardModel card = _cardChute.DealCard();

            _players[playerNumber].Cards.Add(card);

            // if playerNumber is now unplayable, we need to pass on playability to next player
            // player would be unplayable because he/she just bust!
            if (_players[playerNumber].IsPlayable == false)
            {
                int nextKeyIndex = _players.IndexOfKey(playerNumber) + 1;
                if (nextKeyIndex < _players.Keys.Count)
                {
                    ushort nextKey = _players.Keys[nextKeyIndex];
                    _players[nextKey].IsPlayable = true;
                }
                else
                {
                    _gameStatus        = GameStatusEnum.DealersTurn;
                    _dealer.IsPlayable = true;
                }
            }
            return(true);
        }
Пример #2
0
        public bool DealDealerCard()
        {
            bool return_value = false;

            if (_gameStatus != GameStatusEnum.DealersTurn)
            {
                // TODO log exception
                throw new Exception("Unexpected GameStatus in DealDealerCard");
            }

            if (_dealer.MustHit == true && _dealer.IsBust == false)
            {
                return_value = true;
                CardModel card = _cardChute.DealCard();
                _dealer.Cards.Add(card);
            }
            // if dealer is done, assign player results and note that the game is over
            if (_dealer.IsBust || !_dealer.MustHit)
            {
                _gameStatus = GameStatusEnum.GameOver;
                AssignPlayerResults();
            }
            return(return_value);
        }