我目前正在尝试制作非常基本的随机数游戏。一切似乎都应运而生,这要减去数学没有累加的事实。您会获得3个选项:1)攻击,2)治疗,3)退出游戏。每个函数都按预期的功能运行,并显示预期的结果,减去数学没有加起来的事实。
---------------------
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!
---------------------
老实说,我不确定我缺少什么,有点像白痴。
这里是来源。
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
任何帮助将不胜感激。
似乎您的游戏为每次攻击计算了两次伤害,一次在印刷前,一次在印刷中。尝试保存第一次攻击伤害计算的值,并在打印中使用该值,而不是计算另一个随机值。