forked from dylanmc/Fall22Project3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
room.py
48 lines (47 loc) · 1.55 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
import random
class Room:
def __init__(self, description):
self.desc = description
self.player = False
self.creatures = []
self.exits = []
self.items = []
def add_exit(self, exit_name, destination):
self.exits.append([exit_name, destination])
def get_destination(self, direction):
for e in self.exits:
if e[0] == direction:
return e[1]
return None
def connect_rooms(room1, dir1, room2, dir2):
#creates "dir1" exit from room1 to room2 and vice versa
room1.add_exit(dir1, room2)
room2.add_exit(dir2, room1)
def exit_names(self):
return [x[0] for x in self.exits]
def add_item(self, item):
self.items.append(item)
def remove_item(self, item):
self.items.remove(item)
def add_creature(self, creature):
self.creatures.append(creature)
def remove_creature(self, creature):
self.creatures.remove(creature)
def has_items(self):
return self.items != []
def get_item_by_name(self, name):
for i in self.items:
if i.name.lower() == name.lower():
return i
return False
def has_creatures(self):
return self.creatures != []
def get_creature_by_name(self, name):
for i in self.creatures:
if i.name.lower() == name.lower():
return i
return False
def random_neighbor(self):
return random.choice(self.exits)[1]
def random_item(self):
return random.choice(self.items)