-
Notifications
You must be signed in to change notification settings - Fork 0
/
battle.py
45 lines (43 loc) · 1.48 KB
/
battle.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
import time
class Battle:
def do_battle(self, hero, enemy):
print("=====================")
print("%s faces %s" % (hero.name, enemy.name))
print("=====================")
while hero.is_alive(enemy) and enemy.is_alive(hero):
hero.print_status()
enemy.print_status()
time.sleep(1.5)
print("-----------------------")
print("What do you want to do?")
print("1. fight %s" % enemy.name)
print("2. use an item")
print("3. flee")
print("> ",)
user_input = int(input())
if user_input == 1:
hero.attack(enemy)
elif user_input == 2:
if hero.items == []:
print("You have no items.")
continue
else:
try:
hero.use_item(hero.items, enemy)
except (ValueError, IndexError):
print("Did not choose an eligible item")
continue
elif user_input == 3:
print("Goodbye.")
exit(0)
else:
print("Invalid input %r" % user_input)
continue
enemy.attack(hero)
if hero.is_alive(enemy):
print("You defeated %s" % enemy.name)
enemy.give_bounty(hero)
return True
else:
print("YOU LOSE!")
return False