角色扮演游戏,用字典攻击后怪物健康

时间:2015-07-09 10:54:57

标签: python dictionary

之前我曾经问过这个问题,因为我对词典还不太熟悉,但每次我自动攻击怪物的健康状况时,会发生什么:

#MONSTER STATS
corpsefinder_stats = {
    "corpsefinder_strength" : 7,
    "corpsefinder_speed" : 1,
    "corpsefinder_mana" : 0,
    "corpsefinder_health" : 45,
    }
#GAME START
if game_start==True:
time.sleep(0.6)
print(username, "wakes up, the cold snow on their face as they lie down in bewilderment, wondering where they could of come from and why they are here. As they stand up, they notice a small village in the distance, but before they can even begin to think of venturing over, a small bug-like creature approaches, primed for battle")
time.sleep(8)
while corpsefinder_stats["corpsefinder_health"] >= 1 or health >= 1:
    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":
        corpsefinder_stats["corpsefinder_health"] -(random.randint(strength-10, strength))
        print(username, " attack!\nCORPSE-FINDER HP: ", corpsefinder_stats["corpsefinder_health"])
        print("CORPSE-FINDER attacks!\n", username, " HP: ", health-(random.randint(corpsefinder_stats["corpsefinder_strength"]-6, corpsefinder_stats["corpsefinder_stren

1 个答案:

答案 0 :(得分:0)

当你这样做时:

corpsefinder_stats["corpsefinder_health"] -(random.randint(strength-10, strength))

您只是执行数学运算,而不是将其分配给任何东西。

你需要这样做:

corpsefinder_stats["corpsefinder_health"] = corpsefinder_stats["corpsefinder_health"] -(random.randint(strength-10, strength))

相关问题