【发布时间】:2018-08-10 02:19:56
【问题描述】:
你们能在 Jupyter note 中运行我的代码,请告诉我它有什么问题吗?我似乎不明白为什么它不能正常工作。每次我从库存中选择和项目时,它都会让我结束游戏。我希望无论何时龙是否被击败以及打印语句到下一个房间时都打印代码。
import sys
print("""Hello! Type 1 to Continue""")
#ice sword - a
#fire sword - b
#electric sword - c
inv = {'a':'Ice Sword'}
#function to display the inventory
def display():
print("type 1 to display your inventory\n")
n = input()
if int(n)==1:
for i in inv:
print(i +" - "+ inv[i])
sequence = ['c','a','b']
for i in range(0,4):
#room-1 Fire dragon - ice sword win-firesword
if i==0:
print("You are in room-1 a FIRE DRAGON appears\n")
display()
print("choose your Item")
x = input()
if x == 'a' and i==0:
print("The fire dragon is defeated proceed to next room\n")
print("You have acquired a new Item 'Fire Sword'\n")
inv['b'] = 'Fire Sword'
else:
print("---GAME OVER---")
#room-2 Electric dragon - ice sword win-electric sword
if i==1:
print("You are in room-2 a ELECTRIC DRAGON appears\n")
display()
print("choose your Item")
x = input()
if x=='a' and i==1:
print("The electric dragon is defeated you proceed next room\n")
print("You have acquired a new Item 'Electric Sword'\n")
inv['c'] = 'Electric Sword'
else:
print("---GAME OVER---")
#room-3 Ice dragon - fire sword win-key
if i==2:
print("You are in room-3 a Ice dragon appears\n")
display()
print("choose your Item")
x = input()
if x=='b' and i==2:
print("The Ice dragon is defeated you __ next room\n")
print("You have acquired a new Item 'Key'\n")
inv['d'] = 'Key'
else:
print("---GAME OVER---")
#room-4 Dark beast Ganon specific order ([c a b])
if i==3:
print("Use the key you won to enter the last room\n")
display()
print("choose your Item")
x = input()
if x=='d' and i==3:
print("The Final boss DARK BEAST GANON appears\n")
else:
print("---GAME OVER---")
#used the key and the boss appears
print("to defeat this boss you need to use a specific combination of the swords\n")
print("Enter the sequence one by one and press enter after every value")
a = []
for i in range(0,3):
x = input()
a.append(x)
if a == sequence:
print("Congratulation you have completed the game")
#sys.exit()
else:
print("---GAME OVER---")
【问题讨论】: