예제 #1
0
        public void PlayRound()
        {
            if (_player == null)
            {
                _player = InitializePlayer();
            }

            // Bet
            int bet = _playerView.AskForBet(_player);

            _player.Bet = bet;

            // Initialize round
            _gameService.TableUpdated += HandleTableUpdated;
            _gameService.JoinGame(_player);

            // The game could finish on the first round if the player has blackjack
            if (!_playerModel.Table.IsGameFinished())
            {
                // Start round
                PlayerAction playerAction;
                do
                {
                    playerAction = _playerView.AskForAction();

                    switch (playerAction)
                    {
                    case PlayerAction.Hit:
                        _gameService.Hit(_player.Name, _playerModel.Table);
                        break;

                    case PlayerAction.Stand:
                        _gameService.Stand(_player.Name, _playerModel.Table);
                        break;

                    default:
                        break;
                    }
                } while (playerAction != PlayerAction.Stand && !_playerModel.Table.IsGameFinished());
            }

            // Round ended
            _gameService.TableUpdated -= HandleTableUpdated;
        }