public JsonResult CreateGameWithGrid([FromBody] GameDto vm) { // Map to the Entity var game = Mapper.Map <Game>(vm); var result = _repository.GetGameById(game.GameInfo.Id); if (result.Success) { _logger.LogError($"La partie ne peut pas être créée car son identifiant '{game.GameInfo.Id}' est déjà utilisé"); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json("Une erreur s'est produite lors de la sauvegarde du nouveau jeu")); } //Create var createResult = _repository.AddGame(game) .OnSuccess(() => _repository.SaveAll()); if (createResult.Failure) { _logger.LogError($"Échec de la sauvegarde du nouveau jeu : {createResult.Error}"); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json($"Échec de la sauvegarde du nouveau jeu : {createResult.Error}")); } Response.StatusCode = (int)HttpStatusCode.OK; return(Json(Mapper.Map <GameDto>(game))); }
public void Setup() { GameRepository = new GameRepositoryInMemory(); GameRepository.AddGame(new Game { Team1 = "Foo", Team2 = "Bar", Score1 = 0, Score2 = 1 }); GameRepository.AddGame(new Game { Team1 = "Foo", Team2 = "Bar", Score1 = 1, Score2 = 0 }); GameRepository.AddGame(new Game { Team1 = "Foo", Team2 = "Bar", Score1 = 0, Score2 = 1 }); GameRepository.AddGame(new Game { Team1 = "Foo", Team2 = "Bar", Score1 = 1, Score2 = 0 }); }
public void LoadDefaultModel() { if (_defaultModelLoaded == false) { Group groupA = new Group("A"); Group groupB = new Group("B"); _groupRepository.AddGroup(groupA); _groupRepository.AddGroup(groupB); Team hrv = new Team("Hrvatska", groupA); Team fra = new Team("Francuska", groupA); Game GameA = new Game(hrv, fra, groupA); Team den = new Team("Danska", groupB); Team ger = new Team("Njemacka", groupB); Game GameB = new Game(den, ger, groupB); _teamRepository.AddTeam(hrv); groupA.Teams.Add(hrv); _teamRepository.AddTeam(fra); groupA.Teams.Add(fra); _teamRepository.AddTeam(den); groupB.Teams.Add(den); _teamRepository.AddTeam(ger); groupB.Teams.Add(ger); _gameRepository.AddGame(GameA); _gameRepository.AddGame(GameB); _defaultModelLoaded = true; } }
/// <summary> /// This is the main entry point for your service replica. /// This method executes when this replica of your service becomes primary and has write status. /// </summary> /// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service replica.</param> protected override async Task RunAsync(CancellationToken cancellationToken) { _repo = new ServiceFabricGameRepository(this.StateManager); var game1 = new Game { Id = "destiny2", Title = "Destiny 2", MaxPlayersSupported = 8 }; var game2 = new Game { Id = "battlefield1", Title = "Battle Field I", MaxPlayersSupported = 32 }; var game3 = new Game { Id = "mineCraft", Title = "MineCraft", MaxPlayersSupported = 4 }; await _repo.AddGame(game1); await _repo.AddGame(game2); await _repo.AddGame(game3); //IEnumerable<Game> all = await _repo.GetAllGames(); }
public void ShouldAddAGame() { var game = new GameModel(Guid.NewGuid()); gameRepository.AddGame(game); var result = gameRepository.GetGame(game.Id); Assert.AreEqual(game, result); }
public IActionResult PlayGame(int selection, User user) { Random rnd = new Random(); //1 : Rock, 2: Paper, 3:Scissors int compSelection = rnd.Next(1, 3); int result = 0; if (compSelection == selection) { result = 0; //draw } else if ((compSelection == 1 && selection == 2) || (compSelection == 2 && selection == 3) || (compSelection == 3 && selection == 1)) { result = 1; //user wins } else { result = 2; //user loses } User actualUser = repo.GetUserByEmail(user.Email); Game game = new Game { //Gamer = actualUser, TimeStamp = DateTime.Now, Result = result }; repo.AddGame(game, actualUser); ViewBag.UserName = actualUser.Name; ViewBag.UserEmail = actualUser.Email; return(View("ViewResult", game)); }
private void BtnAddAnswer_Tapped(object sender, TappedRoutedEventArgs e) { Game newGame = new Game(); gameRepo.AddGame(newGame); Frame.Navigate(typeof(GameNew), (newGame)); }
public void AddGame(GameVM game, int userProfileID) { game.Active = true; game.PlayerTurn = userProfileID; game.PlayerOne = userProfileID; game.LastLetter = GetLetter(); Game.AddGame(game); }
private void BtnCreateConfirm_Tapped(object sender, TappedRoutedEventArgs e) { Game newGame = new Game(); newGame.Title = txtCreateNewGame.Text.ToUpper(); gameRepo.AddGame(newGame); Frame.Navigate(typeof(GameDetails), (newGame)); }
public async Task CreateGame(GameCreationModel creationModel) { AssertExtensions.NotNull(creationModel, nameof(creationModel)); await ThrowIfActiveGameAlreadyExist(); await _gameStateRepository.AddGame(creationModel.Size); }
public IActionResult Index(string name) { _gameRepository.AddGame(new GameSet() { GameName = name }); return(RedirectToAction("Index")); }
/// <summary> /// Creates and initialises a new game. /// </summary> /// <param name="numberOfRounds">The number of rounds for the new game.</param> /// <param name="secondsPerRound">The number of seconds per round.</param> public async Task CreateNewGameAsync(int numberOfRounds, int secondsPerRound) { var diceGrid = _gridFactory.BuildWithClassicDice(); var game = new Game(_eventPublisher, diceGrid, numberOfRounds, secondsPerRound); _gameRepository.AddGame(game); await game.InitialiseNewGameAsync(); }
public IActionResult Create([Bind("Id,Title,ReleaseDate,Genre,Platform,Developer,Price")] Game game) { if (ModelState.IsValid) { _gameRepository.AddGame(game); return(RedirectToAction(nameof(Index))); } return(View(game)); }
public IActionResult AddGame(Game game) { if (ModelState.IsValid) { _gameRepository.AddGame(game); return(RedirectToAction("AddGameComplete")); } return(View(game)); }
public async Task AddGameToDb() { // Act var game = await _gameRepository.AddGame(); TestData.Games.FlorisGame = game; // Assert Assert.IsNotNull(game); }
public async Task <ApiGame> AddNewGame([FromBody] ApiGame game) { var result = await iRepository.AddGame(new Game() { Description = game.Description, Player1Token = game.Player1Token, Status = GameStatus.Waiting, }); return(ApiGame.GameToApiGame(result)); }
public IActionResult CompleteAdd(AddGameViewModel model) { var userId = _userManager.GetUserId(HttpContext.User); if (model != null && model.ChosenCategoryGuid != Guid.Empty) { _gameRepository.AddGame(model.GameName, model.ChosenCategoryGuid, userId); } return(RedirectToAction("Game", "Home")); }
public async Task CreateGame(GameSetupDto gameSetupDto) { var user = GetCurrentUser(); var gameSetup = _mapper.Map <GameSetup>(gameSetupDto); var game = new Game(gameSetup); game.Players.Add(new Player(user)); _gameRepository.AddGame(game); await UpdateGame(game); await GetAllGames(); await SendMessage($"User {user.Name} has created new game", TypeOfMessage.Server); }
public IActionResult Index( [FromQuery(Name = "fieldSize")] [DefaultValue(4)] int fieldSize) { var game = game2048Handler.StartGame(fieldSize); gameRepository.AddGame(game); var gameDto = Mapper.MapFromGameToGameDto(game); return(Ok(gameDto)); }
public async Task <IActionResult> Create([Bind("GameID,Title,Description,MinPlayer,MaxPlayer,ImgPath,ThumbPath")] Game game) { if (ModelState.IsValid) { await _gamesRepository.AddGame(game); return(RedirectToAction(nameof(Index))); } return(View(game)); /***TODO: this used to redirect to newely created game's detail view. It dont now!!! * Add game does not return newely created ID, it needs to!!!!! */ }
public async Task <ActionResult <GameTokenDto> > CreateGame([FromBody] CreateGameCommand command) { Game game = new Game( command.Name, command.Password, command.MaxPlayers.Value, command.AdminName, command.AdminBuyIn.Value, command.SmallBlind.Value, command.BigBlind.Value); _gameRepository.AddGame(game); await _lobbyHub.Clients.All.SendAsync("gamecreated", _mapper.Map <GameListItemDto>(game)); return(Ok(GenerateToken(game.Id, game.Players.First().Id))); }
public GameDto AddGame(GameDto game) { Game gameEntity = _mapper.Map <Game>(game); Random rng = new Random(); User user = _userRepository.GetUser(game.OwnerPlayer.Email); if (rng.Next(2) == 1) { gameEntity.WhitePlayer = user; } else { gameEntity.BlackPlayer = user; } gameEntity.OwnerPlayer = user; gameEntity = _gameRepository.AddGame(gameEntity); return(_mapper.Map <GameDto>(gameEntity)); }
public async Task <ApiResponse <GameModel> > CreateGame() { if (User.Identity.IsAuthenticated) { return(BadRequest("User is already in a game.")); } var game = new Game( Guid.NewGuid().ToString().Substring(0, 6).ToUpper(), _nameGenerator.GetRandomName(), Team.Red); await _repository.AddGame(game); var player = game.Players.First(); await SignInAsPlayer(player, game.Code); return(Created(game.Code, new GameModel(game, player.Id))); }
/// <summary> /// Make a play during the game /// </summary> /// <param name="match">The match</param> /// <param name="playerOneChoice">The GameItem</param> /// <param name="playerTwoChoice">The GameItem</param> /// <returns>The updated Game Dto</returns> public MatchInfo PlayGame(Match match, GameItem playerOneChoice, GameItem playerTwoChoice) { // Check we have not exceeded the allowed number of plays per game if (match.Games.Count >= match.GameCount) { throw new NotSupportedException("Game play count exceeded"); } // Get game result var result = CalculateGameResult(playerOneChoice, playerTwoChoice); // Add the game to the repo _gameRepository.AddGame(match, playerOneChoice, playerTwoChoice, result); // Check if we should complete the Match if (match.Games.Count >= match.GameCount) { _gameRepository.CompleteMatch(match, CalculateMatchResult(match)); } return(GetMatchInfo(match.Id)); }
public ActionResult NewGame([FromBody] NewGameRequest ngr) { if (!TokenValidator.ValidatePlayerToken(ngr.PlayerToken)) { return(BadRequest()); } Game newGame = new Game { Description = ngr.GameDescription }; if (ngr.PlayerPickedWhite) { newGame.Player1Token = ngr.PlayerToken; } else { newGame.Player2Token = ngr.PlayerToken; } newGame.Token = TokenGenerator.GenerateGameToken(ngr.PlayerToken); iRepository.AddGame(newGame); return(CreatedAtAction("NewGame", newGame)); }
public IActionResult Post(L_Game Game) { _GameRepository.AddGame(Game); return(CreatedAtAction(nameof(GetById), new { id = Game.GameId }, Game)); }
public void StartTournament(Tournament tournament) { tournament.Contestants.Shuffle(); var paddedNumberOfPlayers = Math.Pow(2, (int)Math.Ceiling((Math.Log(tournament.Contestants.Count) / Math.Log(2)))); var numberOfRounds = (int)(Math.Log(paddedNumberOfPlayers) / Math.Log(2)); var numberOfGamesInARound = paddedNumberOfPlayers / 2; for (int i = 1; i <= numberOfRounds; i++) { TournamentRound tournamentRound = new TournamentRound(i); for (int j = 1; j <= numberOfGamesInARound; j++) { var game = new Game(new GameSetup() { PlayersSetup = PlayersSetup.Individual, RoundsToWin = tournament.TournamentSetup.RoundsToWin, GameType = tournament.TournamentSetup.GameType, BannedCards = tournament.TournamentSetup.BannedCards, DrawFourDrawTwoShouldSkipTurn = tournament.TournamentSetup.DrawFourDrawTwoShouldSkipTurn, MatchingCardStealsTurn = tournament.TournamentSetup.MatchingCardStealsTurn, MaxNumberOfPlayers = 2, Password = tournament.TournamentSetup.Password, ReverseShouldSkipTurnInTwoPlayers = tournament.TournamentSetup.ReverseShouldSkipTurnInTwoPlayers, WildCardCanBePlayedOnlyIfNoOtherOptions = tournament.TournamentSetup.WildCardCanBePlayedOnlyIfNoOtherOptions, CanSeeTeammatesHandInTeamGame = false, DrawAutoPlay = tournament.TournamentSetup.DrawAutoPlay, SpectatorsCanViewHands = tournament.TournamentSetup.SpectatorsCanViewHands, LimitColorChangingCards = tournament.TournamentSetup.LimitColorChangingCards, NumberOfStandardDecks = tournament.TournamentSetup.NumberOfStandardDecks }, tournament.Id); _gameRepository.AddGame(game); var tournamentRoundGame = new TournamentRoundGame(j, game) { Game = { Players = new List <Player>(2) } }; tournamentRound.TournamentRoundGames.Add(tournamentRoundGame); } numberOfGamesInARound /= 2; tournament.TournamentRounds.Add(tournamentRound); } for (int i = 0; i < tournament.TournamentRounds[0].TournamentRoundGames.Count; i++) { tournament.TournamentRounds[0].TournamentRoundGames[i].Game.Players.Add(new Player(tournament.Contestants[i].User, 1) { LeftGame = true }); if (tournament.Contestants.ElementAtOrDefault(tournament.TournamentRounds[0].TournamentRoundGames.Count + i) != null) { tournament.TournamentRounds[0].TournamentRoundGames[i].Game.Players.Add(new Player(tournament.Contestants[tournament.TournamentRounds[0].TournamentRoundGames.Count + i].User, 2) { LeftGame = true }); tournament.TournamentRounds[0].TournamentRoundGames[i].Game.GameLog.Add("Game started. (type /hand in chat for newbie tips)"); tournament.TournamentRounds[0].TournamentRoundGames[i].Game.GameLog.Add("If you need more detailed log info, press the 'Game info' button."); tournament.TournamentRounds[0].TournamentRoundGames[i].Game.GameLog.Add("This is the game log summary. We will display the last 3 entries here."); _gameManager.StartNewGame(tournament.TournamentRounds[0].TournamentRoundGames[i].Game); } else { tournament.TournamentRounds[0].TournamentRoundGames[i].Game.GameEnded = true; tournament.TournamentRounds[0].TournamentRoundGames[i].Game.Players.First().RoundsWonCount = tournament.TournamentSetup.RoundsToWin; UpdateTournament(tournament, tournament.TournamentRounds[0].TournamentRoundGames[i].Game); } } tournament.TournamentStarted = true; }
/* * Given a Game entity, add that game to the daabase */ public Game CreateGame(Game game) { return(_gameRepository.AddGame(game)); }
public async Task <int> AddGame([FromBody] Game game) { return(await _gameRepository.AddGame(game)); }
public GameDto CreateGame(GameDto gameDto) { var game = _gameRepository.AddGame(Mapper.MapGameDtoToGame(gameDto)); return(Mapper.MapGameToGameDto(game)); }