Hmm... if you mean truly random walking, then get a list of all the tiles, randomize it, then add the randomized items to a stack (or queue). Pop each tile off the stack as you walk to it.
Tile[] _tiles;
//... some code here to load the tiles
Tile[] _randomizedTiles;
//... some code here to randomize the tiles
Stack<Tile> _tilesToExplore = new Stack<Tile>( _randomizedTiles );
while ( _tilesToExplore.Count > 0 ){
var l_nextTile = _tilesToExplore.Pop();
//... some code to walk to the tile
}
If you mean pseudo-random "wandering around", then you could modify this approach by using a List<Tile>
. Use your own custom solution for picking the next tile (rather than popping it from a stack) and simultaneously remove the Tile
from the List
. Keep looping as long as the List
is not empty.
If you have a more advanced scenario (where you may not know the tiles beforehand, or where tiles may be inaccessible), then you may find this CodeProject article (and demo code) helpful:
A* algorithm implementation in C#
Further Info
Randomize a List in C#
Stack class (MSDN)