轮流玩 Discord.py 游戏
Taking Turns with a Discord.py game
我正在尝试做的事情: 我正在尝试使用 discord.py 创建回合制格斗游戏。当两个玩家的生命值都大于 0 时,消息作者和提到的用户将轮流使用拳击、治疗或投降(不言自明)。
问题: 当涉及到轮流切换时,我不确定从哪里开始。下面我发布了我用于消息作者的全部代码,但我似乎无法找到一种方法让消息作者轮到下一个回合,反之亦然。
@client.command()
async def battle(ctx, user: discord.Member):
aut = 5
ops = 5
user = user.mention
cmam = ctx.message.author.mention
if user == cmam:
await ctx.send(f"You can't fight yourself {cmam} <:BlobWuh:761383059349438464>")
else:
await ctx.send(f'{cmam} vs {user}, who will win?')
while aut > 0 and ops > 0:
await ctx.send(f'{cmam}: `Punch, Heal, Surrender`')
def check(m):
return m.content == 'punch' or m.content == 'heal' or m.content == 'surrender' and m.author == ctx.message.author
response = await client.wait_for('message', check = check)
if "punch" in response.content.lower():
if ops > 0:
dmg = [0, 1, 2]
dmg = (random.choice(dmg))
ops = ops - dmg
await ctx.send(f"{user} is down to **{ops}** health")
if ops <= 0:
await ctx.send(f"**{cmam} has won the battle**")
break
elif ops <= 0:
await ctx.send(f"**{cmam} has won the battle**")
break
if "heal" in response.content.lower():
if aut >= 5:
await ctx.send(f"{cmam} already has **{aut}** health, they lose a turn")
else:
aut = aut + 1
await ctx.send(f"{cmam} now has **{aut}** health")
if "surrender" in response.content.lower():
await ctx.send(f"{cmam} has surrendered with **{aut}** health. {user} has claimed victory with **{ops}** health remaining")
aut = aut - 20
ops = ops - 20
break
好的,这是给再次偶然发现这个的任何人的,它大部分是相同的代码,但有一个 turn 变量来存储当前的回合。 (感谢@Ethan M-H 的建议)
@client.command()
async def test(ctx, user: discord.Member):
turn = 0 #adding a turn variable for turn taking
aut = 5
ops = 5
user = user.mention
cmam = ctx.message.author.mention
if user == cmam:
await ctx.send(f"You can't fight yourself {cmam}")
else:
await ctx.send(f"{cmam} vs {user}, who will win?")
while aut > 0 and ops > 0:
if turn == 0:
await ctx.send(f"{cmam}: `test`")
def check(m):
return m.content == "test" and m.author == ctx.message.author
response = await client.wait_for('message', check = check)
if "test" in response.content.lower() and turn == 0:#turn == 0 is here since it doesn't work sometimes
await ctx.send("a nice test")
turn = turn + 1
elif turn == 1:
await ctx.send(f"{user}: `test`")
def check(o):
return o.content == "test" and o.author == discord.Member
response = await client.wait_for('message', check = check)
if "test" in response.content.lower() and turn == 1:#turn == 1 is here since (elif turn == 1) doesn't work sometimes
await ctx.send("the test is strong with this one")
turn = turn - 1
我正在尝试做的事情: 我正在尝试使用 discord.py 创建回合制格斗游戏。当两个玩家的生命值都大于 0 时,消息作者和提到的用户将轮流使用拳击、治疗或投降(不言自明)。
问题: 当涉及到轮流切换时,我不确定从哪里开始。下面我发布了我用于消息作者的全部代码,但我似乎无法找到一种方法让消息作者轮到下一个回合,反之亦然。
@client.command()
async def battle(ctx, user: discord.Member):
aut = 5
ops = 5
user = user.mention
cmam = ctx.message.author.mention
if user == cmam:
await ctx.send(f"You can't fight yourself {cmam} <:BlobWuh:761383059349438464>")
else:
await ctx.send(f'{cmam} vs {user}, who will win?')
while aut > 0 and ops > 0:
await ctx.send(f'{cmam}: `Punch, Heal, Surrender`')
def check(m):
return m.content == 'punch' or m.content == 'heal' or m.content == 'surrender' and m.author == ctx.message.author
response = await client.wait_for('message', check = check)
if "punch" in response.content.lower():
if ops > 0:
dmg = [0, 1, 2]
dmg = (random.choice(dmg))
ops = ops - dmg
await ctx.send(f"{user} is down to **{ops}** health")
if ops <= 0:
await ctx.send(f"**{cmam} has won the battle**")
break
elif ops <= 0:
await ctx.send(f"**{cmam} has won the battle**")
break
if "heal" in response.content.lower():
if aut >= 5:
await ctx.send(f"{cmam} already has **{aut}** health, they lose a turn")
else:
aut = aut + 1
await ctx.send(f"{cmam} now has **{aut}** health")
if "surrender" in response.content.lower():
await ctx.send(f"{cmam} has surrendered with **{aut}** health. {user} has claimed victory with **{ops}** health remaining")
aut = aut - 20
ops = ops - 20
break
好的,这是给再次偶然发现这个的任何人的,它大部分是相同的代码,但有一个 turn 变量来存储当前的回合。 (感谢@Ethan M-H 的建议)
@client.command()
async def test(ctx, user: discord.Member):
turn = 0 #adding a turn variable for turn taking
aut = 5
ops = 5
user = user.mention
cmam = ctx.message.author.mention
if user == cmam:
await ctx.send(f"You can't fight yourself {cmam}")
else:
await ctx.send(f"{cmam} vs {user}, who will win?")
while aut > 0 and ops > 0:
if turn == 0:
await ctx.send(f"{cmam}: `test`")
def check(m):
return m.content == "test" and m.author == ctx.message.author
response = await client.wait_for('message', check = check)
if "test" in response.content.lower() and turn == 0:#turn == 0 is here since it doesn't work sometimes
await ctx.send("a nice test")
turn = turn + 1
elif turn == 1:
await ctx.send(f"{user}: `test`")
def check(o):
return o.content == "test" and o.author == discord.Member
response = await client.wait_for('message', check = check)
if "test" in response.content.lower() and turn == 1:#turn == 1 is here since (elif turn == 1) doesn't work sometimes
await ctx.send("the test is strong with this one")
turn = turn - 1