Exemplo n.º 1
0
        public IActionResult CreateGame(CreateLudoGameModel model)
        {
            // Create game
            model.GameId = Api.CreateGame(client);
            logger.LogInformation("User created a new game.");

            // Add all players that aren't null to the game.
            if (model.Player1Name != null)
            {
                Api.AddPlayer(model.GameId, model.Player1Name, "0", client);
                logger.LogInformation($"User added player: {model.Player1Name}");
            }
            if (model.Player2Name != null)
            {
                Api.AddPlayer(model.GameId, model.Player2Name, "1", client);
                logger.LogInformation($"User added player: {model.Player2Name}");
            }
            if (model.Player3Name != null)
            {
                Api.AddPlayer(model.GameId, model.Player3Name, "2", client);
                logger.LogInformation($"User added player: {model.Player3Name}");
            }
            if (model.Player4Name != null)
            {
                Api.AddPlayer(model.GameId, model.Player4Name, "3", client);
                logger.LogInformation($"User added player: {model.Player4Name}");
            }

            // Set cookies
            Api.AssignPlayerCookies(model, Response);

            return(RedirectToAction("Lobby"));
        }
Exemplo n.º 2
0
        static public void AssignPlayerCookies(CreateLudoGameModel model, Microsoft.AspNetCore.Http.HttpResponse Response)
        {
            CookieOptions cookie = new CookieOptions();

            cookie.Expires = DateTime.Now.AddHours(1);
            Response.Cookies.Append("gameid", model.GameId.ToString(), cookie);
        }