From e3e6e176a471b86f550a839f7909671033758f2b Mon Sep 17 00:00:00 2001 From: Veronika Minina Date: Sun, 17 May 2026 17:16:36 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D1=89?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MininaVD/docs2/data2/commandsPlayer.ipynb | 65 +++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 MininaVD/docs2/data2/commandsPlayer.ipynb diff --git a/MininaVD/docs2/data2/commandsPlayer.ipynb b/MininaVD/docs2/data2/commandsPlayer.ipynb new file mode 100644 index 0000000..2329588 --- /dev/null +++ b/MininaVD/docs2/data2/commandsPlayer.ipynb @@ -0,0 +1,65 @@ +{ + "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 +}