/// <summary> /// search all rooms in AreaList assigning coords then checking neighbours /// and repeating until AreaList is empty /// /// Completed rooms are added to CompletedRooms and removed from AreaList /// /// </summary> /// <returns>Returns CompletedRooms which contains the list of rooms that have coordinates set</returns> public List <Room.Room> AssignCoords() { var startingLoc = AreaList.FirstOrDefault(x => x.areaId == 0); if (startingLoc == null) { return(null); } SetCoords(startingLoc, new Coordinates()); /* * Takes the 1st room and search all 4 exits * and assigns them coordinates adding them * to the completed list */ ProcessRoom(startingLoc); /* * Now completedList has areas, loop areaList looking for rooms * that have exits that lead to one of the rooms in the completed list */ while (AreaList.Count > 0) { var getRoom = AreaList.Last(); //Check if getRoom has a neighbour in the completed List var getNeighbour = GetNeighbour(getRoom); if (getNeighbour != null) { var getExitToNeighbour = GetNeighbourExit(getRoom, getNeighbour); if (getExitToNeighbour != null) { SetCoords(getRoom, GetNewCoord(getNeighbour.coords, getExitToNeighbour.name, true)); } ProcessRoom(getRoom); } else { /* * if nothing found remove the room from areaList * and add back to the top of the Area:ist */ AreaList.Remove(getRoom); AreaList.Insert(0, getRoom); } } //Once all rooms in areaList have been processed return the list of completed rooms return(CompletedRooms); }