forked from jbs1/jhack14
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.py
More file actions
62 lines (54 loc) · 1.52 KB
/
player.py
File metadata and controls
62 lines (54 loc) · 1.52 KB
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
class Player:
"""player class"""
def __init__(self, name):
self.name = name
self.health = 100
self.hitchance = 0.3
self.inventory = {}
self.room = None
def gethitchance(self):
hc = self.hitchance
tmp = self.inventory.get('Sword')
if tmp:
hc += 0.4
return hc
def get_inv(self):
if self.inventory=={}:
print("Your inventory is empty. Get more stuff!")
else:
print("Your inventory:")
for i in self.inventory:
print(self.inventory[i].name)
def check_inv_item(self,item):
for i in self.inventory:
if self.inventory[i].name == item:
return True
def take_item(self, item): #take_item(room.remove_item('something'))
self.inventory[item.name] = item
print("Taking", item.name)
def drop_item(self, item): # string input
print ("Dropping", item)
item_b = self.inventory[item]
del self.inventory[item]
return item_b
def attack(self, dmg):
self.health = self.health - dmg
if self.health > 0:
print("You were hurt!") # write own "checkhealth" for attack() and defend()
check_health()
def gain_health(self, heal):
self.health = self.health + heal
print("You were healed!")
def check_health(self):
if self.health == 100:
print("You are fully healed.")
elif self.health >= 70:
print("You have minour wounds.")
elif self.health >= 50:
print("You have bigger wounds.")
elif self.health >= 10:
print("You have major, life-threatening wounds.")
elif self.health >= 1:
print("You are as good as dead.")
elif self.health <= 0:
print("You are DEAD!")