public void HighlightPath()
{
path = new List<Point>();
Point startingPoint = FindCode( TileContent.Start );
int pointX = startingPoint.x;
int pointY = startingPoint.y;
if (pointX == -1 && pointY == -1) return;
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 ) );
squares[ pointX, pointY ].SetColor( Color.cyan );
}else{
break;
}
if ( squares[ pointX, pointY ].ContentCode == TileContent.Finish )
{
//We went from monster to hero, so we're finished.
break;
}
}
// if( path != null ) Route = path;
}