-
Notifications
You must be signed in to change notification settings - Fork 1
/
rpg_battle_update.py
179 lines (148 loc) · 5.59 KB
/
rpg_battle_update.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
#RPG Battle game
import random
import time
class Hero:
def __init__(self, name):
self.name = name
self.health = 500
def calculate_damage(self, damage_amount, attacker):
if (damage_amount > self.health):
overkill = abs(self.health - damage_amount)
self.health = 0
if (overkill > 0):
print ("{0} takes fatal damage from {1}, with {2} overkill!"
.format(self.name.capitalize(), attacker, overkill))
else:
print("{0} takes fatal damage from {1}!"
.format(self.name.capitalize(), attacker))
else:
self.health -= damage_amount
print("{0} takes {1} damage from {2}!"
.format(self.name.capitalize(), damage_amount, attacker))
def show_name(self):
return self.name
def move1(self):
self.move1_rand = random.randint(15, 30)
return self.move1_rand
def move2(self):
self.move2_rand = random.randint(30, 60)
return self.move2_rand
def defence_charge(self):
self.health += defence_amount
print("{0} casts a barrier, adding {1} to their health!"
.format(self.name.capitalize(), defence_amount))
@classmethod
def get_user_input(self):
name = input("Hello there, what is your name? ")
return self(name)
class Demon:
def __init__(self, name):
self.name = name
self.health = 1500
def calculate_damage(self, damage_amount, attacker):
if (damage_amount > self.health):
overkill = abs(self.health - damage_amount)
self.health = 0
if (overkill > 0):
print("{0} takes fatal damage from {1}, with {2} overkill!"
.format(self.name.capitalize(), attacker, overkill))
else:
print("{0} takes fatal damage from {1}!"
.format(self.name.capitalize(), attacker))
else:
self.health -= damage_amount
print("{0} takes {1} damage from {2}!"
.format(self.name.capitalize(), damage_amount, attacker))
def move1(self):
self.move1_rand = random.randint(15, 30)
return self.move1_rand
def move2(self):
self.move2_rand = random.randint(25,40)
return self.move2_rand
def move3(self):
self.ultimate = int(2000)
return self.ultimate
def parse_int(input):
try:
int(input)
return True
except ValueError:
return False
def move_selection():
valid_input = False
while (valid_input is False):
print()
choice = input("Select an attack: ")
if (parse_int(choice) is True):
return int(choice)
else:
print("The input was invalid. Re-enter your choice.")
def demon_move_selection(health):
sleep_time = random.randrange(2, 5)
print("You dare defy me?!")
time.sleep(sleep_time)
if (health <= 1300):
print("Heh, you have actually managed to leave a scratch, good, "
"it makes this fight more interesting!")
return random.randint(1, 2)
elif (health <= 1500):
return random.randint(1, 2)
def play_round(demon, hero):
game_in_progress = True
current_player = demon
while game_in_progress:
if (current_player == demon):
current_player = hero
else:
current_player = demon
print()
print(
"You have {0} health remaining and the "
"Demon Lord has {1} health remaining."
.format(hero.health, demon. health))
print()
if (current_player == hero):
print("Available attacks:")
print("1) Quick Punch")
print("2) Mega Punch")
print("3) Absolute Defence")
move = move_selection()
else:
move = demon_move_selection(demon.health)
if (move == 1):
damage = Hero(hero)
demon_damage = Demon(demon)
if (current_player == hero):
demon.calculate_damage(damage.move1(), hero.name.capitalize())
else:
hero.calculate_damage(demon_damage.move1(), demon.name.capitalize())
elif (move == 2):
damage = Hero(hero)
demon_damage = Demon(demon)
if (current_player == hero):
demon.calculate_damage(damage.move2(), hero.name.capitalize())
else:
hero.calculate_damage(demon_damage.move2(), demon.name.capitalize())
if (hero.health == 0):
print("Sorry, you lose!")
game_in_progress = False
if (demon.health == 0):
print("Congratulations, you beat the Demon Lord!")
game_in_progress = False
def gameGreeting():
print("Welcome to the RPG Hero Battle game!")
demon = Demon("Demon Lord Iruma")
name = input("Hello there, what is your name? ")
print("Ahhhh....yes...yes! You are the hero! Hero", name, "!")
print("You have come at a most fortunate time, you must defeat the Demon Lord!\nHe threatens us all!")
hero = Hero(name)
keep_playing = True
while (keep_playing is True):
demon.health = 1500
hero.health = 500
play_round(demon, hero)
print()
response = input("Play another round? (Y/N)")
if (response.lower() == "n"):
break
gameGreeting()