добавлены команды для управления
This commit is contained in:
parent
88fe6c89c8
commit
95dd862d49
27
komissarovgo/docs2/data2/maze_lab/commands.py
Normal file
27
komissarovgo/docs2/data2/maze_lab/commands.py
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
from abc import ABC, abstractmethod
|
||||||
|
from models import Cell, Player
|
||||||
|
|
||||||
|
|
||||||
|
class Command(ABC):
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def execute(self) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def undo(self) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class MoveCommand(Command):
|
||||||
|
|
||||||
|
def __init__(self, player: Player, new_cell: Cell):
|
||||||
|
self._player = player
|
||||||
|
self._new_cell = new_cell
|
||||||
|
self._old_cell = player.current_cell
|
||||||
|
|
||||||
|
def execute(self) -> None:
|
||||||
|
self._player.move_to(self._new_cell)
|
||||||
|
|
||||||
|
def undo(self) -> None:
|
||||||
|
self._player.move_to(self._old_cell)
|
||||||
Loading…
Reference in New Issue
Block a user