python - RPG 游戏的 Python 语法无效

标签 python

我对 Python 比较陌生,并且正在创建一个基本的 Python RPG wordquest 类型游戏。我在 def showInstructions(): 上不断收到无效语法.

rooms = {
        1 : {   "name"  :   "Hall"  },
        2 : {   "name"  :   "Bedroom" },
        3 : {   "name"  :   "Kitchen" },
        4 : {   "name"  :   "Bathroom" }

def showInstructions():
    #The Main Menu
    print ("Mr Bailey's Nightmare!")
    print ("======================")
    print ("Commands:")
    print ("go [direction]'")

def showStatus
    #shows player stats, essentially current room
    print ("---------------------------------------------------------")
    print ("You are in the " + rooms[currentRoom]["name"]
    print ("---------------------------------------------------------")

最佳答案

您需要关闭房间字典:

rooms = {
    1 : {   "name"  :   "Hall"  },
    2 : {   "name"  :   "Bedroom" },
    3 : {   "name"  :   "Kitchen" },
    4 : {   "name"  :   "Bathroom" }

需求

}

所以

rooms = {
    1 : {   "name"  :   "Hall"  },
    2 : {   "name"  :   "Bedroom" },
    3 : {   "name"  :   "Kitchen" },
    4 : {   "name"  :   "Bathroom" }
}

而且 showStatus 的语法也很困惑

def showStatus(currentRoom): # is this the right argument?
    #shows player stats, essentially current room
    print ("---------------------------------------------------------")
    print ("You are in the " + rooms[currentRoom]["name"])
    print ("---------------------------------------------------------")

关于python - RPG 游戏的 Python 语法无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37039810/

相关文章:

python - 带有 like from 变量的 SQL 语句

python - 使用 Python Pytables 加载 Matlab 稀疏矩阵

python - 运行时错误:ALBroker::createBroker

python - Pandas 多索引数据帧: replace certain values by values from other column on 2nd level

python - 我们如何格式化像这个 pickle 这样的数据

python - 我如何使用 python 文件和 RopeVim 插件为 "Rope project root folder: . "指定什么?

python - 月份范围计算未返回预期结果

python - 使用literal_eval 将字符串转换为字典

python - 什么 python 模块取代了 urllib2 以用于 python 3 和 flask?

python - 问题导入 Python 临时文件模块