private Room CreateConnectedRoom(Hall hall) { Dimension roomSize = _randomizer.ChooseDimension(MaxRoomSize); Direction doorWall = GetOppositeDirection(CalculateFinalHallDirection(hall)); int doorPosition = _randomizer.ChooseCount(1, roomSize.Length); Position roomLocation = new Position();; Position lastSegment = hall.Segments[hall.Segments.Length - 1]; switch (doorWall) { case Direction.North: { roomLocation.Row = lastSegment.Row + 1; roomLocation.Column = lastSegment.Column - doorPosition; break; } case Direction.West: { roomLocation.Row = lastSegment.Row - doorPosition; roomLocation.Column = lastSegment.Column - roomSize.Length; break; } case Direction.East: { roomLocation.Row = lastSegment.Row - doorPosition; roomLocation.Column = lastSegment.Column + 1; break; } case Direction.South: { roomLocation.Row = lastSegment.Row - roomSize.Width; roomLocation.Column = lastSegment.Column - doorPosition; break; } default: throw new ApplicationException(string.Format("Unknown wall direction {0}", doorWall)); } Door hallDoor = new Door(GetNextDoorName(), doorWall, doorPosition); Room resultRoom = new Room(GetNextRoomName(), roomLocation, roomSize) { Doors = new Door[] { hallDoor } }; //link up the references hallDoor.ConnectedHallName = hall.Name; hall.EndRoomName = resultRoom.Name; return(resultRoom); }