I am currently attempting to make a very basic random number game. Everything seems to be working the way it should minus the fact that the math isn't adding up. You get 3 options 1) Attack, 2) Heal, 3) Exit Game. Each one functions as intended and display what should be expected, minus the fact that the math does not add up.
--------------------- Beau hit the monster for 10 damage! The Monster hit Beau for 18 damge! You now have 81 health points! The monster now has 80 health points! ---------------------
I'm honestly not sure what I am missing and kind of feel like an idiot.
here is the source.
from random import randint
game_running = True
def calculate_monster_attack(attack_min, attack_max):
return randint(attack_min,attack_max)
def calculate_player_attack(attack_min, attack_max):
return randint(attack_min, attack_max)
def calculate_player_healing(healing_min, healing_max):
return randint(healing_min, healing_max)
while game_running == True:
new_round = True
player = {'attack_min': 10, 'attack_max': 20, 'healing_min': 10, 'healing_max': 18, 'health': 100}
monster = {'name': 'Monster', 'attack_min': 10, 'attack_max': 20, 'health': 100}
print('---' * 7)
print('Enter Player name!')
player['name'] = input()
while new_round == True:
player_won = False
monster_won = False
print('---' *7)
print('Please select an action')
print('---' *7)
print('1) Attack')
print('---' *7)
print('2) Heal')
print('---' *7)
print('3) Exit Game')
player_choice = input()
print('---' *7)
if player_choice == '1':
monster['health'] = monster['health'] - calculate_player_attack(player['attack_min'], player['attack_max'])
print(player['name'] + ' hit the monster for {} damage!'.format(calculate_player_attack(player['attack_min'], player['attack_max'])))
if monster['health'] <= 0:
player_won = True
else:
player['health'] = player['health'] - calculate_monster_attack(monster['attack_min'], monster['attack_max'])
print('The ' + (monster['name'] + ' hit ' + player['name'] + ' for {} damage!'.format(calculate_monster_attack(monster['attack_min'], monster['attack_max']))))
if player['health'] <=0:
monster_won = True
elif player_choice == '2':
player['health'] = player['health'] + calculate_player_healing()
print('You healed yourself and now have {} health points!'.format(player['health']))
print('The ' + (monster['name'] + ' hit ' + player['name'] + ' for {} damge!'.format(calculate_monster_attack(monster['attack_min'], monster['attack_max']))))
player['health'] = player['health'] - calculate_monster_attack(monster['attack_min'], monster['attack_max'])
if player['health'] <=0:
monster_won = True
elif player_choice == '3':
new_round = False
game_running = False
else:
print('Invalid Input')
if player_won == False and monster_won == False:
print('You now have {} health points!'.format(player['health']))
print('The monster now has {} health points!'.format(monster['health']))
elif monster_won:
print('Oh no! Better luck next time ' + player['name'] + ', the monster won this round!')
new_round = False
elif player_won:
print('Congratulations ' + player['name'] + ' you beat the monster!')
new_round = False
Any help would be greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire