亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Python House Adventure - 如果您已經進入過一次房間,如何給出不同的輸出

Python House Adventure - 如果您已經進入過一次房間,如何給出不同的輸出

鳳凰求蠱 2021-08-05 17:44:34
所以基本上,我正在使用 python 制作一個文本冒險游戲,目標是根據線索和謎語在房子的某個地方找到獎品。當你通過告訴程序你想要向北、向南、向東或向西走而進入房子的一個房間時,它會給你一個房間的描述,但在某些情況下,當你進入一個房間時,除了你剛來自的房間,所以如果你已經進入了房子里的房間,我想讓它給你一個不同的輸出。我該怎么做?class bc:    HEADER = '\033[95m'    OKBLUE = '\033[94m'    OKGREEN = '\033[92m'    WARNING = '\033[93m'    FAIL = '\033[91m'    ENDC = '\033[0m'    BOLD = '\033[1m'    UNDERLINE = '\033[4m'inventory = []chest = "Chest"key = "Key"book = "Book"picture = "Picture"def playGame():    location = "Porch"    show_intro()    while not (location == "Exit"):        showRoom(location)        direction = str(input(bc.BOLD + bc.HEADER + "Which direction do you want to go?: \n" + bc.ENDC))        location = pickRoom(direction, location)def show_intro():    print(bc.BOLD + """Welcome to a game with no graphics so you get more FPS's!Old man Mesarosh lived here years ago before he and his wife suddenly disappeared.Before he died, it was said that he left behind a chest full of treasure.It's your job to figure out where he left it, and fast...Police drive by every 30 minutes searching for teens exploring the abandoned houseFind the clues left behind by Mesarosh and find where the treasure is hidden.Type "North", "South", "East" or "West" to decide which way to go.Good luck! \n""" + bc.ENDC)def pickRoom(direction, room):    while True:        if(direction == "quit") or (direction == "exit"):            print("Better luck next time!")            return "Exit"        elif room == "Porch":            if direction.lower() == "north":                return "Pantry"        elif room == "Pantry":            if direction.lower() == "north":                return "Kitchen"            elif direction.lower() == "east":                return "DiningRoom"        elif room == "DiningRoom":            if direction.lower() == "west":                return "Pantry"  
查看完整描述

2 回答

?
嚕嚕噠

TA貢獻1784條經驗 獲得超7個贊

當進入房間時,設置一個變量。在每個房間的 if-else 語句中檢查變量的值,如果變量顯示已更改為 youve-already-been-here 狀態,則顯示 youve-already-been-here 消息。


查看完整回答
反對 回復 2021-08-05
?
Cats萌萌

TA貢獻1805條經驗 獲得超9個贊

您需要一個在玩家進入房間后具有不同值的變量。您可以在游戲開始時初始化標志或計數器,在顯示消息之前檢查它,然后在玩家進入房間時設置它(用于標志)或增加它(用于計數器)。


查看完整回答
反對 回復 2021-08-05
  • 2 回答
  • 0 關注
  • 171 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號