我正在創造一個文本RPG的靈感來自舊的文字冒險,玩家輸入英文命令;如「拿起劍」等。 我已經建立了一個簡單的;輸入'A'來做到這一點,並輸入'B'來做到這一點,但我想擴大我的系統以獲得更多的自由。 我需要創建一個系統;當玩家鍵入一個命令時,程序挑選出關鍵詞。 我認爲這可以通過'in'命令實現。 這裏是我的代碼:英文命令[文字RPG] - 蟒蛇
print "What would you like to do??"
input_loop_sleep = str('')
choice_sleep = raw_input(str('>>>'))
loop_sleep = False
table_time = False
bed_time = False
error_time = False
while loop_sleep == False:
if str('sleep') in choice_sleep or str('bed') in choice_sleep or str('goodnight') in choice_sleep or str('Sleep') in choice_sleep or str('tired') in choice_sleep:
while bed_time == False:
print "you decide to go back to sleep"
time.sleep(1)
print "..."
time.sleep(1)
print ""
time.sleep(1)
print "darkness"
time.sleep(1)
print ""
print "you wake up..."
time.sleep(1)
print "it is now 9:15am"
time == int(9.15)
time.sleep(1)
print "You are standing in your room, slightly more refreshed."
time.sleep(1)
print "there is a table with some things on it, stairs, and a wardrobe... with the doors wide open..."
time.sleep(1)
print "that's strange... you swear that they were shut when you went to sleep..."
break
else:
bed_time == True
break
bed_loop_choice = raw_input('>>>')
elif str('bedside') in choice_sleep or str('table') in str(choice_sleep):
while table_time == False:
print "You rub your eyes and pick up some belongings from a"
print "bedside table."
time.sleep(1)
print "Map added!"
time.sleep(1)
print "100 gold added!"
time.sleep(1)
print "Leather Bag added!"
cash == int(100)
time.sleep(1)
Map == str('map of', str(province))
Inventory == [str(Map)]
container == str('leather bag')
print "your", str(container), str("contains a"), str(Map), str('and'), str(cash)
break
else:
table_time == True
break
else:
print "invalid command!"
當我運行的代碼
,無論我在裏面輸入的內容總是與「睡眠」選項進入。 我可能只是犯了一些簡單的錯誤! 你能幫我解決我做錯了什麼,以及我如何解決它。
下載不公開。請儘量讓您的問題自成一體。 –
請詳細描述您的問題,並在此發佈您的相關代碼。 –
修復了問題 – Dannyboy8899