私自身の作成でゲームを試していますが、私はこの問題に遭遇しました。私は非常にインタラクティブなフィクションスタイルでゲームを作っていますが、take(sword, room)
にtake sword
〜room
とinventory
のような関数を呼び出すことはできません。 まず、ここでゲームが継続的に呼び出すために呼び出すために私が使用しているものですraw_input
:リストのraw_inputを関数に呼び出す方法
def take(item,room):
if item in tools:
if item[0] in room:
room.remove(item[0])
inventory.append(item[1])
print "taken"
else:
print item, "doesn't exist in this game"
def look(room):
place=areas[room]
for i in place:
print i
そして今:
sword=["There is a sword here", "sword"]
room=["There is a table in the corner", sword[0]]
inventory=[]
areas=[room,bedroom,living_room]
tools=[sword, shield, axe]
GameOn=True
while GameOn==True:
a=raw_input("C:\>")
a=a.lower()
if a=="look":
look()
次の機能であります
tools
は、ゲームに何が含まれているかを示すためのものです。 areas
とnoun
は、1つの部屋と1つのアイテムを持つゲームが退屈なので、リスト内に複数のアイテムがあります。noun
とareas
のすべてが、sword
またはroom
でないものは無視してください。剣が2つのリストを有する理由は、room
にはsword[0]
が現れ、inventory
にはsword[1]
が現れる。 Ex。
print inventory
"sword"
look(room)
"There is a table in the corner"
"There is a sword here"
そして、それはゲーム内でどのように見えるか:私はtake(sword, room)
は(下図参照)仕事を得ることができます
C:\>look
"There is a table in the corner"
"There is a sword here"
ので、私はそれはコードではないことを知っている:私は追加
>>>room=["There is a table in the corner, sword[0]]
>>>inventory=[]
>>>look(room)
>"There is a table in the corner"
>"There is a sword here"
>>>print inventory
>
>>>take(sword, room)
>>>look(room)
>"There is a table in the corner"
>>>print inventory
>"sword"
" >>> 'は関数の変数または呼び出しを示し、'> 'は応答を表示します。
今ではカバーされていますことを、私はtake sword
が動作するのですかどのようraw_input
の機能を誤解、あるいはそうでない場合は午前、私はraw_input
で何か間違ったことをやって、私のコードの一部を書き換えるのですか?
メインループは決してtakeを呼び出しません。それはlookと呼ばれる方法です。 raw_inputはあなたに入力を与えるだけで、それを解析するコードを書いてから、残りのプログラムの関連ビットを呼び出さなければなりません – pvg