Nov-21-2019, 12:46 AM
I'm following a tutorial on how to code a very simple game. My code looks exactly like in the tutorial (https://youtu.be/kDdTgxv2Vv0?t=2667 for reference)
The code looks like this
The "game_running" is supposed to change from True to False after the Player or Monster reaches 0 or less health which should make the While loop, end the loop and therefor end the game. Simple enough? No, not for me. The loop doesn't end after the while loop has met the criteria for the loop to end.
The code looks like this
player = {'name': 'Timmy', 'health': 100, 'attack': 75, 'heal': 16} monster = {'name': 'Kanashi', 'health': 150, 'attack' :15} game_running = True while game_running == True: player_won = False monster_won = False print('Please select action') print('1) Attack') print('2) Heal') player_choice = input() if player_choice == '1': monster['health'] = monster['health'] - player['attack'] if monster['health'] <= 0: player_won = True else: player['health'] = player['health'] - monster['attack'] if player['health'] <= 0: monster_won = True print(monster['health']) print(player['health']) elif player_choice == '2': print('Heal Player') else: print('Invalid Input') if player_won == True or monster_won == True: game_running = FalseMy problem with this code is that the while statment continues to loop forever, after the while loop = false. What is wrong with my code?
The "game_running" is supposed to change from True to False after the Player or Monster reaches 0 or less health which should make the While loop, end the loop and therefor end the game. Simple enough? No, not for me. The loop doesn't end after the while loop has met the criteria for the loop to end.