예제 #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,
            });
        }
예제 #2
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);
        }
예제 #3
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);
        }