private void GenerateMainPath(LevelData levelData, LevelLayout levelLayout) { int enterDirection = 0; var selectedPos = IntPair.CreatePair(levelData.StartingRoomCoordinates.x, levelData.StartingRoomCoordinates.y); while (selectedPos.x < LevelSize.x) { var selectedRoomConnection = SelectRoomConnectionType(enterDirection, selectedPos.y); if (selectedRoomConnection.SelectedRoomConnectionAttribute == null) { throw new Exception("Couldn't select any room. Make sure your room inventory has sufficient combinations"); } levelLayout.AddRoomAttribute(selectedPos.x, selectedPos.y, selectedRoomConnection.SelectedRoomConnectionAttribute); levelLayout.MainPath.Add(selectedPos.Clone()); enterDirection = selectedRoomConnection.ExitDirection; switch (selectedRoomConnection.ExitDirection) { case 1: selectedPos.y--; break; case 2: selectedPos.y++; break; case 3: selectedPos.x++; break; } } selectedPos.x--; levelData.EndRoomCoordinate = selectedPos.Clone(); }