2015-11-19 17 views
0
sceneDict = {} 

sceneDict["Beggining"] = { 
"Branching" : False 
"SceneText" : "Walking towards the enterance to the hollowed out tree you \ 
notice some large skulls on the sides of the dirt path along with other \ 
large sized bones which don't look like anything you've ever seen before.", 
"NextScene" : "Enterance" 
} 

sceneDict["Enterance" = { 
"Branching": True, 
"SceneText" : "You come up to the cave enterance and upon inspecting it you notice some \ 
liquid dripping from the roof of the enterance, you catch a small amount in your hand.. It's \ 
red and has the consistency of blood. All of a sudden a thundering roar is heard behind you and a massive \ 
troll has appeared!", 
"Choices" : [ 
     {"ChoiceNumber" : "1. ", 
     "ChoiceText" : "Run into the cave to escape the troll", 
     "NextScene" : "Cave"}, 
     {"ChoiceNumber" : "2. ", 
     "ChoiceText" : "Attempt to escape between the trolls legs", 
     "NextScene" : "Chase"}, 
     {"ChoiceNumber" : "3. ", 
     "ChoiceText" : "Pull out your sword in an attempt to combat the troll" 
     "NextScene" : "Combat"} 
    ] 
} 

sceneDict["Combat"] = { 
"Branching": False, 
"SceneText" : "As you reach back to grab your sword from your back the troll puts its arm out to the \ 
side and in one sweeping motion smashes you into a tree, unfortunately ending your life.", 
"NextScene" : "Afterlife" 
} 

sceneDict["Afterlife"] = { 
"Branching": True, 
"SceneText" : "You feel sunlight on your face and as you open your eyes there is two pathways infront of you \ 
as well as a sign over top of both'that's strange, I should probably be dead' however, above the arrow signs \ 
there is a sign that reads 'You messed up, it happens but try again' the paths both lead to the two other choices\ 
you had before you took the worst of the three choices.", 
"Choices" : [ 
     {"ChoiceNumber" : "1. ", 
     "ChoiceText" : "Run into the cave to escape the troll", 
     "NextScene" : "Cave"}, 
     {"ChoiceNumber" : "2. ", 
     "ChoiceText" : "Attempt to escape between the trolls legs", 
     "NextScene" : "Chase"} 
    ] 
} 

sceneDict["Chase"] = { 
"Branching": False, 
"SceneText" : "You slide on your knees between the trolls legs as it's enormous fists come crashing down behind \ 
you, you get back up and start running down the hill towards your village hearing its thunderous steps close \ 
behind. The people of your town hear the ruckus and go towards the gate to see you being chased and they all \ 
start cheering you to keep going!", 
"NextScene" : "Decisions" 
} 

sceneDict["Decisions"] = { 
"Branching": True, 
"SceneText" : "You are about 100 meters out from your village but you remember that there is a river to the \ 
right of the gate you could most likely lead the troll over there and have it crash through the bridge \ 
into the water, or you could chance the guards speed of closing the gate to block the troll.", 
"Choices" : [ 
     {"ChoiceNumber" : "1. ", 
     "ChoiceText" : "Continue towards the village", 
     "NextScene" : "Village"}, 
     {"ChoiceNumber" : "2. ", 
     "ChoiceText" : "Run towards the water", 
     "NextScene" : "Bridge"} 
    ] 
} 

sceneDict["Village"] = { 
"Branching": False, 
"SceneText" : "You run towards the village as fast as you possibly can the troll clearling gaining on you \ 
you call out for the guards to start closing the gate as you are running, the gate begins to close as you \ 
close in on it, you quickly slide through the last remaining opening as the gate slams shut followed by a loud \ 
'BANG!' as the troll smashes his head into the gate. The village cheers as you made it back alive!", 
} 
sceneDict["Bridge"] = { 
"Branching": False, 
"SceneText" : "As the villagers are cheering they start questioning what are you doing?! You change your path \ 
and go for the bridge. You start running over the wooden bridge as it is creeking and after a few seconds \ 
really shaking. Suddenly you hear a snap as the bottom gives out and you grab onto the side of the bridge. \ 
The bridge falls away at your feet only leaving the sides to hold onto as you hear a loud splash and see \ 
the troll floating away into the distance.", 
} 

sceneDict["Cave"] = { 
"Branching": True, 
"SceneText" : "You run forward into the cave, and slip on some of the blood into the depths of it. Behind you \ 
the troll is coming, however you hear the sound of splashing further into the cave.", 
"Choices" : [ 
     {"ChoiceNumber" : "1. ", 
     "ChoiceText" : "Run deeper into the cave towards the splashing", 
     "NextScene" : "Jump"}, 
     {"ChoiceNumber" : "2. ", 
     "ChoiceText" : "Stand your ground to the troll", 
     "NextScene" : "Learn"} 
    ] 
} 
sceneDict["Jump"] = { 
"Branching": False, 
"SceneText" : "You run towards the end of a cliff which has a small waterfall going over the edge of it \ 
you hear the troll gaining on you, but the drop is managable, you take a step back and leap for glory! You \ 
land with a splash and the troll sits at the top roaring in anger at your escape, you made it.. now to find \ 
your way home..", 
} 

sceneDict["Learn"] = { 
"Branching": False, 
"SceneText" : "You reach back to grab your sword from your back but in one swift movement the troll smashes you \ 
into the ground turning you into mince meat, very unfortunate.. You hear a shimmering sound and you appear back \ 
in on the path towards the cave again as if a God has given you a second chance or something.", 
"NextScene" : "Enterance" 
} 

currentScene = "Beggining" 

while currentScene != "": 
    sceneData = sceneDict[currentScene] 
    print(sceneData["SceneText"]) 
    print() 

    if sceneData["Branching']: 
     for choice in sceneData["Choices"]: 
      print(choice["ChoiceNumber"] + choice["ChoiceText"]) 

     print() 

     answer = input("> ") 
     print() 

     answer = int(answer) - 1 
     if answer <= len(sceneData["Choices"]) 
      currentScene = sceneData["Choices"][answer]["NextScene"] 

    else: 
     currentScene = sceneData ["NextScene"] 

window.exitonclick() 

我有這個代碼,它應該工作看起來完美無瑕,但是我每次運行它時都會收到一個語法錯誤,但它不會將錯誤指向我?錯誤在哪裏,如果你能幫助我,我該如何解決這個問題,謝謝!我該如何解決這個在python上的分支/故事製作?

+0

顯示錯誤信息。 – furas

回答

2

在while循環,你已經使用了不正確收盤報價在你的if語句:

if sceneData["Branching'] 

您應該使用:

if sceneData["Branching"] 

或:

if sceneData['Branching'] 

而且,爲了讓文本在多行上,您應該執行以下操作:

sceneDict["Beggining"] = { 
    "Branching" : False 
    "SceneText" : "Walking towards the enterance to the hollowed out tree you \n" 
        "notice some large skulls on the sides of the dirt path along with other \n" 
        "large sized bones which don't look like anything you've ever seen before.", 
    "NextScene" : "Enterance" 
} 
+0

嘿,感謝響應予固定的,並且還注意到前面我不得不 'sceneDict [ 「Enterance」= {' 所以我固定的到 'sceneDict [ 「Enterance」] = {' 但經過定影這兩件事我仍然收到語法錯誤,並沒有指向它。 – Gramaru

+0

因此,我縮進了上面顯示的所有內容,並對線條拆分進行了調整..但是,如果沒有它們被Python指向,我仍然會得到語法錯誤,所以我真的不知道代碼出現錯誤的位置。 – Gramaru

+0

請確保您的字典中的鍵值對全部用逗號分隔,我能看到的最後一件事是在下列if語句後缺少冒號: 如果回答<= len(sceneData [「Choices」]) – shahvishal