私はZed Shawの「Pythonを学びましょう」のハード・ウェイを練習しています。私は単語を印刷する韻を踏むゲームを作りたいと思っていました。プレイヤーは5秒間単語を推測する言葉を推測しました。タイマーを同時にPythonで実行する方法
タイマーなしでゲームを始めることができました。しかし、私はタイマーをゲームと同時に実行させる方法を理解することはできません。以下のコードされています
#libraries
libs = [about, cake, chart, score]
#points
p = 0
#timer
class countdown(object):
def __init__(self, timer):
self.timer = timer
while timer != 0:
print "timer: %i" % timer
sleep(1)
timer -= 1
else:
exit("You ran out of time!")
class engine(object):
# randomly select a library
i = randint(0, len(libs)-1)
randlib = libs[i].words.split(' ')
rhymeword = sample(randlib, 1)
print rhymeword
guess = raw_input("> ")
while guess not in randlib:
print rhymeword
guess = raw_input("> ")
else:
# to reset the timer
timer = 5
# points assignment
if guess in libs[i].onesyl.split(' '):
p += 1
print "Points: %s" % p
elif guess in libs[i].twosyl.split(' '):
p += 2
print "Points: %s" % p
elif guess in libs[i].threesyl.split(' '):
p += + 3
print "Points: %s" % p
t = countdown(5)
e = engine()
t.start()
e.start()
私がやりたい何かは、ユーザーが推測して、正しい答えが入力されたら、タイマーの再起動を持ってしようとしながら、タイマーがカウントダウンを持っています。
私はPythonのドキュメントでマルチプロセッシングを調べましたが、その作業をどうするかはわかりませんでした。あなたは
私はこれが大体だと思い言ったことすべてを願っていますどのように見て文句を言わない
これはすごい人です、ありがとうございます。 –