public bool ExistPath()
{
Debug.Log(" // Mark the path from monster to hero.");
path = new List<Point>();
Point startingPoint = FindCode( TileContent.Start );
int pointX = startingPoint.x;
int pointY = startingPoint.y;
// if (pointX == -1 && pointY == -1) return null;
while (true)
{
// Look through each direction and find the square with the lowest number of steps marked.
Point lowestPoint = new Point(0,0);
int lowest = 10000;
foreach ( Point movePoint in ValidMoves( pointX, pointY ) )
{
int count = squares[ movePoint.x, movePoint.y ].DistanceSteps;
if (count < lowest){
lowest = count;
lowestPoint.x = movePoint.x;
lowestPoint.y = movePoint.y;
}
}
if ( lowest != 10000 ){
// Mark the square as part of the path if it is the lowest number.
// Set the current position as the square with that number of steps.
squares[ lowestPoint.x, lowestPoint.y ].IsPath = true;
pointX = lowestPoint.x;
pointY = lowestPoint.y;
path.Add( new Point( pointX, pointY ) );
meshBoard.SetTileColor( Color.cyan, pointX, pointY);
}else{
break;
}
if ( squares[ pointX, pointY ].ContentCode == TileContent.Finish)
{
Debug.Log(" //We went from monster to hero, so we're finished.");
break;
}
}
Debug.Log("PathCount : " + path.Count);
if( path != null ) return true;
return false;
}