-
Notifications
You must be signed in to change notification settings - Fork 0
/
battle game(1).py
164 lines (101 loc) · 3.21 KB
/
battle game(1).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
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import random
class Player:
def __init__(self, health = 100):
self.health = health
def take_damage(self, damage):
self.health -= damage
ai = Player()
human = Player()
playing = True
human_player_active = True
def ask_action():
move = 0
while move not in range(1,3):
print(f'\nYou have {human.health} health left. The enemy has {ai.health} left. What do you want to do?')
move = int(input('\n1 - Cautious Punch\n2 - Reckless Punch\n3 - Heal \n'))
if move == 1:
weak_punch()
elif move == 2:
strong_punch()
elif move == 3:
heal()
def weak_punch():
hit_strength = random.randint(18, 25)
if human_player_active:
if hit_strength >= ai.health:
player_win()
else:
ai.take_damage(hit_strength)
print(f'\nYou used the Cautious Punch, hitting the enemy for {hit_strength}. They have {ai.health} health left.')
else:
if hit_strength >= human.health:
ai_win()
else:
human.health -= hit_strength
print(f'\nThe enemy used the Cautious Punch, hitting you for {hit_strength}. You got {human.health} health left.')
def strong_punch():
hit_strength = random.randint(10, 35)
if human_player_active:
if hit_strength >= ai.health:
player_win()
else:
ai.take_damage(hit_strength)
print(f'\nYou used the Reckless Punch, hitting the enemy for {hit_strength}. They have {ai.health} health left.')
else:
if hit_strength >= human.health:
ai_win()
else:
human.health -= hit_strength
print(f'\nThe enemy used the Reckless Punch, hitting you for {hit_strength}. You got {human.health} health left.')
def heal():
if human_player_active:
human.take_damage(-10)
if human.health > 100:
human.health = 100
print(f'\nYou healed 10 and now have {human.health} left.')
else:
ai.take_damage(-10)
if ai.health > 100:
ai.health = 100
print(f'\nThe enemy healed 10 and now has {ai.health} left.')
def ai_action():
if ai.health >90:
ai_decision = randint(1,2)
if ai_decision == 1:
weak_punch()
elif ai_decision == 2:
strong_punch()
elif ai.health < 36:
ai_decision = randint(1,100):
if 0 < ai_decision < 51:
heal()
# while health low more likely to heal
pass
# def check_death():
# pass
# In[39]:
def player_win():
print(f'You got him for {hit_strength}, bringing his health down to 0. You won!\n')
# decision = lower(input('Play again? y/n '))
# if decision[0] == 'y':
# pass
# else:
# playing = False
# break
playing = False
def ai_win():
pass
# In[48]:
weak_punch()
# In[49]:
human.take_damage(30)
# In[51]:
human.health
# In[55]:
heal()
# In[2]:
ask_action()
# In[ ]: