# Dungeon generation test

Nov 21st, 2021
44
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import random
2.
3. class dungeon():
4.     def __init__(self): #
5.         self.map = [[0,0,0,0,0],
6.                     [0,0,0,0,0],
7.                     [0,0,0,0,0],
8.                     [0,0,0,0,0],
9.                     [0,0,0,0,0]]
10.
11.         self.spawnpointx = random.randint(0,2)
12.         self.spawnpointy = random.randint(0, 2)
13.         self.enemy_room = random.randint(1,2)
14.
15.
16.     def generatemap(self):
17.         posx = 0
18.         posy = 0
19.         while posx < 5 and posy < 5:
20.             self.map[posx][posy] = "R"
21.             posx = posx + 1
22.             while posx == 5:
23.                 posx = 0
24.                 posy = posy + 1
25.
26.         posx = 0
27.         posy = 0
28.
29.         while posx < 5 and posy < 5:
30.             if self.enemy_room == 2:
31.                 self.map[posx][posy] = "E"
32.             self.enemy_room = random.randint(1, 2)
33.             posx = posx + 1
34.             while posx == 5:
35.                 posx = 0
36.                 posy = posy + 1
37.
38.         self.map[self.spawnpointx][self.spawnpointy] = "S"
39.
40.         return self.map
41.
42.     def display(self):
43.         i = 0
44.         while i < len(self.map):
45.             print(self.map[i])
46.             i += 1
47.
48.     def findlocation(self):
49.         print("You are in", self.map[self.spawnpointx][self.spawnpointy])
50.
51. Dungeon = dungeon()
52.
53. Dungeon.generatemap()
54. Dungeon.display()
55. Dungeon.findlocation()
56.
57.
58.
59.
60.