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)); }
public ActionResult Delete(ShowGameViewModel game) { if (ModelState.IsValid) { _gameService.Delete(game.Key); return(RedirectToAction("Games")); } return(View(game)); }
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); } } }
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")); } }
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")); } }