{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "c2a5ffd4-9644-453e-83de-bdac76215a37", "metadata": {}, "outputs": [], "source": [ "from typing import Optional\n", "from modelsMaze import Maze\n", "from modelsCell import Cell\n", "\n", "class Player:\n", " \"\"\"Игрок, перемещающийся по лабиринту.\"\"\"\n", " \n", " def __init__(self, maze: Maze, start_cell: Cell):\n", " self.maze = maze\n", " self.current_cell = start_cell\n", " self._previous_cell: Optional[Cell] = None\n", " \n", " def move_to(self, cell: Cell) -> bool:\n", " \"\"\"Переместить игрока в указанную клетку (если она проходима).\"\"\"\n", " if cell and cell.is_passable():\n", " self._previous_cell = self.current_cell\n", " self.current_cell = cell\n", " return True\n", " return False\n", " \n", " def undo_move(self) -> bool:\n", " \"\"\"Отменить последнее перемещение.\"\"\"\n", " if self._previous_cell:\n", " self.current_cell = self._previous_cell\n", " self._previous_cell = None\n", " return True\n", " return False\n", " \n", " @property\n", " def position(self) -> Cell:\n", " return self.current_cell" ] } ], "metadata": { "kernelspec": { "display_name": "Python [conda env:base] *", "language": "python", "name": "conda-base-py" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.9" } }, "nbformat": 4, "nbformat_minor": 5 }