-
Notifications
You must be signed in to change notification settings - Fork 1
/
room.py
50 lines (41 loc) · 1.23 KB
/
room.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
import json
# holds all the blocks info
def get_blocks():
locations = []
with open("game.json", "r") as f:
jsontext = f.read()
d = json.loads(jsontext)
blocks = (d["block"])
for x in blocks:
locations.append(Block(**x))
return locations
class Block():
def __init__(self, ident="", name="A room",
description="an empty room",
neighbours={}, items={},
hasEnemy=False, enemy=None):
self.ident=ident
self.name=name
self.description=description
self.neighbours = neighbours
self.items = items
self.hasEnemy = hasEnemy
self.enemy = enemy
def _neighbour(self, direction):
if direction in self.neighbours:
return self.neighbours[direction]
else:
return None
def _item(self, item):
if item in self.items:
return self.items[item]
else:
return None
def removeItem(self, item):
# remove the itemm from the import dictionary
self.items.pop(item, None)
def returnItems(self):
# return a list of items in the room
return list(self.items.keys())
def _enemy(self):
return self.enemy