私はpython 3.3.2でテキストベースのゲームを作っています.ランダムな選択の後に2つの質問が必要です.これは私のコードです:
if attack_spider == "Y":
attack = ['Miss', 'Miss', 'Miss', 'Miss', 'Hit']
from random import choice
print(choice(attack))
messages = {
"Miss": "You made the spider angry! The spider bites you do you attack it again? Y/N",
"Hit": "You killed the spider! It's fangs glow red do you pick them up? Y/N!"
}
print(messages[choice(attack)])
次のように入力すると、天気が当たったり外れたりすることに応じて、さまざまな質問ができるようになります。
spider = input()
if spider == "Y":
print("as you pick the fangs up the begin to drip red blood")
クモを怒らせることとは何の関係もありません。ヒットかミスかで異なる答えを得る方法があります。
以下の回答からコードを追加しました。
if attack_spider == "Y":
attack = choice(attack)
attack = ['Miss', 'Miss', 'Miss', 'Miss', 'Hit']
from random import choice
print (choice(attack))
messages = {
"Miss": "You made the spider angry! The spider bites you do you attack it again? Y/N",
"Hit": "You killed the spider! It's fangs glow red do you pick them up? Y/N!"
}
print(messages[choice(attack)])
spider = input()
if spider == "Y":
if attack == "Hit":
print("As you pick the fangs up the begin to drip red blood")
if attack == "Miss":
print("As you go to hit it it runs away very quickly")
if spider == "N":
if attack == "Hit":
print("As you walk forward and turn right something flies past you")
if attack == "Miss":
print("The spider begins to bite harder and you beging to See stars")
私はこのエラーが発生することを知っています:
Traceback (most recent call last):
File "C:\Users\callum\Documents\programming\maze runner.py", line 29, in <module>
attack = choice(attack)
NameError: name 'choice' is not defined