Ejemplo n.º 1
0
        /// <summary>
        ///     проверка может ли пуля попасть в игрока, если да возвращакт игрока
        /// </summary>
        private static AttackStatus Shoot(Lobby lobby, Player player, Direction direction)
        {
            var coord          = Extensions.TargetCoordinate(player.Rotate, direction);
            var bulletPosition = new Coordinate(player.UserCoordinate);

            List <MazeObjectType> type;

            do
            {
                type = MazeLogic.CheckLobbyCoordinate(bulletPosition - coord, lobby);

                bulletPosition -= coord;
            } while (!type.Contains(MazeObjectType.Player) && !type.Contains(MazeObjectType.Wall));

            player.Guns--;

            if (type.Contains(MazeObjectType.Wall))
            {
                return(new AttackStatus
                {
                    CurrentPlayer = player,
                    Result = AttackType.NoTarget,
                    Target = null,
                });
            }

            var target = lobby.Players.Find(e => Equals(e.UserCoordinate, bulletPosition));

            if (target.Chest != null)
            {
                DropChest(lobby, target);
            }

            if (target.Health == 1)
            {
                KillPlayer(lobby, target);
            }
            else
            {
                target.Health--;
            }

            return(new AttackStatus
            {
                CurrentPlayer = player,
                Result = AttackType.Hit,
                Target = target,
            });
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        public static bool LootChest(Lobby lobby, Player player)
        {
            //var types = MazeLogic.CheckLobbyCoordinate(player.UserCoordinate, lobby);
            var events = MazeLogic.EventsOnCell(player.UserCoordinate, lobby);

            if (events.Contains(EventTypeEnum.Chest))
            {
                if (player.Chest == null && player.Health == lobby.Rules.PlayerMaxHealth)
                {
                    player.Chest = MazeLogic.PickChest(player.UserCoordinate, lobby, player);
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Взрыв стены
        /// </summary>
        public static BombResultType Bomb(Lobby lobby, Player player, Direction direction)
        {
            if (player.Bombs <= 0)
            {
                return(BombResultType.NoBomb);
            }
            var coord = Extensions.TargetCoordinate(player.Rotate, direction);

            player.Bombs--;

            if (MazeLogic.CheckLobbyCoordinate(player.UserCoordinate - coord, lobby)
                .Contains(MazeObjectType.Wall))
            {
                lobby.Maze.Set(player.UserCoordinate - coord, 0);
                return(BombResultType.Wall);
            }

            return(BombResultType.Void);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Возвращает можно ли идти в направлении
        /// </summary>
        public static List <PlayerAction> TryMove(Lobby lobby, Player player, Direction direction)
        {
            var coord = Extensions.TargetCoordinate(player.Rotate, direction);
            var types = MazeLogic.CheckLobbyCoordinate(player.UserCoordinate - coord, lobby);

            //TODO: debug
            Console.Clear();
            Console.WriteLine(player.UserCoordinate.X + " " + player.UserCoordinate.Y);
            //===========

            if (types.Contains(MazeObjectType.Wall) || types.Contains(MazeObjectType.Space))
            {
                return new List <PlayerAction> {
                           PlayerAction.OnWall
                }
            }
            ;

            player.UserCoordinate -= coord;
            if (player.Chest != null)
            {
                lobby.Chests.Find(e => e.Id == player.Chest.Id).Position = player.UserCoordinate;
            }
            var actions = new List <PlayerAction>();

            if (types.Contains(MazeObjectType.Event))
            {
                var events = MazeLogic.EventsOnCell(player.UserCoordinate, lobby);
                if (events.Contains(EventTypeEnum.Arsenal))
                {
                    player.Bombs = lobby.Rules.PlayerMaxBombs;
                    player.Guns  = lobby.Rules.PlayerMaxGuns;
                    actions.Add(PlayerAction.OnArsenal);
                }

                if (events.Contains(EventTypeEnum.Hospital))
                {
                    player.Health = lobby.Rules.PlayerMaxHealth;
                    actions.Add(PlayerAction.OnHospital);
                }

                if (events.Contains(EventTypeEnum.Chest))
                {
                    if (player.Chest == null && player.Health == lobby.Rules.PlayerMaxHealth)
                    {
                        player.Chest = MazeLogic.PickChest(player.UserCoordinate, lobby, player);
                        actions.Add(PlayerAction.OnChest);
                    }
                }
            }

            if (types.Contains(MazeObjectType.Player))
            {
                actions.Add(PlayerAction.MeetPlayer);
            }


            if (types.Contains(MazeObjectType.Exit) && player.Chest != null)
            {
                if (player.Chest.IsReal == false)
                {
                    var r = lobby.Chests.Find(e =>
                                              Equals(player.UserCoordinate, e.Position));
                    lobby.Chests.Remove(r);
                    player.Chest = null;
                    actions.Add(PlayerAction.FakeChest);
                }
                else
                {
                    actions.Add(PlayerAction.GameEnd);
                }
            }

            return(actions);
        }