【发布时间】:2019-04-21 08:21:14
【问题描述】:
我试图制作一个只使用角色的 python 游戏,老实说我做到了,但结束条件太模糊了。为了制作一个,我简单地将 startLocation 指定为一个正常位置,完成目标后,我将返回起始位置并退出游戏以提供新的行文本。然而:
def locations():
startLocation = random.choice(mapaGrid)
monsterLocation = random.choice(mapaGrid)
wellLocation = random.choice(mapaGrid)
goldLocation = random.choice(mapaGrid)
arrowLocation = random.choice(mapaGrid)
if monsterLocation == goldLocation or monsterLocation == startLocation or goldLocation == startLocation or monsterLocation == arrowLocation or wellLocation == goldLocation or wellLocation == startLocation or wellLocation == monsterLocation:
return locations()
return startLocation, monsterLocation, goldLocation, arrowLocation, wellLocation
#Locais do jogador, monstro, ouro, poco, flecha e entrada.
playerLocation, monsterLocation, goldLocation, arrowLocation, wellLocation, startLocation = locations()
所以这就是代码失败的地方。当我最后将 startLocation 分配给 locations() 时,我在标题中得到错误,即使添加任何其他完全组成的位置不会导致此错误。我确实尝试过搜索,但由于我缺乏经验,我无法将答案与我的代码联系起来。
【问题讨论】:
-
Location 返回一个包含 5 个值的元组,您正试图将其分解为 6 个值。
playerLocation和startLocation有什么区别? -
playerLocation 是玩家在网格上的直接位置,因此每次移动时都会更新它。 startLocation 是玩家开始游戏的随机网格选择。
标签: python