您好,我正在制作井字游戏游戏,但我的板子无法正常唤醒。有人能帮我吗?我正在名为repl.it 的网站上进行此工作。这是链接:https://repl.it/@JustCoding123/Help 。这个概念是您放下 X或O -s的数字是1-9 ,我使董事会得以工作,但是 X和O没有显示。多谢您度过愉快的一天。对不起,我的英语。
答案 0 :(得分:0)
一些原因导致了问题:
counter
,而不是遍历整个网格。这总是将下一个动作放在下一个单元格中,而不是在选定的单元格中。board[0] != "X" or "O"
。每个条件都将单独评估,并且任何非空字符串(如“ O”)都将被视为True。这样会更准确:board[0] != "X" and board[0] != "O"
这是更新的代码(简明):
def update_board():
pen.clear()
global turn
print(board)
for counter, cur_char in enumerate(board): #starts with 0
counter += 1 # start with 1
if counter == 1:
pen.penup()
pen.setpos(-100, 80)
pen.write(cur_char, align="center", font=("Comic Sans MS",50,"normal"))
............... same for 2-8
if counter == 9:
pen.setpos(100, -130)
pen.write(cur_char, align="center", font=("Comic Sans MS",50,"normal"))
if turn=='X': # switch turn
turn='O'
else:
turn='X'
print("Updated Board")
def pr1():
if board[0] not in ["X","O"]: # same as board[0] != "X" and board[0] != "O"
board[0] = turn
update_board()
else:
print("There are already something at space 1")
............. same for pr2-pr8
def pr9():
if board[8] not in ["X","O"]:
board[8] = turn
update_board()
else:
print("There are already something at space 9")
............