forked from jf-2020/rpg-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpg-0.py
47 lines (41 loc) · 1.35 KB
/
rpg-0.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
"""
In this simple RPG game, the hero fights the goblin. He has the options to:
1. fight goblin
2. do nothing - in which case the goblin will attack him anyway
3. flee
"""
def main():
hero_health = 10
hero_power = 5
goblin_health = 6
goblin_power = 2
while goblin_health > 0 and hero_health > 0:
print("You have %d health and %d power." % (hero_health, hero_power))
print("The goblin has %d health and %d power." % (goblin_health, goblin_power))
print()
print("What do you want to do?")
print("1. fight goblin")
print("2. do nothing")
print("3. flee")
print("> ",)
user_input = input()
if user_input == "1":
# Hero attacks goblin
goblin_health -= hero_power
print("You do %d damage to the goblin." % hero_power)
if goblin_health <= 0:
print("The goblin is dead.")
elif user_input == "2":
pass
elif user_input == "3":
print("Goodbye.")
break
else:
print("Invalid input %r" % user_input)
if goblin_health > 0:
# Goblin attacks hero
hero_health -= goblin_power
print("The goblin does %d damage to you." % goblin_power)
if hero_health <= 0:
print("You are dead.")
main()