Beispiel #1
0
 /// <summary>
 /// Create a new instance of PathFinder
 /// </summary>
 /// <param name="searchParameters"></param>
 public PathFinder(SearchParameters searchParameters)
 {
     this.searchParameters = searchParameters;
     InitializeNodes(searchParameters.Map);
     this.startNode = this.nodes[searchParameters.StartLocation.X, searchParameters.StartLocation.Y];
     this.startNode.State = NodeState.Open;
     this.endNode = this.nodes[searchParameters.EndLocation.X, searchParameters.EndLocation.Y];
 }
Beispiel #2
0
		public  int nMaxStep;		// limit of path find
	     /// <summary>
        /// Create a new instance of PathFinder
        /// </summary>
        /// <param name="searchParameters"></param>
        public PathFinder(SearchParameters searchParameters)
        {
            this.searchParameters = searchParameters;
            InitializeNodes(searchParameters.Map);	//  it create node. 
            this.startNode = this.nodes[searchParameters.StartLocation.X, searchParameters.StartLocation.Y];
            this.startNode.State = NodeState.Open;
            this.endNode = this.nodes[searchParameters.EndLocation.X, searchParameters.EndLocation.Y];

			// path find cache
			openlst = new List<Node>();
			movelst = new List<Point>();

			bIsDirty = true;
        }
Beispiel #3
0
        /// <summary>
        /// Creates a clear map with a start and end point and sets up the search parameters
        /// </summary>
        private void InitializeMap()
        {
            //  □ □ □ □ □ □ □
            //  □ □ □ □ □ □ □
            //  □ S □ □ □ F □
            //  □ □ □ □ □ □ □
            //  □ □ □ □ □ □ □

            this.map = new bool[7, 5];
            for (int y = 0; y < 5; y++)
                for (int x = 0; x < 7; x++)
                    map[x, y] = true;

            var startLocation = new Point(1, 2);
            var endLocation = new Point(5, 2);
            this.searchParameters = new SearchParameters(startLocation, endLocation, map);
        }
Beispiel #4
0
        public void calculateMovement(Object o, Map map)
        {
            int left, top;
            int PCleft, PCtop;

            //get monster coords
            left = _posX;
            top = _posY;
            Point monsterLocation = new Point((left - 1), (top - 5));

            //get Object's coord
            PCleft = o.getX();
            PCtop = o.getY();
            Point targetLocation = new Point(PCleft - 1, PCtop - 5);

            bool[,] b = map.getMapForPathFinding();
            //remove himself and target from map
            b[monsterLocation.X, monsterLocation.Y] = true;
            b[targetLocation.X, targetLocation.Y] = true;

            //find path
            SearchParameters sPams = new SearchParameters(monsterLocation, targetLocation, b);
            Finder = new PathFinder(sPams);
            _route = Finder.FindPath();

            //if no path was find quit
            if (_route.Count == 0)
            {
                _pathAvaible = false;
                return;
            }
            _pathAvaible = true;
            //clear movement list if there is something left and recreate it
            _movement.Clear();
            for (int i = 0; i < _route.Count; i++)
            {
                if (i == 0)
                {
                    _movement.Add(Game.calculateDelta(monsterLocation, _route[i]));
                }
                else
                {
                    _movement.Add(Game.calculateDelta(_route[i - 1], _route[i]));
                }
                
            }
            //save to file to check for errors
            StreamWriter file = new StreamWriter("log.txt");
            file.WriteLine("test for calculating delta for pathfinding");
            file.WriteLine("Monster position on map -- X :"+monsterLocation.X+" Y :"+monsterLocation.Y);
            file.WriteLine("Monster position on screen -- X :"+left+" Y :"+top);
            file.WriteLine("Delta X :" +(left-monsterLocation.X)+" Delta Y :"+(top-monsterLocation.Y));
            file.WriteLine("Object position on map -- X :" + targetLocation.X + " Y :" + targetLocation.Y);
            file.WriteLine("Object position on screen -- X :" + PCleft + " Y :" + PCtop);
            file.WriteLine("Delta X :" + (PCleft - targetLocation.X) + " Delta Y :" + (PCtop - targetLocation.Y));
            file.WriteLine("_route and _movement:");
            for (int i = 0; i < _route.Count; i++)
            {
                file.WriteLine("_route\t Pos X : "+_route[i].X+"\tPos Y :"+_route[i].Y+"\t\t\t_movement\t Pos X :"+_movement[i].X+"\tPos Y :"+_movement[i].Y);
            }
            file.Close();
        }