Guest User

Untitled

a guest
Jul 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. function generateLevel(roomCount)
  2. local dirs = {north = "south", south = "north", east = "west", west = "east"}
  3. local rooms = { { } }
  4. for r = 1, roomCount do
  5. -- pick a random exit in a random room
  6. local room, exit = nil, nil
  7. while exit == nil do
  8. local exits = {}
  9. room = rooms[math.random(table.maxn(rooms))]
  10. for dir, opp in pairs(dirs) do
  11. if room[dir] == nil then table.insert(exits, dir) end
  12. end
  13. if table.maxn(exits) > 0 then
  14. exit = exits[math.random(table.maxn(exits))]
  15. end
  16. end
  17. -- attach a new room to that exit
  18. room[exit] = { [dirs[exit]] = room }
  19. table.insert(rooms, room[exit])
  20. end
  21. return rooms
  22. end
Add Comment
Please, Sign In to add comment