Dec-06-2019, 09:31 PM
So, I'm trying to make a code to dodge the monsters attack, I want to pick a random value from dodge, and then depending on the value that is picked, I want it to print whether or not you managed to dodge the attack.
player = {'name': 'matthew', 'attack': 10, 'heal': 25, 'health': 100} monster = {'name': 'Joe', 'attack': 25, 'health': 100} health_list = ['Health', 'health'] game_running = True dodge = [1, 2] import random dodge1 = dodge while game_running == True: player_won = False monster_won = False print('\n-------------------------------------') print('please select an action') print("Type ? for a list of commands") print('-------------------------------------') print('\n1) Attack') print('2) Heal') print('3) Dodge') print('\n-------------------------------------') player_choice = input('>>>') if player_choice == '1': print('\nYou attacked the monster!') 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('Player health: ', player['health']) print('Monster health: ', monster['health']) elif player_choice == '2': print('\n---------------------------------') print('You used a potion and healed 25 HP! ') print('---------------------------------') player['health'] = player['health'] + player['heal'] elif player_choice in health_list: print('\n-----------------------------------') print('your health is: ', player['health']) print("Monster's health is:", monster['health'] ) print('-----------------------------------') elif player_choice == '?': print('\n-----------------------------------') print('Heres a list of commands:') print('-----------------------------------') print('- Health: shows your current health and the enemies current health.') print('- Version: shows the games current version') print('-----------------------------------') elif player_choice == '3': print(random.choice(dodge1)) if dodge == 1: print("You dodged the monsters attack!") elif dodge == 2: print("Your dodge attempt failed!") else: print("null") else: print('\n-----------------------------------') print('Invalid Input: use 1, 2, or 3') print('-----------------------------------') if player_won == True or monster_won == True: game_running = False