Python中的无效语法对于RPG游戏电脑游戏

2024-04-29 11:29:29 发布

您现在位置: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 ("---------------------------------------------------------")

Tags: name游戏类型def语法rpgprinthall
1条回答
网友
1楼 · 发布于 2024-04-29 11:29:29

您需要关闭roomsdict:

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

相关问题 更多 >