forked from dylanmc/Fall22Project3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.py
206 lines (203 loc) · 7.87 KB
/
player.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import os
def clear():
os.system('cls' if os.name == 'nt' else 'clear')
class Player:
def __init__(self):
self.location = None
self.items = []
self.health = 400
self.atk = 7
self.alive = True
self.cry_count = 0
self.asleep = False
# cries
def cry(self):
self.cry_count += 1
clear()
print("You cry.")
if self.cry_count > 5:
print('Your eyes are starting to feel dry.')
if self.cry_count > 50:
print('You are starting to feel dehydrated.\nMaybe you should stop crying so much.')
if self.cry_count > 90:
print('You feel you are dying of thirst!\nAll the water in your body is exiting through your eyes!')
if self.cry_count > 100:
print('All the water in your body is gone!\nYour body no longer has enough water to function.')
print()
print('You lose.')
self.alive = False
print()
input("Press enter to continue...")
# goes in specified direction if possible, returns True
# if not possible returns False
def go_direction(self, direction):
new_location = self.location.get_destination(direction.lower())
if new_location is not None:
self.location.player = False
self.location = new_location
self.location.player = self
return True
return False
# picks up specified item
def pickup(self, item):
self.items.append(item)
item.loc.items.remove(item)
item.loc = self
# drops specified item
def drop(self, item, target = None):
target = target or self.location
self.items.remove(item)
item.put_in_room(target)
# removes item from inventory
def remove_item(self, item):
self.drop(item, None)
# drops all items
def drop_all(self, target = None):
while self.items != []:
self.drop(self.items[0], target)
# gains hp
def gain_hp(self, hp):
self.health += hp
# eats specified item
def eat(self, item):
self.health += item.nv
if item in self.items:
self.items.remove(item)
if item in self.location.items:
self.location.items.remove(item)
clear()
print(f"You slurp {item.name} up. Slurpity slurp slurp slurp. Sluuuurrrrrrp. Fuck, that tastes {'good' if item.nv > 0 else 'awful'}. Who knows where it goes.")
print()
input("Press enter to continue...")
# returns item, identified by name
# if item not found, returns false
def get_item_by_name(self, name):
for i in self.items:
if i.name.lower() == name.lower():
return i
return False
# returns a total of the number of gold in inventory
def count_gold(self):
ret = 0
for i in self.items:
if i.kind == 'Gold':
ret += 1
return ret
# displays inventory
def show_inventory(self):
clear()
print("You are currently carrying:")
print()
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()
input("Press enter to continue...")
# pets creature
def pet_creature(self, mon):
clear()
print(f"You are petting {mon.name}")
if mon.kind == 'Friend':
print(f"{mon.name} loves it! You can see them wagging their little tail.\nOr... no, wait, {mon.name} doesn't have a tail.\nWhat are you seeing? How can you tell that they're happy?\nHow do you know what's even real?\nWell, you can tell that {mon.name} is happy.\nExistential crisis postponed because ohmigosh they're so cuuuuuuteeeeeee~\n")
print(f"Both you and {mon.name} gain hitpoints.")
self.health += mon.atk
mon.health += self.atk
else:
print(f"{mon.name} is hating this. They are scared of you.")
input("Press enter to continue...")
# prints a description of self
def show(self):
clear()
print("You sure have an appearance.")
print(f"You have a height for sure, a hair color certainly.\nCan't forget eyes.{' They are looking rather red.' if self.cry_count > 10 else ''} All the usual limbs.")
print(f"You have {self.health} health.")
print(f"You have {self.atk} attack.")
print()
input("Press enter to continue...")
clear()
for c in self.location.creatures:
if c.kind == 'Friend':
print("You have a little friend!")
print(f"{c.name} is your friend!")
else:
print("You are not alone.")
print(f"{c.name} is in the room with you.")
print()
input('Press enter to continue...')
clear()
print(self.location.desc)
if self.items == []:
print("You have no items.")
else:
print("You have items in your inventory!")
print("You are currently carrying:")
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(f"You have {self.atk} attack.")
if self.cry_count != 0:
print(f"You have cried {self.cry_count} time{'' if self.cry_count == 1 else 's'}.")
print()
input("Press enter to continue...")
# adds item to the inventory
def add_item(self, item):
self.items.append(item)
# attacks specified creature
# before attacking the creature, every 'friend' creature also attacks specified creature
# 'attacking' is subtracting self's attack from target's hp, and vice versa
def attack_creature(self, mon):
for c in self.location.creatures:
if c.kind == 'Friend' and c != mon:
c.attack(mon)
if not mon.alive:
break
if mon.alive:
clear()
print("You are attacking " + mon.name)
print()
print("Your health is " + str(self.health) + ".")
print(f"Your attack is {self.atk}.")
print(mon.name + "'s health is " + str(mon.health) + ".")
print(f"{mon.name}'s attack is {mon.atk}.")
print()
if mon.kind != 'Friend':
self.health -= mon.atk
mon.health -= self.atk
print("You fight. Your health is now " + str(self.health) + ".")
if mon.kind == 'Friend':
print(f"{mon.name} doesn't fight back.")
print(f"{mon.name} is your friend.")
if mon.health <= 0:
print(f"You win! {mon.name} is now dead.")
if mon.kind == 'Friend':
print("Are you proud of yourself? Are you happy?")
print(f"All {mon.name} wanted was to be your friend.")
if mon.has_items():
print(f"{mon.name} had items!")
print("They drop the following items:")
present = {}
for i in mon.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]}")
mon.die()
else:
print(f"{mon.name}'s health is now {mon.health}.")
if self.health <= 0:
print("You lose.")
self.alive = False
print()
input("Press enter to continue...")