1.ループから抜け出すために使用break
していますが、これが発生しない限り、プログラムを継続させる方法がわかりません。入力するだけでwhile:
は無効です (または、プログラムが教えてくれます)。ユーザーが空の文字列を入力しても、ゲームを続行したいと考えています。
2.コードが必要になるたびにコードを再入力する必要がないようにする方法はありますか? プログラムが吐き出すための応答がたくさんありますが、これは何度も使用する必要があります。
if action[0]=='go':
print("You're supposed to go to David!")
elif action[0]=='look':
print("You can't see that")
elif action[0]=='take':
print("You don't see the point in taking that.")
else:
print("I don't recognise that command")
action
プレーヤーの入力からのリストはどこにありますか。それとも、毎回もう一度入力する必要がありますか?
上記を実行する関数を定義する方法がわかりません。また、それが私がすべきことかどうかさえわかりません。
3.私が使用しているいくつかのストーリーの説明は非常に長い文章であり、プレイヤーが横にスクロールしすぎないようにしたい. しかし、入力を節約するために、それらを変数として定義したいと思います。これを回避する方法はありますか。または、毎回入力する必要がありますか
print(“““a string here”””)
4.文字列が「look」で始まり、「floor」または「mess」または「rubbish」が含まれている場合、特定の出力を出力したい。これは私が現在持っているものです:
if action[0]=='look':
if 'floor' in action or 'rubbish' in action or 'trash' or 'mess' in action:
print('onec')
elif 'screen' in action or 'computer' in action or 'monitor' in action:
print('oned')
elif 'around' in action or 'room' in action or 'apartment' in action:
print('onee')
elif 'david' in action or 'tyler' in action or 'boy' in action or 'brat' in action or 'youth' in action:
print('onef')
break
else:
print("You can't see that")
'onec'
で始まるすべての入力に対して出力され'look'
ます。