public ActionResult <JoinGameResponseDto> Join(JoinGameInputDto input)
        {
            Game g;

            try
            {
                g = GameStore.GetGameByJoinCode(input.JoinCode);
                g.ValidateJoin(input.PlayerName);
            } catch (Exception e)
            {
                return(ValidationProblem(e.Message));
            }

            Player p = new Player(input.PlayerName);

            g.Players.Add(p);

            return(new JoinGameResponseDto()
            {
                Game = g,
                Me = p
            });
        }
Пример #2
0
        public async Task <GamePlayerDto> CreateAsync(CreatePlayerDto model)
        {
            Player p = ObjectMapper.Map <Player>(model);

            p.Id = Guid.NewGuid();
            Game g = GameStore.GetGameByJoinCode(model.JoinCode);

            if (g.Players.Select(p => p.Name.ToLower()).Contains(model.Name.ToLower()))
            {
                throw new UserFriendlyException("Name already taken", $"The name '{model.Name}' has already been taken by another player!");
            }
            if (model.Name.Length > 20)
            {
                throw new UserFriendlyException("Name too long", $"Name cannot be longer than 20 characters.");
            }
            g.Players.Add(p);
            GameStore.AddOrUpdateGame(g);
            GamePlayerDto gp = new GamePlayerDto();

            gp.Game   = g;
            gp.Player = p;
            return(gp);
        }
Пример #3
0
        public void GetGameByJoinCode()
        {
            Game g = SetupGameStoreWithSingleGame();

            Assert.AreEqual(g, GameStore.GetGameByJoinCode(g.JoinCode));
        }