class CatcherPiece: character = "-" color = "white_on_indigo" def __init__(self, position): self.position = position class Catcher: width = 7 display = False pieces = [] name = "Player" color = "white_on_indigo" def __init__(self, position): self.position = position def play_turn(self, game): if not self.pieces: self.create_pieces(game) def handle_keystroke(self, keystroke, game): x, y = self.position width, height = game.board_size if keystroke.name == "KEY_LEFT": if 0 < x: self.position = (x-1, y) self.update_piece_positions() if keystroke.name == "KEY_RIGHT": if x + self.width < width: self.position = (x+1, y) self.update_piece_positions() def create_pieces(self, game): x, y = self.position self.pieces = [] for i in range(self.width): piece = CatcherPiece((x + i, y)) self.pieces.append(piece) game.add_agent(piece) def update_piece_positions(self): x, y = self.position for i, piece in enumerate(self.pieces): piece.position = (x + i, y) def can_move(self, position, game): on_board = game.on_board(position) empty = game.is_empty(position)