@tech4teachers/

GREG's FINISHED Python Turn based PlyrVsCmptr JoJo's Game

Python

No description

fork
loading
Files
  • main.py
main.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
#Template for battles made by https://codereview.stackexchange.com/questions/94116/turn-based-battle-simulator
import os
import random
import sys
#import time

print("Place Holder Story Text")

#Tutorial Battle Against Vark
def main():
    """Main function that will welcome the player to the game."""

    print("\tWelcome to your first battle! The combat in this game is turn based")
    print("\nHow to play.\n\nPlayers take turns to choose a move. Moves can either deal moderate damage")
    print("or they can heal. (Note: Moves can miss, including Heal!)")

    print("\nThe player starts with 1000 health, and the first")
    print("player to reduce their opponent to 0 is the winner.")

    play_again = True

    # Set up the play again loop
    while play_again:
        blocked=False #putting this higher here, solves the issue with it being unseen when it was the computer players turn 
        winner = None
        player_health = 1000
        vark_health = 500

        # determine whose turn it is
        turn = random.randint(1,2) # heads or tails
        if turn == 1:
            player_turn = True
            computer_turn = False
            print("\nPlayer will go first.")
        else:
            player_turn = False
            computer_turn = True
            print("\n Vark will go first.")


        print("\nPlayer health:", player_health, "Vark's health: ", vark_health)

        # set up the main game loop
        while (player_health != 0 or vark_health != 0):

            heal_up = False # determine if heal has been used by the player. Resets false each loop.
            miss = False # determine if the chosen move will miss.
            #tried putting blocked= at this location ..but didn't work....not global enough for the computer's turn to detect what it had been set to be
            # create a dictionary of the possible moves and randomly select the damage it does when selected
            player_moves = {"Duplicate Weapon": random.randint(30, 65),
                     "Duplicate High Velocity Bulltet": random.randint(25, 100),
                     "Duplicate Wall": 0,
                     "Recharge Stand Energy": random.randint(40, 65)}
            varks_moves = {"Pressurized Blow": random.randint(20, 65),
                     "Ajusting Pressure": random.randint(25, 75),
                     "Reliveing Pressure": random.randint(1, 200)}
                     

            if player_turn:
                print("\nPlease select a move:\n1. Duplicate Weapon (Deal damage between 30-55)\n2. Duplicate High Velocity Bullet (Deal damage between 25-100)\n3. Duplicate Wall (Chance of blocking an attack) \n4. Recharge Stand Energy (Restore between 40-65 health)\n")

                player_move = input("> ").lower()

                move_miss = random.randint(1,5) # 20% of missing
                if move_miss == 1:
                    miss = True
                else:
                    miss = False

                if miss and blocked==True:
                    player_move = 0 # player misses and deals no damage
                    print("You are ready to block!")
                if miss:
                    player_move = 0 # player misses and deals no damage
                    print("You failed your chance!")
                else:
                    if player_move in ("1", "Duplicate Weapon"):
                        player_move = player_moves["Duplicate Weapon"]
                        print("\nYou duplicated a weapon. It dealt ", player_move, " damage.")
                    elif player_move in ("2", "Duplicate High Velocity Bulltet"):
                        player_move = player_moves["Duplicate High Velocity Bulltet"]
                        print("\nYou shot your opponent with a high velocity bullet. It dealt ", player_move, " damage.")
                    elif player_move in ("3", "Duplicate Wall"):
                          player_move = 1
                          if player_move==1:
                            blocked=True
                            player_move=0
                            print("\nYou duplicated a wall to block the enimes next attck")
                          else:
                            blocked=False
                            player_move=0
                            print("\nYou Failed to block")

                          
                    elif player_move in ("4", "Recharge Stand Energy"):
                        heal_up = True # heal activated
                        player_move = player_moves["Recharge Stand Energy"]
                        print("\nYou recharged your stand energy. It healed for ", player_move, " health.")
                    else:
                        print("\nThat is not a valid move. Please try again.")
                        continue

            else: # computer turn

                move_miss = random.randint(1,4)
                if move_miss == 1:
                    miss = True
                elif move_miss >1 and blocked==False:
                    miss = False
                elif blocked==True:
                    miss = True
                

                else:
                    miss = True

                if miss==True and blocked==False:
                    computer_move = 0 # the computer misses and deals no damage
                    print("Vark wiffed it big time ...didn''t even touch the wall!")
                    blocked=False
                elif miss==True and blocked==True:
                    computer_move = 0 # the computer misses and deals no damage
                    print("Vark was Blocked Successfully, only superficial scratches on your wall as it fades away for the next round of battle!")
                    blocked=False
                else:
                    if vark_health > 30: 
                        if player_health > 75:
                            computer_move = varks_moves["Pressurized Blow"]
                            print("\nVark used a pressurised blow. It dealt ", computer_move, " damage.")
                        elif player_health > 35 and player_health <= 75: # computer decides whether to go big or play it safe
                            imoves = ["Pressurized Blow", "Ajusting Pressure"]
                            imoves = random.choice(imoves)
                            computer_move = varks_moves[imoves]
                            print("\nVark used ", imoves, ". It dealt ", computer_move, " damage.")
                        elif player_health <= 35:
                            computer_move = varks_moves["Ajusting Pressure"] # FINISH HIM!
                            print("\nVark ajusted your pressure. It dealt ", computer_move, " damage.")                       
                    else: # if the computer has less than 30 health, there is a 50% chance they will heal
                        heal_or_fight = random.randint(1,2) 
                        if heal_or_fight == 1:
                            heal_up = True
                            computer_move = varks_moves["Reliveing Pressure"]
                            print("\nVark relived pressure to heal. It healed for ", computer_move, " health.")
                        else:
                            if player_health > 75:
                                computer_move = varks_moves["Pressurized Blow"]
                                print("\nVark used a pressurized blow. It dealt ", computer_move, " damage.")
                            elif player_health > 35 and player_health <= 75:
                                imoves = ["Pressurized Blow", "Ajusting Pressure"]
                                imoves = random.choice(imoves)
                                computer_move = varks_moves[imoves]
                                print("\nVark used ", imoves, ". It dealt ", computer_move, " damage.")
                            elif player_health <= 35:
                                computer_move = varks_moves["Ajusting Pressure"] # FINISH HIM!
                                print("\nVark ajusted the pressure. It dealt ", computer_move, " damage.")
                    blocked=False
            if heal_up:
                if player_turn:
                    player_health += player_move
                    if player_health > 1000:
                        player_health = 1000 # cap max health at 1000. No over healing!
                else:
                    vark_health += computer_move
                    if vark_health > 500:
                        vark_health = 500
            else:
                if player_turn:
                    vark_health -= player_move
                    if vark_health < 0:
                        vark_health = 0 # cap minimum health at 0
                        winner = "Player"
                        break
                else:
                    player_health -= computer_move
                    if player_health < 0:
                        player_health = 0
                        winner = "Vark"
                        break

            print("\nPlayer's health: ", player_health, "Vark's health: ", vark_health)

            # switch turns
            player_turn = not player_turn
            computer_turn = not computer_turn

        # once main game while loop breaks, determine winner and congratulate

        if winner == "Player":
            print("\nPlayer health: ", player_health, "Vark's health: ", vark_health)
            print("\nCongratulations! You have won. You're an animal!!")
        else:
            print("\nPlayer health: ", player_health, "Vark's health: ", vark_health)
            print("\nSorry, but your opponent wiped the floor with you. Better luck next time.")

        print("\nWould you like to play again?")

        answer = input("> ").lower()
        if answer not in ("yes", "y"):
            play_again = False
            os.system('clear')

main()

print("Placeholder Story Text")


def main():
    """Main function that will welcome the player to the game."""

    print("\tWelcome to your second battle! The combat in this game is turn based")
    print("\nHow to play.\n\nPlayers take turns to choose a move. Moves can either deal moderate damage")
    print("or they can heal. (Note: Moves can miss, including Heal!)")

    print("\nThe player starts with 1000 health, and the first")
    print("player to reduce their opponent to 0 is the winner.")

    play_again = True
    

    # Set up the play again loop
    while play_again:
        blocked=False #putting this higher here, solves the issue with it being unseen when it was the computer players turn 
        winner = None
        player_health = 1000
        Perd_health = 500

        # determine whose turn it is
        turn = random.randint(1,2) # heads or tails
        if turn == 1:
            player_turn = True
            computer_turn = False
            print("\nPlayer will go first.")
        else:
            player_turn = False
            computer_turn = True
            print("\n Perd will go first.")


        print("\nPlayer health:", player_health, "Perd's health: ", Perd_health)

        # set up the main game loop
        while (player_health != 0 or Perd_health != 0):

            heal_up = False # determine if heal has been used by the player. Resets false each loop.
            miss = False # determine if the chosen move will miss.
            #tried putting blocked= at this location ..but didn't work....not global enough for the computer's turn to detect what it had been set to be
            # create a dictionary of the possible moves and randomly select the damage it does when selected
            player_moves = {"Duplicate Weapon": random.randint(30, 65),
                     "Duplicate High Velocity Bulltet": random.randint(25, 100),
                     "Duplicate Wall": 0, 
                    "Recharge Stand Energy": random.randint(40, 65)
            }
            Perds_moves = {"Propeller Throw": random.randint(25, 75),
                     "Propeller Spin Pull": random.randint(10, 125),
                     "Heal": random.randint(20,80)
                     }
                     

            if player_turn:
                print("\nPlease select a move:\n1. Duplicate Weapon (Deal damage between 30-55)\n2. Duplicate High Velocity Bullet (Deal damage between 25-100)\n3. Duplicate Wall (Chance of blocking an attack) \n4. Recharge Stand Energy (Restore between 40-65 health)\n")

                player_move = input("> ").lower()

                move_miss = random.randint(1,5) # 20% of missing
                if move_miss == 1:
                    miss = True
                else:
                    miss = False

                if miss and blocked==True:
                    player_move = 0 # player misses and deals no damage
                    print("You are ready to block!")
                if miss:
                    player_move = 0 # player misses and deals no damage
                    print("You failed your chance!")
                else:
                    if player_move in ("1", "Duplicate Weapon"):
                        player_move = player_moves["Duplicate Weapon"]
                        print("\nYou duplicated a weapon. It dealt ", player_move, " damage.")
                    elif player_move in ("2", "Duplicate High Velocity Bulltet"):
                        player_move = player_moves["Duplicate High Velocity Bulltet"]
                        print("\nYou shot your opponent with a high velocity bullet. It dealt ", player_move, " damage.")
                    elif player_move in ("3", "Duplicate Wall"):
                          player_move = 1
                          if player_move==1:
                            blocked=True
                            player_move=0
                            print("\nYou duplicated a wall to block the enimes next attck")
                          else:
                            blocked=False
                            player_move=0
                            print("\nYou Failed to block")

                          
                    elif player_move in ("4", "Recharge Stand Energy"):
                        heal_up = True # heal activated
                        player_move = player_moves["Recharge Stand Energy"]
                        print("\nYou recharged your stand energy. It healed for ", player_move, " health.")
                    else:
                        print("\nThat is not a valid move. Please try again.")
                        continue

            else: # computer turn

                move_miss = random.randint(1,4)
                if move_miss == 1:
                    miss = True
                elif move_miss >1 and blocked==False:
                    miss = False
                elif blocked==True:
                    miss = True
                

                else:
                    miss = True

                if miss==True and blocked==False:
                    computer_move = 0 # the computer misses and deals no damage
                    print("Per wiffed it big time ...didn''t even touch the wall!")
                    blocked=False
                elif miss==True and blocked==True:
                    computer_move = 0 # the computer misses and deals no damage
                    print("Perd was Blocked Successfully, only superficial scratches on your wall as it fades away for the next round of battle!")
                    blocked=False
                else:
                    if Perd_health > 30: 
                        if player_health > 75:
                            computer_move = Perds_moves["Propeller Throw"]
                            print("\nPerd threw a propeller. It dealt ", computer_move, " damage.")
                        elif player_health > 35 and player_health <= 75: # computer decides whether to go big or play it safe
                            imoves = ["Propeller Throw", "Propeller Spin Pull"]
                            imoves = random.choice(imoves)
                            computer_move = Perds_moves[imoves]
                            print("\nPerd used ", imoves, ". It dealt ", computer_move, " damage.")
                        elif player_health <= 35:
                            computer_move = Perds_moves["Propeller Spin Pull"] # FINISH HIM!
                            print("\nPerd spun his popellers pulling you closer to to finish you off. It dealt ", computer_move, " damage.")                       
                    else: # if the computer has less than 30 health, there is a 50% chance they will heal
                        heal_or_fight = random.randint(1,2) 
                        if heal_or_fight == 1:
                            heal_up = True
                            computer_move = Perds_moves["Heal"]
                            print("\nPerd used healed. It added ", computer_move, " health.")
                        else:
                            if player_health > 75:
                                computer_move = Perds_moves["Propeller Throw"]
                                print("\nPerd threw a propeller. It dealt ", computer_move, " damage.")
                            elif player_health > 35 and player_health <= 75:
                                imoves = ["Propeller Throw", "Propeller Spin Pull"]
                                imoves = random.choice(imoves)
                                computer_move = Perds_moves[imoves]
                                print("\nPerd used ", imoves, ". It dealt ", computer_move, " damage.")
                            elif player_health <= 35:
                                computer_move = Perds_moves["Propeller Spin Pull"] # FINISH HIM!
                                print("\nPerd spun his popellers pulling you closer to to finish you off. It dealt ", computer_move, " damage.")
                    blocked=False
            if heal_up:
                if player_turn:
                    player_health += player_move
                    if player_health > 1000:
                        player_health = 1000 # cap max health at 1000. No over healing!
                else:
                    Perd_health += computer_move
                    if Perd_health > 1000:
                        Perd_health = 1000
            else:
                if player_turn:
                    Perd_health -= player_move
                    if Perd_health < 0:
                        Perd_health = 0 # cap minimum health at 0
                        winner = "Player"
                        break
                else:
                    player_health -= computer_move
                    if player_health < 0:
                        player_health = 0
                        winner = "Perd"
                        break

            print("\nPlayer's health: ", player_health, "Perd's health: ", Perd_health)

            # switch turns
            player_turn = not player_turn
            computer_turn = not computer_turn

        # once main game while loop breaks, determine winner and congratulate

        if winner == "Player":
            print("\nPlayer health: ", player_health, "Perd's health: ", Perd_health)
            print("\nCongratulations! You have won. You're an animal!!")
        else:
            print("\nPlayer health: ", player_health, "Perd's health: ", Perd_health)
            print("\nSorry, but your opponent wiped the floor with you. Better luck next time.")

        print("\nWould you like to play again?")

        answer = input("> ").lower()
        if answer not in ("yes", "y"):
            play_again = False
            os.system('clear')

main()
play_again = False
print("That's the end of the game for now...")