private void Explore(IActor actor, ILocation location) { //If an exit location is found, print the path and continue to find another exit if (location is ExitLocation) { if ((location as ExitLocation).ExitPreviouslyFound) return; (location as ExitLocation).ExitPreviouslyFound = true; NumberOfExits++; TripRecorder.Instance.PrintTrip(); terrain.PathToExit(); terrain.TerrainPrinter(terrain.StartLocation); str= String.Format("{0} Number Of Exit(s) Found!", NumberOfExits); Console.WriteLine(str); Console.WriteLine("*****************************************************************"); return; } //When the location is dead end if (location.ListOfNeighbors().Count == 0) { (location as MarkedLocation).MarkRed(); return; } //traverses to all the neigbors of a location foreach (var neighbor in location.ListOfNeighbors()) { location.MoveToNeighbor(actor, neighbor.Key); Explore(actor, neighbor.Value); } //The location will be marked red when it backtracks (location as MarkedLocation).MarkRed(); }
/// <summary> /// Prints Neigbors of a Location /// </summary> /// <param name="location"></param> private static void PrintNeigbors(ILocation location) { foreach (var loc in location.ListOfNeighbors()) { depth++; PrintTabs(depth); Console.WriteLine("{0} -> {1}", loc.Key, loc.Value.ToString()); PrintNeigbors(loc.Value); depth--; } }