所以,我试图做一个二十一点游戏。一个非常简单的,如果我可以补充。使功能睡眠,直到完成另一个功能
我的代码目前看起来是这样的:
def cmd_blackjack(message):
playblackjack(message, player=True)
def dealcard():
card = random.randrange(1, 11)
return card
def dealhand(message, player=False, dealer=False):
card1 = dealcard()
card2 = dealcard()
if player:
client.send_message(message.channel,
'BLACKJACK: Your cards: %s and %s \n Type !hitme for more cards or !stay to stay' % (card1, card2))
if dealer:
client.send_message(message.channel,
"BLACKJACK: Dealer's cards: %s %s" % (card1, card2))
return card, card2
def playblackjack(message, player=False, dealer=False):
dealhand(player)
而这差不多就是我试图archieve:
def playblackjack(message, player=False, dealer=False):
dealhand(player)
// This is when the player has to input !hitme to get more cards
if not playerhastypedhitme in 300 secs:
return
dealhand(player=False, dealer=True)
// code continues
所以基本上,我需要找出一个(非例如,我知道我可以通过列表来完成这项工作),以使该功能等待用户输入。就像创建另一个函数一样,向这个函数发送'OK,continue'消息。
我知道这可能已经前已问,这只是在搜索方面很难描述我要完成
http://stackoverflow.com/questions/1335507/keyboard-input-with-timeout-in-python – technicalbloke
“_I知道我可以列出这样做,对example_” 。你能告诉我们你是如何用列表完成的吗?这可能是一个很好的起点。 – Kevin
我没有尝试在这个特定的东西上使用列表,但我在之前的编码考察中使用过它们,当时我更加爱好业余时间。基本上,一个功能完成后,它会附加一个数字列表,然后另一个函数检查该列表是否有一个数字.. 现在,当我想到它,我不知道我会在这里使用它,嘿。 – user3553653