-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathF) Blood Pit.py
More file actions
123 lines (88 loc) · 3.8 KB
/
F) Blood Pit.py
File metadata and controls
123 lines (88 loc) · 3.8 KB
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
hero_max_power=[20]
hero_max_health=[300]
hero_health=[300] # This is a list [] with only one item
hero_power=[20]
turn_counter=1
rep=[0]
"""
1)with f string there is no need to change an integer into a string anymore
eg : Use print( f"Totol Reputation: {rep}") instead of print("Total Reputation: " + str(rep))
2) This also demonstrate how we can maintain game state Without Globals or Classes but by using a
data structure called 'list'
Remember integers can't be modified inside a function but list can be, therefore,
wrapping values in lists allows shared state
Technically you can just use one list to represent each of the stats but it will be confusing
hero_stats-[20,300,300,20,0]
0= hero_max_power 1= hero_max_health 2=hero_health 3=hero_power 4=rep etc
So the first 'enemy function' would be
def enemy(name,enemy_hp,enemy_pow):
print(f"{name} {enemy_hp}hp {enemy_pow} power")
while hero_stats[2]>0 and enemy_hp>0:
hero_stats[2]-=enemy_pow
enemy_hp-=hero_stats[3]
print(f"The {name} attacks you. Your health is {hero_stats[2]}")
print(f"You attack the {name}. The {name}'s health is {enemy_hp}")
if hero_stats[2]<=0:
print("hero has been slained")
input("Press enter to quit")
quit()
if enemy_hp<=0:
print("You have slained the "+name)
break
"""
def enemy(name,enemy_hp,enemy_pow):
print(f"{name} {enemy_hp}hp {enemy_pow} power")
while hero_health[0]>0 and enemy_hp>0:
hero_health[0]-=enemy_pow
enemy_hp-=hero_power[0]
print(f"The {name} attacks you. Your health is {hero_health[0]}")
print(f"You attack the {name}. The {name}'s health is {enemy_hp}")
if hero_health[0]<=0:
print("hero has been slained")
input("Press enter to quit")
quit()
if enemy_hp<=0:
print("You have slained the "+name)
break
def level_up(hp_increase,pow_increase,enemy,rep_points):
rep[0]+=rep_points
hero_max_health[0]+=hp_increase
hero_max_power[0]+=pow_increase
hero_health[0] = hero_max_health[0]
hero_power[0] = hero_max_power[0]
print(f"you become stronger with every {enemy} you slay")
print("you gain some reputation for the fight")
print( f"Totol Reputation: {rep}") # no need to change an integer to a string anymore
while True:
print("Welcome to the blood pit, choose your opponent!! ")
choose=input( "Please select goblin, orc, pit fighter or red dragon: ")
choose=choose.upper()
while choose in ("GOBLIN", "ORC", "PIT FIGHTER", "RED DRAGON"):
print("your opponent is a...")
if choose==("GOBLIN"):
enemy("Goblin",200,20)
level_up(30,10,"Goblin",10)
break
elif choose==("ORC"):
enemy("Orc",400,60)
level_up(50,15,"Orc",50)
break
elif choose==("PIT FIGHTER"):
enemy("Pit Fighter",500,200)
level_up(70,25,"Pit Fighter",100)
break
elif choose==("RED DRAGON"):
enemy("Red Dragon",1500,400)
level_up(100,30,"Red Dragon",300)
break
else:
print("Try again")
break
turn_counter+=1
print(f"It is turn {turn_counter}") # no need to change an integer to a string anymore
if rep[0]>2500:
print("You are the master of the blood pit")
print(f"You beat the game on turn {turn_counter}")
input("You win, press enter to exit")
break
#https://github.com/Ninedeadeyes/15-mini-python-games-