-
Notifications
You must be signed in to change notification settings - Fork 2
/
game.py
185 lines (141 loc) · 4.95 KB
/
game.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
import random
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
class Person:
def __init__(self, name, hp, mp, atk, df, magic, items):
self.maxhp = hp
self.hp = hp
self.maxmp = mp
self.mp = mp
self.atkl = atk - 10
self.atkh = atk + 10
self.df = df
self.magic = magic
self.items = items
self.actions = ["Attack", "Magic", "Items"]
self.name = name
def generate_damage(self):
return random.randrange(self.atkl, self.atkh)
def take_damage(self, dmg):
self.hp -= dmg
if self.hp < 0:
self.hp = 0
return self.hp
def heal(self, dmg):
self.hp += dmg
if self.hp > self.maxhp:
self.hp = self.maxhp
def get_hp(self):
return self.hp
def get_max_hp(self):
return self.maxhp
def get_mp(self):
return self.mp
def get_max_mp(self):
return self.maxmp
def reduce_mp(self, cost):
self.mp -= cost
def choose_action(self):
i = 1
print("\n" + " " + bcolors.BOLD + self.name + bcolors.ENDC)
print(bcolors.OKBLUE + bcolors.BOLD + " ACTIONS:" + bcolors.ENDC)
for item in self.actions:
print(" " + str(i) + ".", item)
i += 1
def choose_magic(self):
i = 1
print("\n" + bcolors.OKBLUE + bcolors.BOLD + " MAGIC:" + bcolors.ENDC)
for spell in self.magic:
print(" " + str(i) + ".", spell.name, "(cost:", str(spell.cost) + ")")
i += 1
def choose_item(self):
i = 1
print("\n" + bcolors.OKGREEN + bcolors.BOLD + " ITEMS:" + bcolors.ENDC)
for item in self.items:
print(" " + str(i) + ".", item["item"].name + ":", item["item"].description, " (x" + str(item["quantity"]) +")")
i += 1
def choose_target(self, enemies):
i = 1
print("\n" + bcolors.FAIL + bcolors.BOLD + " TARGET:" + bcolors.ENDC)
for enemy in enemies:
if enemy.get_hp() != 0:
print(" " + str(i) + ".", enemy.name)
i += 1
choice = int(input(" Choose target:")) - 1
return choice
def get_enemy_stats(self):
hp_bar = ""
bar_ticks = (self.hp / self.maxhp) * 100 / 2
while bar_ticks > 0:
hp_bar += "█"
bar_ticks -= 1
while len(hp_bar) < 50:
hp_bar += " "
hp_string = str(self.hp) + "/" + str(self.maxhp)
current_hp = ""
if len(hp_string) < 11:
decreased = 11 - len(hp_string)
while decreased > 0:
current_hp += " "
decreased -= 1
current_hp += hp_string
else:
current_hp = hp_string
print(" __________________________________________________ ")
print(bcolors.BOLD + self.name + " " +
current_hp + " |" + bcolors.FAIL + hp_bar + bcolors.ENDC + "|")
def get_stats(self):
hp_bar = ""
bar_ticks = (self.hp / self.maxhp) * 100 / 4
mp_bar = ""
mp_ticks = (self.mp / self.maxmp) * 100 / 10
while bar_ticks > 0:
hp_bar += "█"
bar_ticks -= 1
while len(hp_bar) < 25:
hp_bar += " "
while mp_ticks > 0:
mp_bar += "█"
mp_ticks -= 1
while len(mp_bar) < 10:
mp_bar += " "
hp_string = str(self.hp) + "/" + str(self.maxhp)
current_hp = ""
if len(hp_string) < 9:
decreased = 9 - len(hp_string)
while decreased > 0:
current_hp += " "
decreased -= 1
current_hp += hp_string
else:
current_hp = hp_string
mp_string = str(self.mp) + "/" + str(self.maxmp)
current_mp = ""
if len(mp_string) < 7:
decreased = 7 - len(mp_string)
while decreased > 0:
current_mp += " "
decreased -= 1
current_mp += mp_string
else:
current_mp = mp_string
print(" _________________________ __________ ")
print(bcolors.BOLD + self.name + " " +
current_hp +" |" + bcolors.OKGREEN + hp_bar + bcolors.ENDC + "| " +
current_mp + " |" + bcolors.OKBLUE + mp_bar + bcolors.ENDC + "|")
def choose_enemy_spell(self):
magic_choice = random.randrange(0, len(self.magic))
spell = self.magic[magic_choice]
magic_dmg = spell.generate_damage()
pct = self.hp / self.maxhp * 100
if self.mp < spell.cost or spell.type == "white" and pct > 50:
self.choose_enemy_spell()
else:
return spell, magic_dmg