public class Location { private List<Exit> _Exits { get; set; } public int LocationId { get; set; } public Location(int id) : this() { // Store the id of the location LocationId = id; } public Location() { // Initialise the exits _Exits = new List<Exit>(); } /// <summary> /// Gets the location to which a given exit leads, if applicable /// </summary> /// <param name="direction">Direction of the exit</param> /// <returns>The location the exit leads to or -1 if there is no location in the specified direction</returns> public int ExitInDirection(int direction) { int result = -1; Exit exitInDirection = (from e in _Exits where e.DirectionId == direction select e).FirstOrDefault(); // If an exit in the specified direction exists, return that if (exitInDirection != null) result = exitInDirection.DestinationLocationId; return result; } /// <summary> /// Connects an exit to the Id of the location it leads to /// </summary> /// <param name="direction">Direction of the exit</param> /// <param name="destinationLocationId">Id of the location the exit should lead to</param> public void SetExitToLocation(int direction, int destinationLocationId) { _Exits.Add(new Exit(direction, destinationLocationId)); } }