使一个函数休眠,直到另一个函数完成

2024-05-18 12:03:58 发布

您现在位置:Python中文网/ 问答频道 /正文

所以,我想做一个21点游戏。一个非常简单的,如果我可以补充的话。你知道吗

我的代码当前如下所示:

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)

而这正是我想要证明的:

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

所以基本上,我需要找出一种(非迟钝的,我知道我可以用列表来实现)方法,让函数等待用户输入。例如,使另一个函数向该函数发送“确定,继续”消息。你知道吗

我知道以前有人问过这个问题,只是很难用搜索词来描述我想要实现的目标


Tags: tofalsemessagereturnifdefcardcards
2条回答

你不需要睡觉。如果我理解正确,您只需要等待用户输入。你知道吗

Python的input()函数正好为您做到了这一点。你知道吗

中有一个内置函数不和谐.py那救了我。最终结果如下: https://github.com/Thomaxius/lemon_bot_discord

相关问题 更多 >