拨开荷叶行,寻梦已然成。仙女莲花里,翩翩白鹭情。
IMG-LOGO
主页 文章列表 如何在python中的不和谐问答游戏中为特定玩家增加价值(1分)?

如何在python中的不和谐问答游戏中为特定玩家增加价值(1分)?

白鹭 - 2022-02-14 1968 0 0

在这里,当玩家输入 '!start' 时,他将被添加到记分板字典中。

if message.content.startswith('!start'):
            await message.channel.send("The game starts")
            self.scoreboard = {}

***在这里,一旦他输入“!play”,机器人就会给出所有玩家的串列( message.author.name ),并将他的分数设为 0 以 0 分开始测验***

if message.content.startswith('!play'):
    txt = 'adding player: '   message.author.name
    await message.channel.send(txt)
    players.append(message.author.name)

    txt = 'current users: '   ' '.join(map(str, players))
    await message.channel.send(txt)
    self.scoreboard[message.author.name] = 0

在机器人提出问题并且玩家正确回答之后,我希望正确的玩家获得 1 分。如何将字典中的值 1 添加到正确的播放器?

    if message.content == '!score':
        score = str(self.scoreboard)
        print(score)
        await message.channel.send(self.scoreboard)
        return

    if message.content == self.answer:
        await message.channel.send('Good answer')

uj5u.com热心网友回复:

您可以检查讯息的作者是否在记分板字典中,然后使用 Python 中的加法运算子增加分数计数。

if message.author.name in self.scoreboard:
    self.scoreboard[message.author.name]  = 1
标签:

0 评论

发表评论

您的电子邮件地址不会被公开。 必填的字段已做标记 *