Example #1
0
        public static AttackStatus ShootCommand(int userId, Direction direction)
        {
            Lobby lobby = LobbyRepository.Read(MemberRepository.ReadLobbyId(userId));

            if (LobbyService.CanMakeTurn(lobby, userId) == false)
            {
                return(new AttackStatus
                {
                    IsOtherTurn = true
                });
            }

            var currentPlayer = lobby.Players[lobby.CurrentTurn];
            var shootResult   = PlayerLogic.TryShoot(lobby, currentPlayer, direction);

            LobbyService.EndTurn(lobby);
            if (currentPlayer.Guns == 0)
            {
                shootResult.KeyboardType = KeyboardType.Bomb;
            }
            if (currentPlayer.Guns == 0 && currentPlayer.Bombs == 0)
            {
                shootResult.KeyboardType = KeyboardType.Move;
            }
            return(shootResult);
        }
Example #2
0
        public static MoveStatus MoveCommand(int userId, Direction direction)
        {
            Lobby lobby = LobbyRepository.Read(MemberRepository.ReadLobbyId(userId));

            if (LobbyService.CanMakeTurn(lobby, userId) == false)
            {
                return(new MoveStatus()
                {
                    IsOtherTurn = true
                });
            }

            var currentPlayer = lobby.Players[lobby.CurrentTurn];
            var actionList    = PlayerLogic.TryMove(lobby, currentPlayer, direction);

            LobbyService.EndTurn(lobby);

            //TODO: Вывод для дебага
            FormatAnswers.ConsoleApp(lobby);

            if (actionList.Contains(PlayerAction.GameEnd))
            {
                lobby.IsActive = false;
                MemberRepository.Delete(lobby.GameId);

                LobbyService.EndTurn(lobby);
                return(new MoveStatus
                {
                    IsGameEnd = true,
                    CurrentPlayer = currentPlayer,
                    PlayerActions = actionList
                });
            }

            MoveStatus status = new MoveStatus
            {
                IsOtherTurn   = false,
                IsGameEnd     = false,
                CurrentPlayer = currentPlayer,
                PlayerActions = actionList
            };

            if (actionList.Contains(PlayerAction.MeetPlayer))
            {
                status.PlayersOnSameCell = MazeLogic.PlayersOnCell(currentPlayer, lobby);
            }
            return(status);
        }
Example #3
0
        public static AttackStatus StabCommand(int userId)
        {
            Lobby lobby = LobbyRepository.Read(MemberRepository.ReadLobbyId(userId));

            if (LobbyService.CanMakeTurn(lobby, userId) == false)
            {
                return(new AttackStatus
                {
                    IsOtherTurn = true
                });
            }

            var currentPlayer = lobby.Players[lobby.CurrentTurn];
            var stabResult    = PlayerLogic.Stab(lobby, currentPlayer);

            LobbyService.EndTurn(lobby);
            return(stabResult);
        }
Example #4
0
        public static SkipTurnResult SkipTurn(int userId)
        {
            Lobby lobby  = LobbyRepository.Read(MemberRepository.ReadLobbyId(userId));
            var   result = new SkipTurnResult();

            if (LobbyService.CanMakeTurn(lobby, userId) == false)
            {
                //TODO:
                result.CanMakeTurn = false;
                return(result);
            }
            result.PickChest = PlayerLogic.LootChest(lobby, lobby.Players[lobby.CurrentTurn]);
            LobbyService.EndTurn(lobby);

            //TODO:
            result.CanMakeTurn = true;
            return(result);
        }
Example #5
0
        public static BombStatus BombCommand(int userId, Direction direction)
        {
            Lobby lobby = LobbyRepository.Read(MemberRepository.ReadLobbyId(userId));

            if (LobbyService.CanMakeTurn(lobby, userId) == false)
            {
                return(new BombStatus
                {
                    IsOtherTurn = true
                });
            }

            var currentPlayer = lobby.Players[lobby.CurrentTurn];
            var bombResult    = PlayerLogic.Bomb(lobby, currentPlayer, direction);

            LobbyService.EndTurn(lobby);

            if (currentPlayer.Bombs == 0 && currentPlayer.Guns == 0)
            {
                return(new BombStatus
                {
                    CurrentPlayer = currentPlayer,
                    Result = bombResult,
                    KeyboardId = KeyboardType.Move
                });
            }
            if (currentPlayer.Bombs == 0)
            {
                return(new BombStatus
                {
                    CurrentPlayer = currentPlayer,
                    Result = bombResult,
                    KeyboardId = KeyboardType.Shoot
                });
            }

            return(new BombStatus
            {
                CurrentPlayer = currentPlayer,
                Result = bombResult,
            });
        }