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);
        }
Exemple #2
0
        public static AttackStatus Stab(Lobby lobby, Player player)
        {
            var stabResult = new AttackStatus
            {
                CurrentPlayer = player
            };
            var target = MazeLogic.PlayersOnCell(player, lobby)?.FirstOrDefault();

            stabResult.PickChest = LootChest(lobby, player);
            if (target == null)
            {
                stabResult.Result = AttackType.NoAttack;
                return(stabResult);
            }
            stabResult.Target = target;
            if (target.Chest != null)
            {
                DropChest(lobby, target);
            }
            if (target.Health > 1)
            {
                target.Health--;
                stabResult.Result = AttackType.Hit;
                return(stabResult);
            }
            else
            {
                KillPlayer(lobby, target);
            }

            //TODO: Добавить победу
            //TODO: А еще лучше писать метод, который будет определять, что остался один игрок
            //stabResult.IsGameEnd ==...
            KillPlayer(lobby, target);
            //lobby.Players.Remove(target);
            stabResult.Result = AttackType.Kill;
            return(stabResult);
        }