【发布时间】:2021-10-06 21:22:24
【问题描述】:
我想在第二个玩家使用 %tttjoin 加入游戏时让游戏开始。我尝试了我的想法,但我真的不知道该怎么做,所以我将我的 Player2 设置为 True。而当有人使用命令 %tttjoin p2 时设置为 False。然后使用“如果 p2 为 False:”行,游戏开始。但是这个功能不起作用,我不知道我的想法是如何工作的......我希望有人知道该怎么做......而且我还没有收到任何错误。游戏运行良好,没有任何错误。当我写 %ttt 时,机器人会发送消息,但是当有人加入 %tttjoin 时,没有任何反应。我的错误应该是“如果 p2 为 False”这行,但我不知道我必须更改什么。
async def tttjoin(self, ctx):
global p2
global p2name
p2 = ctx.author
p2 = False
p2name = ctx.author.name
@commands.command(aliases=["tiktaktoe", "ttt"])
async def tictactoe(self, ctx):
global player1
global player2
global p2
global turn
global gameOver
global count
player1 = ctx.author
player2 = p2
p1name = ctx.author.name
msg = await ctx.send(f"<%tttjoin> um mitzuspielen. \n Player 1: {p1name} Player 2: / ")
if p2 is False:
await msg.edit(f"Player 1: {p1name} Player 2: {p2name} ")
if gameOver:
global board
board = [":white_large_square:", ":white_large_square:", ":white_large_square:",
":white_large_square:", ":white_large_square:", ":white_large_square:",
":white_large_square:", ":white_large_square:", ":white_large_square:"]
turn = ""
gameOver = False
count = 0
line = ""
for x in range(len(board)):
if x == 2 or x == 5 or x == 8:
line += " " + board[x]
await ctx.send(line)
line = ""
else:
line += " " + board[x]
num = random.randint(1, 2)
if num == 1:
turn = player1
await ctx.send(f"{player1.mention} fängt an!")
elif num == 2:
turn = player2
await ctx.send(f"{player2.mention} fängt an!")
else:
await ctx.send("Es wird bereits gespielt! Bitte wartet bis das Spiel fertig ist!")
@commands.command()
async def place(self, ctx, pos: int = None):
global turn
global player1
global player2
global board
global count
if pos is None:
await ctx.send("Du musst eine Position wählen!")
if not gameOver:
mark = ""
if turn == ctx.author:
if turn == player1:
mark = ":regional_indicator_x:"
elif turn == player2:
mark = ":o2:"
if 0 < pos < 10:
if board[pos - 1] == ":white_large_square:":
board[pos -1] = mark
count += 1
line = ""
for x in range(len(board)):
pass
checkWinner(winningC, mark)
if gameOver:
await ctx.send(f"{mark} hat gewonnen!")
elif count >= 9:
await ctx.send("Unentschieden")
if turn == player1:
turn = player2
elif turn == player2:
turn = player1
@commands.command()
@commands.has_role("Admin")
async def tttquit(self, ctx):
global gameOver
global p2
p2 = True
gameOver = True
await ctx.send("Das Spiel wurde beendet!")
【问题讨论】:
标签: python discord.py command