示例#1
0
        public LazerEntity(
            int x,
            int y,
            LazerDirection glowDirection,
            IMap map,
            ITaskProcessor taskProcessor)
            : base(
                EntityType.Lazer,
                x,
                y,
                MapLayer.PlayerBody,
                new[] {
            EntityProperty.PointIsBusy,
            EntityProperty.StopLazerRay
        })
        {
            Condition.Requires(map, nameof(map)).IsNotNull();
            Condition.Requires(taskProcessor, nameof(taskProcessor)).IsNotNull();

            this._map           = map;
            this._taskProcessor = taskProcessor;

            this.GlowDirection = glowDirection;
            this.State         = LazerState.Works;
        }
 public OutgoingLazerRayEntity(int x, int y, LazerDirection direction)
     : base(
         x,
         y,
         direction)
 {
 }
示例#3
0
 public LazerRayEntity(int x, int y, LazerDirection direction)
     : base(
         EntityType.LazerRay,
         x,
         y,
         MapLayer.PlayerBody)
 {
     this.Direction = direction;
 }
示例#4
0
        public void ChangeLazerDirection(MirrorDirection mirrorDirection, ref LazerDirection lazerDirection)
        {
            if (mirrorDirection == MirrorDirection.Left)
            {
                if (lazerDirection == LazerDirection.North)
                {
                    lazerDirection = LazerDirection.West;
                    return;
                }

                if (lazerDirection == LazerDirection.South)
                {
                    lazerDirection = LazerDirection.East;
                    return;
                }

                if (lazerDirection == LazerDirection.East)
                {
                    lazerDirection = LazerDirection.South;
                    return;
                }

                if (lazerDirection == LazerDirection.West)
                {
                    lazerDirection = LazerDirection.North;
                    return;
                }
            }

            if (mirrorDirection == MirrorDirection.Right)
            {
                if (lazerDirection == LazerDirection.North)
                {
                    lazerDirection = LazerDirection.East;
                    return;
                }

                if (lazerDirection == LazerDirection.South)
                {
                    lazerDirection = LazerDirection.West;
                    return;
                }

                if (lazerDirection == LazerDirection.East)
                {
                    lazerDirection = LazerDirection.North;
                    return;
                }

                if (lazerDirection == LazerDirection.West)
                {
                    lazerDirection = LazerDirection.South;
                    return;
                }
            }
        }
        private string GetOrientation(LazerDirection lazerDirection)
        {
            if (lazerDirection == LazerDirection.North || lazerDirection == LazerDirection.South)
                return "V";

            if (lazerDirection == LazerDirection.West || lazerDirection == LazerDirection.East)
                return "H";

            return string.Empty;
        }
        private Position GetPositionWhenOnesidedMirror(MazeSquare currentMazeSquare, ref LazerDirection lazerDirection)
        {
            if (currentMazeSquare.Mirror.Direction == MirrorDirection.Right)
                return GetPositionForRightDirectionMirror(currentMazeSquare, ref lazerDirection);

            else if (currentMazeSquare.Mirror.Direction == MirrorDirection.Left)
                return GetPositionForLeftDirectionMirror(currentMazeSquare, ref lazerDirection);

            else
                return null;
        }
 private MazeSquare GetNextSquare(Maze maze, MazeSquare currentMazeSquare, ref LazerDirection lazerDirection)
 {
     if (!MazeSquareHasMirror(currentMazeSquare))
     {
         var nextPosition = GetNextPosition(currentMazeSquare, lazerDirection);
         return FindMazeSquareFromPosition(maze, nextPosition);
     }
     else
     {
         var nextPosition = GetNextPositionWhenMirrorPresent(currentMazeSquare, ref lazerDirection);
         return FindMazeSquareFromPosition(maze, nextPosition);
     }
 }
示例#8
0
        public static LazerDirection RotateToRight(
            this LazerDirection direction)
        {
            switch (direction)
            {
            case LazerDirection.Top: return(LazerDirection.Right);

            case LazerDirection.Right: return(LazerDirection.Down);

            case LazerDirection.Down: return(LazerDirection.Left);

            case LazerDirection.Left: return(LazerDirection.Top);
            }

            throw new Exception("unknown lazer direction");
        }
        public Point GetLazerDirectionPoint(
            LazerDirection direction)
        {
            switch (direction)
            {
            case LazerDirection.Down:
                return(this.GetMiddlePointDown());

            case LazerDirection.Left:
                return(this.GetMiddlePointLeft());

            case LazerDirection.Top:
                return(this.GetMiddlePointTop());

            case LazerDirection.Right:
            default:
                return(this.GetMiddlePointRight());
            }
        }
        private Position GetNextPosition(MazeSquare currentMazeSquare, LazerDirection lazerDirection)
        {
            var newPosY = currentMazeSquare.Position.Y + 1;

            var newNegY = currentMazeSquare.Position.Y - 1;

            var newPosX = currentMazeSquare.Position.X + 1;

            var newNegX = currentMazeSquare.Position.X - 1;

            if (lazerDirection == LazerDirection.North)
                return new Position { X = currentMazeSquare.Position.X, Y = newPosY };

            if (lazerDirection == LazerDirection.South)
                return new Position { X = currentMazeSquare.Position.X, Y = newNegY };

            if (lazerDirection == LazerDirection.East)
                return new Position { X = newPosX, Y = currentMazeSquare.Position.Y };

            if (lazerDirection == LazerDirection.West)
                return new Position { X = newNegX, Y = currentMazeSquare.Position.Y };

            return null;
        }
        private Position GetNextPositionWhenMirrorPresent(MazeSquare currentMazeSquare, ref LazerDirection lazerDirection)
        {
            if (currentMazeSquare.Mirror.Type == MirrorType.OneSided)
            {
                return GetPositionWhenOnesidedMirror(currentMazeSquare, ref lazerDirection);
            }

            else if (currentMazeSquare.Mirror.Type == MirrorType.TwoSided)
            {
                _lazerService.ChangeLazerDirection(currentMazeSquare.Mirror.Direction, ref lazerDirection);

                return GetNextPosition(currentMazeSquare, lazerDirection);
            }

            else 
                return null;
        }
        private Position GetPositionForLeftDirectionMirror(MazeSquare currentMazeSquare, ref LazerDirection lazerDirection)
        {
            if (currentMazeSquare.Mirror.ReflectiveSide == MirrorReflectiveSide.Left && (lazerDirection == LazerDirection.South || lazerDirection == LazerDirection.West))
                return GetNextPosition(currentMazeSquare, lazerDirection);

            if (currentMazeSquare.Mirror.ReflectiveSide == MirrorReflectiveSide.Right && (lazerDirection == LazerDirection.North || lazerDirection == LazerDirection.East))
                return GetNextPosition(currentMazeSquare, lazerDirection);

            if (currentMazeSquare.Mirror.ReflectiveSide == MirrorReflectiveSide.Right && (lazerDirection == LazerDirection.South || lazerDirection == LazerDirection.West))
            {
                _lazerService.ChangeLazerDirection(currentMazeSquare.Mirror.Direction, ref lazerDirection);
                return GetNextPosition(currentMazeSquare, lazerDirection);
            }

            if (currentMazeSquare.Mirror.ReflectiveSide == MirrorReflectiveSide.Left && (lazerDirection == LazerDirection.North || lazerDirection == LazerDirection.East))
            {
                _lazerService.ChangeLazerDirection(currentMazeSquare.Mirror.Direction, ref lazerDirection);
                return GetNextPosition(currentMazeSquare, lazerDirection);
            }

            return null;
        }
示例#13
0
 public static LazerDirection GetOppositeDirection(
     this LazerDirection direction)
 {
     return(LazerDirectionExtensions.OppositeDirection[direction]);
 }
示例#14
0
 private LazerEntity CreateLazer(int x, int y, LazerDirection glowDirection)
 {
     return(new LazerEntity(x, y, glowDirection, this._map, this._taskProcessor));
 }
示例#15
0
 public static LazerDirection GetReflectedRay(
     this MirrorPosition position,
     LazerDirection incomingRay)
 {
     return(ReflectedRay[position][incomingRay]);
 }