# Define piece class class Piece: def __init__(self, row, col, color): self.row = row self.col = col self.color = color self.king = False
# Game loop selected_piece = None while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.MOUSEBUTTONDOWN: row = event.pos[1] // SQUARE_SIZE col = event.pos[0] // SQUARE_SIZE if selected_piece: if board[row][col] == 0: board[row][col] = board[selected_piece[0]][selected_piece[1]] board[selected_piece[0]][selected_piece[1]] = 0 board[row][col].move(row, col) selected_piece = None else: selected_piece = None else: if board[row][col] != 0: selected_piece = (row, col)
# Initialize Pygame pygame.init()
# Create game board board = [] for row in range(ROWS): board_row = [] for col in range(COLS): if (row + col) % 2 == 1: if row < 3: board_row.append(Piece(row, col, RED)) elif row > 4: board_row.append(Piece(row, col, (0, 0, 255))) else: board_row.append(0) else: board_row.append(0) board.append(board_row)
# Define colors WHITE = (255, 255, 255) BLACK = (0, 0, 0) RED = (255, 0, 0) checker 2 player game unblocked
def move(self, row, col): self.row = row self.col = col
# Set up display screen = pygame.display.set_mode((BOARD_SIZE, BOARD_SIZE)) # Define piece class class Piece: def __init__(self,
# Draw game board screen.fill(WHITE) for row in range(ROWS): for col in range(COLS): if (row + col) % 2 == 1: pygame.draw.rect(screen, BLACK, (col * SQUARE_SIZE, row * SQUARE_SIZE, SQUARE_SIZE, SQUARE_SIZE)) if board[row][col] != 0: color = board[row][col].color pygame.draw.circle(screen, color, (col * SQUARE_SIZE + SQUARE_SIZE // 2, row * SQUARE_SIZE + SQUARE_SIZE // 2), SQUARE_SIZE // 2 - 10)