forked from bloominstituteoftechnology/CS-Build-Week-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworld_creation.py
91 lines (90 loc) · 3.29 KB
/
world_creation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from room import Room
import random
import math
class World_Creation:
def __init__(self):
self.startingRoom = None
self.rooms = {}
self.roomGrid = []
self.gridSize = 0
def loadGraph(self, roomGraph):
numRooms = len(roomGraph)
rooms = [None] * numRooms
gridSize = 1
for i in range(0, numRooms):
x = roomGraph[i][0][0]
gridSize = max(gridSize, roomGraph[i][0][0], roomGraph[i][0][1])
self.rooms[i] = Room(f"Room {i}", f"({roomGraph[i][0][0]},{roomGraph[i][0][1]})",i, roomGraph[i][0][0], roomGraph[i][0][1])
self.roomGrid = []
gridSize += 1
self.gridSize = gridSize
for i in range(0, gridSize):
self.roomGrid.append([None] * gridSize)
for roomID in roomGraph:
room = self.rooms[roomID]
self.roomGrid[room.x][room.y] = room
if 'n' in roomGraph[roomID][1]:
self.rooms[roomID].connectRooms('n', self.rooms[roomGraph[roomID][1]['n']])
if 's' in roomGraph[roomID][1]:
self.rooms[roomID].connectRooms('s', self.rooms[roomGraph[roomID][1]['s']])
if 'e' in roomGraph[roomID][1]:
self.rooms[roomID].connectRooms('e', self.rooms[roomGraph[roomID][1]['e']])
if 'w' in roomGraph[roomID][1]:
self.rooms[roomID].connectRooms('w', self.rooms[roomGraph[roomID][1]['w']])
self.startingRoom = self.rooms[0]
def printRooms(self):
rotatedRoomGrid = []
for i in range(0, len(self.roomGrid)):
rotatedRoomGrid.append([None] * len(self.roomGrid))
for i in range(len(self.roomGrid)):
for j in range(len(self.roomGrid[0])):
rotatedRoomGrid[len(self.roomGrid[0]) - j - 1][i] = self.roomGrid[i][j]
f = open("map.txt", "w")
f.write("#####")
print("#####")
str = ""
for row in rotatedRoomGrid:
allNull = True
for room in row:
if room is not None:
allNull = False
break
if allNull:
continue
# PRINT NORTH CONNECTION ROW
str += "#"
for room in row:
if room is not None and room.n_to is not None:
str += " | "
else:
str += " "
str += "#\n"
# PRINT ROOM ROW
str += "#"
for room in row:
if room is not None and room.w_to is not None:
str += "-"
else:
str += " "
if room is not None:
str += f"{room.id}".zfill(3)
else:
str += " "
if room is not None and room.e_to is not None:
str += "-"
else:
str += " "
str += "#\n"
# PRINT SOUTH CONNECTION ROW
str += "#"
for room in row:
if room is not None and room.s_to is not None:
str += " | "
else:
str += " "
str += "#\n"
f.write(str)
f.write("#####")
f.close()
print(str)
print("#####")