大家好,目前卡在如何讓遊戲輸了或玩完五次後,詢問玩家意願
若回答yes便可以重新再玩。以下是我的程式碼,在此謝謝python的高手們
import time
print('這是一個冒險的遊戲,你將闖過五個關卡,')
print('每個關卡,你要報上通關密語。')
def initiate():
print('報錯了,你會被吃掉;')
print('報對了,你可以往下闖。')
print('闖過五關,你會得到一個驚喜….' )
time.sleep(3)
print('我們開始。')
time.sleep(3)
print('現在你進入了第一關….. 這關的密語是水果….. 請你選擇一個門…. 試試
運氣吧….. ')
def password():
print("恭禧!!你過了這關!\n 下一關")
print('現在你進入了第二關….. 這關的密語交通工具….. 請你選擇一個門…
. 試試運氣吧….. ')
def password0():
print("恭禧!!你過了這關!\n 下一關")
print('現在你進入了第三關….. 這關的密語是親屬關係….. 請你選擇一個門
…. 試試運氣吧….. ')
def password1():
print("恭禧!!你過了這關!\n 下一關")
print('現在你進入了第四關….. 這關的密語是動物….. 請你選擇一個門….
試試運氣吧….. ')
def password2():
print("恭禧!!你過了這關!\n 下一關")
print('現在你進入了第五關….. 這關的密語是成語….. 請你選擇一個門….
試試運氣吧….. ')
def password3():
print("恭禧!!你過了這關!\n 下一關")
initiate()
for i in range (5):
given= int (input("你選的門(1-5)是:"))
given= str(input("你輸入的通關密語是:"))
if given=="西瓜":
password()
elif given=="汽車":
password0()
elif given=="父子":
password1()
elif given=="大象":
password2()
elif given=="七上八下":
password3()
else:
print("啊~ 密語錯誤!怪獸來吃你了…." )
playAgain = 'yes'
while playAgain == 'yes' or playAgain == 'y':
playAgain = input('Do you want to play again? (yes or no)\n')