예제 #1
0
        private void Act(Player player, Map map)
        {
            Point target = Position;

            if (GetDistanceToTarget(player.Position, Position) <= visibilityRadius)
            {
                if (GetDistanceToTarget(player.Position, Position) > attackRadius)
                {
                    target = player.Position;
                }
                else
                {
                    TryAttack(player);
                }
            }
            else
            {
                if (Position == Trajectory.Peek())
                {
                    Trajectory.Enqueue(Trajectory.Dequeue());
                }
                target = Trajectory.Peek();
            }

            var direction = DirectionFinder.FindDirectionToTarget(map, target, Position, Radius);

            if (direction != Direction.None)
            {
                Position = GetNextPosition(direction, Position);
                MovementTimer.Restart();
            }
        }
예제 #2
0
        public void FindDirection()
        {
            var textMap   = "@@@@@\r\n@...@\r\n@.@.@\r\n@...@\r\n@@@@@";
            var map       = new Map(textMap, 10);
            var direction = DirectionFinder.FindDirectionToTarget(map,
                                                                  new Point {
                X = 25, Y = 13
            }, new Point {
                X = 13, Y = 19
            }, 5);

            Assert.AreEqual(direction, Direction.Right);
        }
예제 #3
0
        public void BypassObstacleRight()
        {
            var textMap   = "@@@@@\r\n@...@\r\n@.@.@\r\n@...@\r\n@@@@@";
            var map       = new Map(textMap, 10);
            var direction = DirectionFinder.FindDirectionToTarget(map,
                                                                  new Point {
                X = 32, Y = 30
            }, new Point {
                X = 30, Y = 32
            }, 5);

            Assert.AreEqual(direction, Direction.Right);
        }
예제 #4
0
        public void BypassObstacleUp()
        {
            var textMap   = "@@@@@\r\n@...@\r\n@.@.@\r\n@...@\r\n@@@@@";
            var map       = new Map(textMap, 10);
            var direction = DirectionFinder.FindDirectionToTarget(map,
                                                                  new Point {
                X = 25, Y = 13
            }, new Point {
                X = 27, Y = 19
            }, 5);

            Assert.AreEqual(direction, Direction.Up);
        }
예제 #5
0
        public void ReturnNoneDirection()
        {
            var textMap   = "@@@@@\r\n@.@.@\r\n@@@@@";
            var map       = new Map(textMap, 1);
            var direction = DirectionFinder.FindDirectionToTarget(map,
                                                                  new Point {
                X = 1, Y = 1
            }, new Point {
                X = 3, Y = 1
            }, 1);

            Assert.AreEqual(direction, Direction.None);
        }
예제 #6
0
        public void CheckBfs()
        {
            var textMap   = "@@@@@\r\n@...@\r\n@.@.@\r\n@...@\r\n@@@@@";
            var map       = new Map(textMap, 10);
            var direction = DirectionFinder.FindDirectionToTarget(map,
                                                                  new Point {
                X = 30, Y = 14
            }, new Point {
                X = 30, Y = 34
            }, 10);

            Assert.AreEqual(Direction.Left, direction);
        }