簡體   English   中英

基於Python文本的游戲縮進

[英]Python text based game indentation

我的縮進問題從我的代碼的第40行旅館開始。 如果有人能告訴我如何解決它,我將非常感激

print "You wake up in a dark room, There is a box of matches in your pocket. What do you do?"
print "#1 Light a match #2 Do nothing"
door = raw_input(">")
if door == "1":
    print "You light a match, In the room there is an axe and a door without a handle. What do you do?"
    print "#1 Grab the axe #2 Punch the door #3 Do nothing"
    axe = raw_input(">")
    if axe == "1":
        print "You grab the axe, What do you do?"
        print "#1 Knock down the door #2 Do nothing"
        end = raw_input(">")
        if end == "1":
            print "You are free! You Win!"
        elif end == "2":
            print"You wait and then the axe slips out of your hand, decapacitating you. You die"
        else:
            print "Ivalid input. Game End"   
    elif axe == "2":
        print"Ow, that hurt. What to do now?"
        print "#1 Grab the axe #2 do nothing"
        chop = raw_input(">")
        if chop  == "1":
            print" You grab the axe, What do you do?"
            print "#1 Knock down the door #2 Do nothing"
            end = raw_input(">")
            if end == "1":
                print "You are free! You Win!"
            elif end == "2":
                print"You wait and then the axe slips out of your hand, decapacitating you. You die"      
            else:
                print "Ivalid input. Game End"    
        elif chop == "2":
            print "You go insane from waiting. Game Over"     
        else:
            print "Ivalid input. Game End"       
    elif axe == "3":
        print "You go insane from waiting. Game Over"    
    else:
        print "Ivalid input. Game End"  
elif door == "2":
    print"You wait in the darkness until something grabs your arm. Whate do you do?"
    print"#1 Use your ninja skills to escape the clutches of whatever is grabbing you. #2 Flail your arms around"
    flail = raw_input('>')
    if flail == "1":
        print"You escape from the things grasp. What do you do now?"
        print"#Light a match. #2 Throw a punch at the whatever was attacking you"
        punch = raw_input('>')
        if punch == "1":
            print"You light a match only to see a hideous monster in front of you. What do you do now"
            print"#1 Throw the match at the monster #2 Punch the monster"
            match = raw_input('>')
            if match == "1":
                print"You throw a match at the monster. The monster eats the match then turns dissapears. What do you do"
                print"#1 Panic #2 Look around"
                panic = raw_input('>')
                if panic == "1":
                    print"You panic then have a heart attack. You die. Game over"
                elif panic == "2":
                    print"You look around, it appears the monster is gone.In the room there is an axe and a door without a handle. What do you do?"
                    print "#1 Grab the axe #2 Punch the door #3 Do nothing"
                    axe = raw_input(">")
                    if axe == "1":
                        print "You grab the axe, What do you do?"
                        print "#1 Knock down the door #2 Do nothing"
                        end = raw_input(">")
                        if end == "1":
                            print "You are free! You Win!"
                        elif end == "2":
                            print"You wait and then the axe slips out of your hand, decapacitating you. You die"
                        else:
                            print "Ivalid input. Game End"   
                    elif axe == "2":
                        print"Ow, that hurt. What to do now?"
                        print "#1 Grab the axe #2 do nothing"
                        chop = raw_input(">")
                        if chop  == "1":
                            print" You grab the axe, What do you do?"
                            print "#1 Knock down the door #2 Do nothing"
                            end = raw_input(">")
                            if end == "1":
                                print "You are free! You Win!"
                            elif end == "2":
                                print"You wait and then the axe slips out of your hand, decapacitating you. You die"      
                            else:
                                print "Ivalid input. Game End"    
                        elif chop == "2":
                            print "You go insane from waiting. Game Over"     
                        else:
                            print "Ivalid input. Game End"       
                    elif axe == "3":
                        print "You go insane from waiting. Game Over"    
                    else:
                        print "Ivalid input. Game End"      
                else:
                    print"Invalid Input. Game end"
            else:
                print"Invalid Input. Game end"        
        elif match == "2":
            print"You punch the hideous monster in its face and it dies. You look around and you see a axe and a door without a handle. What do you do?"
            print "#1 Grab the axe #2 Punch the door #3 Do nothing"
            axe = raw_input(">")
            if axe == "1":
                print "You grab the axe, What do you do?"
                print "#1 Knock down the door #2 Do nothing"
                end = raw_input(">")
                if end == "1":
                    print "You are free! You Win!"
                elif end == "2":
                    print"You wait and then the axe slips out of your hand, decapacitating you. You die"
                else:
                    print "Ivalid input. Game End"   
            elif axe == "2":
                print"Ow, that hurt. What to do now?"
                print "#1 Grab the axe #2 do nothing"
                chop = raw_input(">")
                if chop  == "1":
                    print" You grab the axe, What do you do?"
                    print "#1 Knock down the door #2 Do nothing"
                    end = raw_input(">")
                    if end == "1":
                        print "You are free! You Win!"
                    elif end == "2":
                        print"You wait and then the axe slips out of your hand, decapacitating you. You die"      
                    else:
                        print "Ivalid input. Game End"    
                elif chop == "2":
                    print "You go insane from waiting. Game Over"     
                    else:
                        print "Ivalid input. Game End"       
            elif axe == "3":
                print "You go insane from waiting. Game Over"    
            else:
                print "Ivalid input. Game End"      
        else:
            print"Invalid Input. Game end"        
    else:
        print"Invalid Input. Game end"        
elif punch == "2":
    print"The monster eats your hand whole and you bleed to death. Game Over"
        else:
            print"Invalid Input. Game end"
    elif flail == "2":
        print"You flail your arms and then you get killed by the mmonster. Nice job. You lose. Game Over"
    else:
        print"Invalid input. Game end."
else:
    print"Invalid Input. Game end."      

我看到了,我看到了!

elif punch == "2": # you can't `elif punch` here, because you haven't defined punch (maybe)
    print"The monster eats your hand whole and you bleed to death. Game Over"
        else: # else what? there's nothing here to "else!"
            print"Invalid Input. Game end"

請注意,這種游戲最好使用“有限狀態機”來實現 ,這可能會超出您的能力范圍。 只是想提一下,因為您當前有意大利面條代碼,而我不希望您認為“這就是代碼的外觀”,而不應該這樣。 但是,在您當前的知識水平上,沒有更好的方法可以實現:)

print "You wake up in a dark room, There is a box of matches in your pocket. What do you do?"
print "#1 Light a match #2 Do nothing"
door = raw_input(">")
if door == "1":
    print "You light a match, In the room there is an axe and a door without a handle. What do you do?"
    print "#1 Grab the axe #2 Punch the door #3 Do nothing"
    axe = raw_input(">")
    if axe == "1":
        print "You grab the axe, What do you do?"
        print "#1 Knock down the door #2 Do nothing"
        end = raw_input(">")
        if end == "1":
            print "You are free! You Win!"
        elif end == "2":
            print"You wait and then the axe slips out of your hand, decapacitating you. You die"
        else:
            print "Ivalid input. Game End"   
    elif axe == "2":
        print"Ow, that hurt. What to do now?"
        print "#1 Grab the axe #2 do nothing"
        chop = raw_input(">")
        if chop  == "1":
            print" You grab the axe, What do you do?"
            print "#1 Knock down the door #2 Do nothing"
            end = raw_input(">")
            if end == "1":
                print "You are free! You Win!"
            elif end == "2":
                print"You wait and then the axe slips out of your hand, decapacitating you. You die"      
            else:
                print "Ivalid input. Game End"    
        elif chop == "2":
            print "You go insane from waiting. Game Over"     
        else:
            print "Ivalid input. Game End"       
    elif axe == "3":
        print "You go insane from waiting. Game Over"    
    else:
        print "Ivalid input. Game End"  
elif door == "2":
    print"You wait in the darkness until something grabs your arm. Whate do you do?"
    print"#1 Use your ninja skills to escape the clutches of whatever is grabbing you. #2 Flail your arms around"
    flail = raw_input('>')
    if flail == "1":
        print"You escape from the things grasp. What do you do now?"
        print"#Light a match. #2 Throw a punch at the whatever was attacking you"
        punch = raw_input('>')
        if punch == "1":
            print"You light a match only to see a hideous monster in front of you. What do you do now"
            print"#1 Throw the match at the monster #2 Punch the monster"
            match = raw_input('>')
            if match == "1":
                print"You throw a match at the monster. The monster eats the match then turns dissapears. What do you do"
                print"#1 Panic #2 Look around"
                panic = raw_input('>')
                if panic == "1":
                    print"You panic then have a heart attack. You die. Game over"
                elif panic == "2":
                    print"You look around, it appears the monster is gone.In the room there is an axe and a door without a handle. What do you do?"
                    print "#1 Grab the axe #2 Punch the door #3 Do nothing"
                    axe = raw_input(">")
                    if axe == "1":
                        print "You grab the axe, What do you do?"
                        print "#1 Knock down the door #2 Do nothing"
                        end = raw_input(">")
                        if end == "1":
                            print "You are free! You Win!"
                        elif end == "2":
                            print"You wait and then the axe slips out of your hand, decapacitating you. You die"
                        else:
                            print "Ivalid input. Game End"   
                    elif axe == "2":
                        print"Ow, that hurt. What to do now?"
                        print "#1 Grab the axe #2 do nothing"
                        chop = raw_input(">")
                        if chop  == "1":
                            print" You grab the axe, What do you do?"
                            print "#1 Knock down the door #2 Do nothing"
                            end = raw_input(">")
                            if end == "1":
                                print "You are free! You Win!"
                            elif end == "2":
                                print"You wait and then the axe slips out of your hand, decapacitating you. You die"      
                            else:
                                print "Ivalid input. Game End"    
                        elif chop == "2":
                            print "You go insane from waiting. Game Over"     
                        else:
                            print "Ivalid input. Game End"       
                    elif axe == "3":
                        print "You go insane from waiting. Game Over"    
                    else:
                        print "Ivalid input. Game End"      
                else:
                    print"Invalid Input. Game end"
            else:
                print"Invalid Input. Game end"        
        elif match == "2":
            print"You punch the hideous monster in its face and it dies. You look around and you see a axe and a door without a handle. What do you do?"
            print "#1 Grab the axe #2 Punch the door #3 Do nothing"
            axe = raw_input(">")
            if axe == "1":
                print "You grab the axe, What do you do?"
                print "#1 Knock down the door #2 Do nothing"
                end = raw_input(">")
                if end == "1":
                    print "You are free! You Win!"
                elif end == "2":
                    print"You wait and then the axe slips out of your hand, decapacitating you. You die"
                else:
                    print "Ivalid input. Game End"   
            elif axe == "2":
                print"Ow, that hurt. What to do now?"
                print "#1 Grab the axe #2 do nothing"
                chop = raw_input(">")
                if chop  == "1":
                    print" You grab the axe, What do you do?"
                    print "#1 Knock down the door #2 Do nothing"
                    end = raw_input(">")
                    if end == "1":
                        print "You are free! You Win!"
                    elif end == "2":
                        print"You wait and then the axe slips out of your hand, decapacitating you. You die"      
                    else:
                        print "Ivalid input. Game End"    
                elif chop == "2":
                    print "You go insane from waiting. Game Over"     
                    else:
                        print "Ivalid input. Game End"       
            elif axe == "3":
                print "You go insane from waiting. Game Over"    
            else:
                print "Ivalid input. Game End"      
        else:
            print"Invalid Input. Game end"        
    else:
        print"Invalid Input. Game end"        
elif punch == "2":
    print"The monster eats your hand whole and you bleed to death. Game Over"
        else:
            print"Invalid Input. Game end"
    elif flail == "2":
        print"You flail your arms and then you get killed by the mmonster. Nice job. You lose. Game Over"
    else:
        print"Invalid input. Game end."
else:
    print"Invalid Input. Game end."   

需要括號用於新版本的python

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM