2017-09-19 94 views
-4

我想使一個基於文本的選擇你自己的冒險遊戲。我該怎麼做? (想不到一個準確的標題)(PYTHON)

在這個遊戲中,每回合有三個選項:清除,休息,並繼續你的旅程。每次選擇「繼續旅行」時,Area變量都會上移一個。如果你在同一地區清除兩次,我想讓它說「你找不到任何東西。」。但是如果我必須寫'如果Area == one和Canteen == 1: print「你找不到任何東西。」 (食堂是你在第一個區域獲得清理的物品)如果我必須爲每個選項編寫這個項目,我會感到非常沮喪。那麼如何輕鬆測試他們是否在該領域獲得了清除,並說「你什麼都找不到」。在此先感謝「

+0

考慮類,詞典,狀態變量.... – mauve

+0

谷歌‘!狀態轉換表’ 。 – Barmar

回答

0

如果你正在尋找的東西很簡單,這可以作爲一個例子:

area = 0 
inventory = [] 
area_scavenged = False 

while True: 
    print 'Area: %s\nInventory: %s' % (area, str(inventory)) 
    choice = raw_input("Choose an option: ") 
    if choice == 'rest': 
     pass 
    elif choice == 'continue': 
     area_scavenged = False 
     area += 1 
    elif choice == 'scavenge': 
     if not area_scavenged: 
      # Append to inventory the item that corresponds to the area you're in 
      inventory.append('whatever') 
      area_scavenged = True 
     else: 
      print("You couldn't find anything") 
    elif choice == 'end': 
     break 
相關問題