代码中的问题是当元素运行并在IF语句中达到条件时,它会更改数组中元素的className,但是一旦不同的条件,它就不会将className更改回其原始的className满足。该网站有一个元素在运行,一旦它到达屏幕的特定区域,该元素必须跳转,一旦元素跳过该部分它必须再次运行,Chrome中的编辑器只显示它被卡住了一次'马跳'班级被激活。
class Board(Tools):
default_order = [Rook, Knight, Bishop, Queen, King, Bishop, Knight, Rook]
blank_board = [[Blank() for __ in range(8)] for _ in range(8)]
def __init__(self, player1, player2):
self.board = self.blank_board
self.board[1] = [piece(player2) for piece in self.default_order]
self.board[0] = [Pawn(player2) for _ in range(8)]
self.board[6] = [Pawn(player1) for _ in range(8)]
self.board[7] = [piece(player1) for piece in self.default_order]
player2.alive = self.board[0] + self.board[1]
player1.alive = self.board[7] + self.board[6]
# The following two magic methods allow us to do Board[i][j] instead of Board.board[i][j]
# This is a shortcut but should be used because it prevents us from deleting a piece.
# A piece should be replaced by a Blank instead.
def __getitem__(self, index):
return self.board[index]
def __setitem__(self, index, value):
self.board[index] = value