public async Task <GenericResponseView <StartGameResponseView> > Start([FromBody] StartGameView model) { var response = new GenericResponseView <StartGameResponseView>(); response.Model = await _gameService.StartGame(UserId, model); return(response); }
private void starrtGameToolStripMenuItem_Click(object sender, EventArgs e) { var view = new StartGameView(); if (view.ShowDialog() == DialogResult.OK) { // Start Game ViewModel.StartGame(view.Args); } }
public async Task <MainGameView> NewGame(StartGameView view) { //TEST var mainView = new MainGameView(); mainView.Players.Add(new PlayerMainGameViewItem { Name = view.PlayerName, Id = Guid.NewGuid() }); return(mainView); }
public async Task <int> StartGame(StartGameView viewFromUI) { int gameId = await CreateGame(viewFromUI.PlayerName, viewFromUI.BotQuantity); var rounds = new List <Round>(); rounds.AddRange(await CreateHuman(viewFromUI.PlayerName, gameId)); if (viewFromUI.BotQuantity != 0) { rounds.AddRange(await CreateBots(viewFromUI.BotQuantity, gameId)); } rounds.AddRange(await CreateDealer(gameId)); return(gameId); }
public void Start() { StartGameView startGameView = new StartGameView(); startGameView.Render(); // Start view _timer = new Timer(); _timer.Interval = 2000; // Hook up the Elapsed event for the timer. _timer.Elapsed += HandleTimervalTimer; // Have the timer fire repeated events (true is the default) _timer.AutoReset = true; _timer.Enabled = true; // Start the timer PlayGame(); }
// View models private StartGameView CreateStartGameModel(string userId, string gameId) { var botList = GetBotsList(userId, gameId); var user = _playerRepository.Get(userId); var listCard = _cardMoveRepository .GetAll() .Where(t => t.GameId == gameId) .ToList(); var gameModel = new StartGameView(); gameModel.GameId = gameId; gameModel.User = CreateUser(user, listCard); gameModel.Bots.AddRange(GetBots(botList, listCard)); gameModel.Cardsleft = _deck.CardsLeft(); return(gameModel); }
public async Task <StartGameView> Start(int botCount) { //await SetDeck(); await SetBotCount(botCount); int handOverCount = 2; _round++; for (int i = 0; i < handOverCount; i++) { await GiveCardToEachPlayer(); } Dictionary <Player, List <Card> > playerCardsLastGame = await DefinePlayersFromLastGame(); List <PlayerGameViewItem> playerViewItemList = new List <PlayerGameViewItem>(); foreach (var player in playerCardsLastGame) { PlayerGameViewItem playerViewItem = new PlayerGameViewItem(); playerViewItem.Id = player.Key.Id; playerViewItem.Name = player.Key.Name; playerViewItem.GameNumber = player.Key.GameNumber; playerViewItem.PlayerType = player.Key.PlayerType; playerViewItem.Score = player.Value.Sum(c => c.Value); foreach (var card in player.Value) { playerViewItem.Cards.Add(new CardViewItem { Id = card.Id, Value = card.Value }); } playerViewItemList.Add(playerViewItem); } CountSum(ref playerViewItemList); StartGameView startViewModel = new StartGameView(); startViewModel.Players = playerViewItemList; return(startViewModel); }
public async Task <StartGameResponseView> StartGame(string userId, StartGameView model) { var game = new Game() { UserId = userId, State = UserGameStateType.InGame, NumberOfPlayers = model.NumberOfBots + 1 }; await _gameRepository.CreateAsync(game); var usersPoints = new UsersPoints() { UserId = userId, GameId = game.Id, Points = Constants.GameSettings.InitionalPoints }; await _usersPointsRepository.CreateAsync(usersPoints); var bots = (await _botRepository.GetRandomBotsAsync(model.NumberOfBots)).ToList(); var botsPoints = bots.Select(x => new BotsPoints() { BotId = x.Id, GameId = game.Id, Points = Constants.GameSettings.InitionalPoints, CardsInHand = Constants.GameSettings.InitialCardsInHand }) .ToList(); await _botsPointsRepository.AddRangeAsync(botsPoints); await InitialCardsDeal(game, usersPoints, bots, botsPoints); await _gameRepository.UpdateAsync(game); var response = new StartGameResponseView() { GameId = game.Id, State = (int)game.State }; return(response); }
public async Task <IHttpActionResult> Start([FromBody] StartGameView model) { MainGameView view = await _gameService.NewGame(model); return(Ok(view)); }
public async Task <IHttpActionResult> CreateGame(StartGameView startModel) { var result = await _gameService.StartGame(startModel); return(Ok(result)); }
public async Task <ActionResult> Start(int botCount) { StartGameView model = await _gameService.Start(botCount); return(View("Play", model.Players)); }
public async Task <ActionResult> StartGame(StartGameView viewModel) { var gameId = await _gameService.StartGame(viewModel); return(RedirectToAction("GetFirstRound", new { id = gameId })); }
public async Task <StartGameView> Start(string playerName, int countOfBots) { if (string.IsNullOrEmpty(playerName)) { throw new CustomServiceException("Player name cannot be null"); } var player = await _database.Players.GetByName(playerName); if (player == null) { throw new CustomServiceException("Player does not exist"); } var isActiveGame = await _database.Games.GetActiveByPlayerId(player.Id); var game = new Game(); if (isActiveGame != null) { game = isActiveGame; } else { game = new Game() { PlayerId = player.Id, Player = player, GameState = (GameStateType)GameStateTypeEnumView.Unknown }; await _database.Games.Create(game); var playerSteps = new List <PlayerStep> { CreatePlayerStep(player, game), CreatePlayerStep(player, game) }; await _database.PlayerSteps.Create(playerSteps); } var bots = new List <Bot>(); bots = (isActiveGame != null) ? await _database.Bots.GetAllBotsByGameId(isActiveGame.Id) : await _database.Bots.GetAllBotsByGameId(game.Id); if (bots == null || bots.Count == 0) { var stepsOfAllBots = new List <BotStep>(); var countOfAlreadyExistBots = await _database.Bots.Count() + 1; var createdBots = new List <Bot>(); if (countOfBots > 0) { for (int i = 0; i < countOfBots; i++) { var bot = new Bot() { Balance = 1000, Bet = 0, Name = $"Bot {countOfAlreadyExistBots}" }; createdBots.Add(bot); countOfAlreadyExistBots += 1; stepsOfAllBots.Add(CreateBotStep(bot, game)); stepsOfAllBots.Add(CreateBotStep(bot, game)); } } await _database.Bots.Create(createdBots); await _database.BotSteps.Create(stepsOfAllBots); } await _database.Players.Update(player); var result = new StartGameView() { Id = game.Id, GameState = (GameStateTypeEnumView)game.GameState, CountOfBots = countOfBots, Player = new PlayerStartGameView() { PlayerId = game.Player.Id, UserName = game.Player.UserName, Balance = game.Player.Balance, Bet = game.Player.Bet } }; return(result); }
public async Task <ActionResult> StartNewRound() { StartGameView model = await _gameLogicService.Start(); return(PartialView("StartNewRound", model)); }
public async Task <ActionResult> HandOverCards() { StartGameView model = await _gameLogicService.Start(); return(View(model.Players)); }