internal void SetLocation(Place newPlace) { Console.WriteLine("SetLocation", ConsoleColor.Yellow); //Check for known places. //See if the place is different from current location if (!World.places.Any()) { Console.WriteLine("Its a brave new world"); //This is a new world if (OnFoundNewPlace != null) { OnFoundNewPlace(newPlace); } Location = newPlace; World.places.Add(newPlace); } else if (Location != null) //We are not starting a new world. { Place returningPlace = World.places.Find(p => p.placeHash == newPlace.placeHash); if (returningPlace != null) //This is a know place { UpdatePlaceExits(ref returningPlace); Location = returningPlace; Console.WriteLine("Returned to " + location.heading); } else //This is a new place, and we have moved. { Console.WriteLine("Found new place " + location.heading); if (World.ConnectPlaces(ref newPlace, ref location)) { //This place is connected to a known place, add it to mapped world. World.places.Add(newPlace); if (OnFoundNewPlace != null) { OnFoundNewPlace(newPlace); } //Move to new location Location = newPlace; } else //Could not connect to known place, we are lost. //Lost { Location = World.places.First(); //TODO: Impliment Lost state. } } } else //Starged game, location not known { if (World.HasPlace(newPlace)) //place is known { Location = newPlace; } else //Started at unknown location, we are Lost //TODO: Impliment Lost state. //FORNOW: Just go to first know place { Location = World.places.First(); } } }