예제 #1
0
        public GameViewItem GetView(Game game, List <PlayerInGame> playersInGame, List <long> deck)
        {
            foreach (var playerInGame in playersInGame)
            {
                game.PlayersInGame.Where(player => player.PlayerId == playerInGame.PlayerId).FirstOrDefault().CardsInHand = playerInGame.CardsInHand;
            }

            var getGameViewModel = new GameViewItem()
            {
                Bots = new List <PlayerViewItem>()
            };

            var human  = game.PlayersInGame.Where(player => player.Player.Type == PlayerType.Human).FirstOrDefault();
            var dealer = game.PlayersInGame.Where(player => player.Player.Type == PlayerType.Dealer).FirstOrDefault();

            getGameViewModel.Human          = Mapper.Map <Player, PlayerViewItem>(human.Player);
            getGameViewModel.Human.BetValue = human.BetValue;
            getGameViewModel.Human.Hand     = GetHand(human.CardsInHand);
            getGameViewModel.Dealer         = Mapper.Map <Player, DealerViewItem>(dealer.Player);
            getGameViewModel.Dealer.Hand    = GetHand(game.PlayersInGame.Where(player => player.PlayerId == dealer.PlayerId).FirstOrDefault().CardsInHand);

            foreach (var playerInGame in game.PlayersInGame.Where(player => player.Player.Type == PlayerType.Bot))
            {
                var bot = new PlayerViewItem();

                bot          = Mapper.Map <Player, PlayerViewItem>(playerInGame.Player);
                bot.BetValue = playerInGame.BetValue;

                bot.Hand = GetHand(playerInGame.CardsInHand);

                getGameViewModel.Bots.Add(bot);
            }

            if (getGameViewModel.Human.Hand.CardsInHand.Count() != 0)
            {
                getGameViewModel.Options = UserMessages.OptionDrawCard;
            }

            if ((getGameViewModel.Human.Hand.CardsInHand.Count() == 0) ||
                (getGameViewModel.Human.BetValue == 0))
            {
                getGameViewModel.Options = UserMessages.OptionSetBet(string.Empty);
            }

            getGameViewModel.Deck = deck;

            return(getGameViewModel);
        }
예제 #2
0
        private async Task <string> UpdateScore(PlayerViewItem player, int dealerCardsValue, long gameId)
        {
            _logger.Log(LogHelper.GetEvent(player.Id, gameId, UserMessages.PlayerValue(player.Hand.CardsInHandValue, dealerCardsValue)));

            if ((player.Hand.CardsInHandValue > dealerCardsValue) &&
                (player.Hand.CardsInHandValue <= Constant.WinValue))
            {
                await UpdateWonPlayersPoints(player.Id, gameId, player.BetValue, player.Points);

                return(UserMessages.OptionWin);
            }

            if ((player.Hand.CardsInHandValue <= Constant.WinValue) &&
                (dealerCardsValue > Constant.WinValue))
            {
                await UpdateWonPlayersPoints(player.Id, gameId, player.BetValue, player.Points);

                return(UserMessages.OptionWin);
            }

            if (player.Hand.CardsInHandValue > Constant.WinValue)
            {
                await UpdateLostPlayersPoints(player.Id, gameId, player.BetValue, player.Points);

                return(UserMessages.OptionLose);
            }

            if ((dealerCardsValue > player.Hand.CardsInHandValue) &&
                (dealerCardsValue <= Constant.WinValue))
            {
                await UpdateLostPlayersPoints(player.Id, gameId, player.BetValue, player.Points);

                return(UserMessages.OptionLose);
            }

            _logger.Log(LogHelper.GetEvent(player.Id, gameId, UserMessages.PlayerDraw));
            return(UserMessages.OptionDraw);
        }