我正在尝试创建一个最终幻想类型的RPG战斗,但无论我尝试什么,词典或列表,它都不起作用。我试图做到这一点,所以我可以定义一次怪物,并在未来的战斗中一遍又一遍地重复使用它,而不会永久地消除怪物的统计数据。这是我的代码
#MONSTER STATS
corpsefinder_stats = {
"corpsefinder_strength" : 7,
"corpsefinder_speed" : 1,
"corpsefinder_mana" : 0,
"corpsefinder_health" : 45,
}
#LIVE STATS
#GAME START
if game_start==True:
time.sleep(0.6)
print("You wake up, the cold snow on your face as you lie down in bewilderment, wondering where you could of come from and why you are here. As you stand up, you notice a small village in the distance, but before you can even begin to think of venturing over, a small bug-like creature approaches, primed for battle")
time.sleep(8)
tutorialbattle=input("\nA CORPSE-FINDER gets ready to attack!\nWhat will you do?\n\n##########\n# Attack #\n##########\n\n##########\n# Defend #\n##########\n")
tutorialbattle=tutorialbattle.lower()
if tutorialbattle=="attack":
print (corpsefinder_stats) ["corpsefinder_health"] - strength
print(int(corpsefinder_health))
答案 0 :(得分:0)
第18行应该是
print (corpsefinder_stats["corpsefinder_health"] - strength)
第19行应该是
print (corpsefinder_stats["corpsefinder_health"])
如果您有兴趣在不同的怪物之间拥有单独的属性,我建议您查看课程 - https://docs.python.org/2/tutorial/classes.html
答案 1 :(得分:0)
在最后一行中,您引用了corpsefinder_health
,但没有这样的变量!它是dict corpsefinder_stats
的关键。
请改用:
print(corpsefinder_stats['corpsefinder_health'])
答案 2 :(得分:0)
首先你的行:
tutorialbattle=input()
应该是:(接受字符串输入)
tutorialbattle=raw_input()
以后再替换最后一行:
print(int(corpsefinder_health))
带
print(int(corpsefinder_stats["corpsefinder_health"]))
最后你的代码在使用前没有定义game_start
定义它。希望这会有所帮助:)