Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function generateLevel(roomCount)
- local dirs = {north = "south", south = "north", east = "west", west = "east"}
- local rooms = { { } }
- for r = 1, roomCount do
- -- pick a random exit in a random room
- local room, exit = nil, nil
- while exit == nil do
- local exits = {}
- room = rooms[math.random(table.maxn(rooms))]
- for dir, opp in pairs(dirs) do
- if room[dir] == nil then table.insert(exits, dir) end
- end
- if table.maxn(exits) > 0 then
- exit = exits[math.random(table.maxn(exits))]
- end
- end
- -- attach a new room to that exit
- room[exit] = { [dirs[exit]] = room }
- table.insert(rooms, room[exit])
- end
- return rooms
- end
Add Comment
Please, Sign In to add comment