-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroom.py
71 lines (54 loc) · 2.16 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import random
from item import Item, sword, key, torch, orb, garlic, chest, spell_book, broken_mirror # Import the Item class and specific items
class Room():
def __init__(self, room_name):
self.name = room_name
self.description = None
self.linked_rooms = {}
self.character = None
self.items = []
self.items_found = False
self.enemy = None
def get_description(self):
return self.description
def set_description(self, description):
self.description = description
def get_name(self):
return self.name
def set_name(self, room_name):
self.name = room_name
def set_character(self, new_character):
self.character = new_character
def get_character(self):
return self.character
def set_enemy(self, new_enemy):
self.enemy = new_enemy
def describe(self):
print(self.description)
def link_room(self, room_to_link, direction):
self.linked_rooms[direction] = room_to_link
def get_details(self):
print(self.name)
print("-----------------------------------------")
print(self.description)
for direction in self.linked_rooms:
room = self.linked_rooms[direction]
print(f"The {room.get_name()} is {direction}.")
if self.enemy is not None:
print(f"{self.enemy.get_name()} is here!")
print(self.enemy.describe())
def move(self, direction):
if direction in self.linked_rooms:
return self.linked_rooms[direction]
else:
print("You can't go that way!")
return self
def assign_items_to_room(self, item):
self.items.extend(item)
def search(self):
if self.items and not self.items_found: # Check if there are items and they haven't been found before
found_item = self.items.pop() # Take the last item from the list
self.items_found = True # Set the items_found flag to True
return found_item # Return the found item
else:
return "Nothing to find here" # Return this message if no item found or already found