Пример #1
0
        public async Task <IActionResult> AddPlayer(Player player)
        {
            PlayerColor.SetPlayerColor(player);
            var       gameId = HttpContext.Session.GetInt32("game");
            GameModel output = new GameModel();

            if (ModelState.IsValid)
            {
                await GetAddPlayer.AddPlayer(client, (int)gameId, player);

                output = await GetGameInfo.GetGame(client, (int)gameId);

                output.Player = new Player()
                {
                    Id = player.Id + 1
                };
            }
            else
            {
                output = await GetGameInfo.GetGame(client, (int)gameId);

                output.Player = new Player()
                {
                    Id = player.Id
                };
            }
            Log.Information($"GameID: {gameId} created a player named: {player.Name} with the color: {player.Color}(IP: {HttpContext.Connection.RemoteIpAddress.ToString()})");

            output.PlayerList = await GetPlayerInfo.GetPlayerPosition((int)gameId, output.NumberOfPlayers, client);

            return(View("Newgame", output));
        }
Пример #2
0
        public async Task <IActionResult> MovePiece(GameModel htmlModel)
        {
            var gameId = HttpContext.Session.GetInt32("game");

            GameModel output = await GetGameInfo.GetGame(client, (int)gameId);

            output.MovePiece          = new MovePiece();
            output.WhosTurn           = counter;
            output.MovePiece.PlayerId = counter.WhosTurn;

            output.Player = await GetCurrentPlayer.GetPlayer(client, (int)gameId, counter);

            output.MovePiece.PieceId        = htmlModel.MovePiece.PieceId - 1;
            output.MovePiece.NumberOfFields = htmlModel.DiceThrow;
            await GetMovePiece.MovePiece(client, output.MovePiece, (int)gameId);

            output.PlayerList = await GetPlayerInfo.GetPlayerPosition((int)gameId, output.NumberOfPlayers, client);

            counter.UpdatePlayerTurn(output.NumberOfPlayers);

            output.Player = output.PlayerList[counter.WhosTurn];
            output.Winner = await GetWinner.GetPlayer(client, (int)gameId);

            if (output.Winner != null)
            {
                Log.Information($"{output.Winner.Name} won the game: {gameId}! (IP: {HttpContext.Connection.RemoteIpAddress.ToString()})");
            }
            ModifyPlayerStartPosition.SetStartPosition(output);

            return(View("Gameboard", output));
        }
Пример #3
0
        public async Task <IActionResult> RollDice()
        {
            var       gameId = HttpContext.Session.GetInt32("game");
            GameModel output = await GetGameInfo.GetGame(client, (int)gameId);

            output.Player = await GetCurrentPlayer.GetPlayer(client, (int)gameId, counter);

            output.DiceThrow = await GetDiceThrow.RollDice(client);

            output.PlayerList = await GetPlayerInfo.GetPlayerPosition((int)gameId, output.NumberOfPlayers, client);

            ModifyPlayerStartPosition.SetStartPosition(output);

            return(View("gameboard", output));
        }
Пример #4
0
        public IActionResult GetGameInfo(GetGameInfo model)
        {
            var result = new ReturnGameInfo();

            result.GameInfoModel = null;
            result.Status        = loginService.CheckLoginStatus(model.Account, model.Token);
            if (result.Status == 1)
            {
                var infoModelValues = GetInfoModelValues();
                if (infoModelValues != null && infoModelValues.InfoModels != null && infoModelValues.TotilGold != null && infoModelValues.InfoModels.Count > 0)
                {
                    result.GameInfoModel = infoModelValues;
                }
            }
            return(Ok(result));
        }