【发布时间】:2017-10-24 08:46:28
【问题描述】:
我在输入和输入单个单词时遇到了“超出范围”。我理解为什么它们超出范围,我只是找不到解决问题的方法。这是我的代码:
commands = {
'help': help,
'exit': exit,
'look': look,
'stats': thePlayer.printStats,
's':thePlayer.move_South}
def runCmd(cmd, args, player):
commands[cmd](args, player)
def help(args):
print(commands)
def play():
main1()
World.loadTiles()
#These lines load the starting room and display the text
room = World.tileExists(player.locationX, player.locationY)
print(room.introText())
while player.isAlive():
room = World.tileExists(player.locationX, player.locationY)
room.modifyPlayer(player)
# Check again since the room could have changed the player's state
if player.isAlive():
print("\nHp:%d\%d Mp:%d\%d\n"%(player.hp,player.maxHp,player.mp,player.maxMp))
print(room.printEnemy())
availableActions = room.availableActions()
for action in availableActions:
print(action)
actionInput = input('Action: ')
action = actionInput.lower()
action = action.split()
print(action)
if action[0] in commands:
runCmd(action[0],action[1], player)
我意识到我没有传递“动作 [1]”,并且只是按 Enter 键不在“命令”中导致我的错误。我是编码新手,所以创建游戏是我自学的方式。
我正试图到达我可以输入的位置:输入、单字(帮助、统计)、双字(看老鼠)、其他有更多单词的东西(购买大剑)等等。关于如何正确编码的任何帮助?
【问题讨论】:
标签: python-3.x text-based