forked from dylanmc/Fall22Project3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
item.py
98 lines (85 loc) · 2.46 KB
/
item.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
92
93
94
95
96
97
98
import os
from random import randint
def clear():
os.system('cls' if os.name == 'nt' else 'clear')
class Item:
def __init__(self, name, desc):
self.name = name
self.desc = desc
self.loc = None
self.kind = 'Generic'
def describe(self):
clear()
print(self.desc)
print()
input("Press enter to continue...")
def put_in_room(self, room):
self.loc = room
room.add_item(self)
class Gold(Item):
def __init__(self, name, desc):
super().__init__(name, desc)
self.kind = 'Gold'
class Bed(Item):
def __init__(self, name, desc):
super().__init__(name, desc)
self.kind = 'Bed'
def sleep(self, player):
hp = sum([randint(0,3) for _ in range(10)])
player.gain_hp(hp)
clear()
print("You've ept! Hope you had a good eep.")
print(f"You've regenerated {hp} hitpoints!")
print()
input("Press enter to continue...")
class Food(Item):
def __init__(self, name, desc, nutrition_value):
super().__init__(name, desc)
self.kind = 'Food'
self.nv = nutrition_value
class Container(Item):
def __init__(self, name, desc):
super().__init__(name, desc)
self.kind = 'Container'
self.items = []
self.open = False
def open_up(self):
if self.open:
return False
self.open = True
return True
def close_up(self):
if self.open:
self.open = False
return True
return False
def get_item_by_name(self, name):
for i in self.items:
if i.name.lower() == name.lower():
return i
return False
def drop(self, item, target = None):
target = target or self.loc
self.items.remove(item)
item.put_in_room(target)
def add_item(self, item):
self.items.append(item)
def describe(self):
clear()
print(self.desc)
if self.open:
self.show_contents()
else:
print("It's locked.")
input("Press enter to continue...")
def show_contents(self):
print("It contains the following:")
present = {}
for i in self.items:
if i.name in present.keys():
present[i.name] += 1
else:
present[i.name] = 1
for k in present.keys():
print(f"{k} x {present[k]}")
print()