-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharacters.py
72 lines (57 loc) · 1.92 KB
/
characters.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
from char_actions import Attack
from char_actions import Action
from item import Item
class Player():
def __init__(self):
self.max_health = 10
self.health = 4
self.status = []
self.inventory = []
def is_alive(self):
return self.health > 0
def get_health_state(self):
if self.health == self.max_health:
return "You feel healthy."
elif self.health >= 2/3 * self.max_health:
return "You are lightly injured."
elif self.health >= 1/3 * self.max_health:
return "You are moderately injured."
else:
return "You are grievously injured."
def has_weapon(self):
for item in self.inventory:
if item.is_weapon:
return True
return False
def pickup(self, item):
self.inventory.append(item)
item.on_pickup()
def use(self, item, target):
item.on_use(target)
if item.consumable:
self.inventory.remove(item)
class Character():
def __init__(self, name, health, aggression, description, response=None):
self.name = name
self.max_health = health
self.health = health
self.aggression = aggression
self.description = description
self.status = []
self.inventory = []
self.attacks = []
self.response = response
def is_alive(self):
return self.health > 0
def attack(self, target):
if len(self.attacks) == 0:
return ""
else:
chosen_attack = self.attacks[0]
if target.is_alive():
target.health -= chosen_attack.damage
return chosen_attack.text
def add_attack(self, attack_to_add):
self.attacks.append(attack_to_add)
def respond(self):
print(self.response)