Ejemplo n.º 1
0
        public async Task <ShowGameViewModel> ShowGame(int id)
        {
            ShowGameViewModel showGame = new ShowGameViewModel();
            Game game = await _gameRepository.GetGameById(id);

            showGame.Id   = game.Id;
            showGame.Name = game.Name;
            GetAllGamesViewModel allGamesItem = new GetAllGamesViewModel();
            var gamePlayers = await _gamePlayerRepository.GetGamePlayersByGameId(id);

            foreach (GamePlayer gp in gamePlayers)
            {
                Player p = await _playerRepository.GetPlayerById(gp.PlayerId);

                if (p.RoleId.Equals(Role.Player))
                {
                    showGame.PlayerId = p.Id;
                }
                else
                {
                    if (p.RoleId.Equals(Role.Dealer))
                    {
                        showGame.DealerId = p.Id;
                    }
                    else
                    {
                        showGame.BotsNumber += 1;
                    }
                }
            }

            return(showGame);
        }
        public ActionResult ShowGame(int gameid)
        {
            var model = new ShowGameViewModel {
                Game = Game.ActiveGames.First(p => p.ID == gameid)
            };

            return(View(model));
        }
Ejemplo n.º 3
0
        public ActionResult Delete(ShowGameViewModel game)
        {
            if (ModelState.IsValid)
            {
                _gameService.Delete(game.Key);
                return(RedirectToAction("Games"));
            }

            return(View(game));
        }
Ejemplo n.º 4
0
        public async Task FinishGame(ShowGameViewModel showGame)
        {
            var gamePlayers = await _gamePlayerRepository.GetGamePlayersByGameId(showGame.Id);

            GamePlayer dealer = (from gp in gamePlayers where gp.PlayerId == showGame.DealerId select gp).FirstOrDefault();

            foreach (GamePlayer gp in gamePlayers)
            {
                if (gp.Id == dealer.Id)
                {
                    continue;
                }
                else
                {
                    if (dealer.Points <= 21)
                    {
                        if (dealer.Points == 21 && gp.Points < 21)
                        {
                            gp.Result += " You lost";
                        }
                        else
                        {
                            if (gp.Points > dealer.Points && gp.Points <= 21)
                            {
                                gp.Result += " You won";
                            }
                            else
                            {
                                if (gp.Points == dealer.Points && gp.Points <= 21)
                                {
                                    gp.Result += " Even";
                                }
                                else
                                {
                                    gp.Result += " You lost";
                                }
                            }
                        }
                    }
                    else
                    {
                        if (gp.Points <= 21)
                        {
                            gp.Result += " You won";
                        }
                        else
                        {
                            gp.Result += " You lost";
                        }
                    }

                    await _gamePlayerRepository.UpdateGamePlayer(gp);
                }
            }
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> Enough(int gameId)
        {
            try
            {
                await _gameService.Enough(gameId);

                ShowGameViewModel game = await _gameService.ShowGame(gameId);

                await _gameService.FinishGame(game);

                return(RedirectToAction("Play", new { id = gameId }));

                return(View());
            }
            catch (Exception e)
            {
                return(View("Error"));
            }
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> Play(int id)
        {
            try
            {
                var gamePlayers = await _gameService.GetAllGamePlayersWithoutDealerByGameId(id);

                ShowGamePlayerViewModel dealer = await _gameService.GetGameDealerByGameId(id);

                ShowGameViewModel game = await _gameService.ShowGame(id);

                ViewBag.Dealer  = dealer;
                ViewBag.Players = gamePlayers;
                return(View(game));
            }
            catch (Exception e)
            {
                return(View("Error"));
            }
        }