Python for RPG游戏中的语法无效

时间:2016-05-04 23:30:10

标签: 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 ("---------------------------------------------------------")

1 个答案:

答案 0 :(得分:3)

您需要关闭rooms字典:

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 ("---------------------------------------------------------")