From fa0e805e3a7997dfdd3e28bd530a6cd03ea4eeb1 Mon Sep 17 00:00:00 2001 From: smirnovavyu Date: Fri, 4 Sep 2026 15:12:50 +0000 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B8=D1=82=D1=8C=20Sm?= =?UTF-8?q?irnovaVYu/docs/data/commands.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SmirnovaVYu/docs/data/commands.py | 62 ------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 SmirnovaVYu/docs/data/commands.py diff --git a/SmirnovaVYu/docs/data/commands.py b/SmirnovaVYu/docs/data/commands.py deleted file mode 100644 index 4abbc4a5..00000000 --- a/SmirnovaVYu/docs/data/commands.py +++ /dev/null @@ -1,62 +0,0 @@ -from abc import ABC, abstractmethod -from typing import Optional -from models import Cell, Maze - - -class Player: - - def __init__(self, start_cell: Cell): - self.current_cell = start_cell - - def move_to(self, new_cell: Cell) -> None: - self.current_cell = new_cell - - -class Command(ABC): - - @abstractmethod - def execute(self) -> bool: - pass - - @abstractmethod - def undo(self) -> None: - pass - - -class MoveCommand(Command): - - def __init__(self, player: Player, maze: Maze, direction: str): - self.player = player - self.maze = maze - self.direction = direction - self.previous_cell: Optional[Cell] = None - self.new_cell: Optional[Cell] = None - - def _get_target_cell(self) -> Optional[Cell]: - x, y = self.player.current_cell.x, self.player.current_cell.y - - if self.direction == 'w': - y -= 1 - elif self.direction == 's': - y += 1 - elif self.direction == 'a': - x -= 1 - elif self.direction == 'd': - x += 1 - else: - return None - - return self.maze.get_cell(x, y) - - def execute(self) -> bool: - self.previous_cell = self.player.current_cell - self.new_cell = self._get_target_cell() - - if self.new_cell and self.new_cell.is_passable(): - self.player.move_to(self.new_cell) - return True - return False - - def undo(self) -> None: - if self.previous_cell: - self.player.move_to(self.previous_cell) \ No newline at end of file