示例#1
0
        public List <Vector2> getMoveInstructions()
        {
            PathsList      pathsList = this.pathsList.Find(p => p.size == minSize);
            List <Vector2> moves     = new List <Vector2>();
            int            cont      = 0;

            if (pathsList == null)
            {
                return(moves);
            }
            foreach (Square square in pathsList.path)
            {
                cont++;
                if (cont >= minSize)
                {
                    break;
                }
                Square nextSquare = pathsList.path[cont];
                int    toX = 0, toY = 0;
                toX = (int)(-square.position.x + nextSquare.position.x);
                toY = (int)(-square.position.y + nextSquare.position.y);
                Vector2 vector2 = new Vector2(toX, toY);
                if (!nextSquare.hasCharacter || (nextSquare.hasCharacter && cont != minSize - 1))
                {
                    moves.Add(vector2);
                }
            }
            this.pathsList = new List <PathsList>();
            return(moves);
        }
示例#2
0
        void RetracePath(Square startSquare, Square endSquare)
        {
            List <Square> path          = new List <Square>();
            Square        currentSquare = endSquare;

            while (currentSquare != startSquare)
            {
                path.Add(currentSquare);
                currentSquare = currentSquare.parent;
            }
            path.Add(startSquare);
            path.Reverse();
            PathsList pathsList = new PathsList();

            pathsList.path = path;
            pathsList.size = path.Count;
            if (pathsList.size < minSize)
            {
                minSize = pathsList.size;
            }
            this.pathsList.Add(pathsList);
            ready = true;
        }