From d677c5c794bff8e6d8dd6ffbc8b08cde55dc804a Mon Sep 17 00:00:00 2001 From: Veronika Minina Date: Sun, 17 May 2026 17:17:41 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../docs2/data2/commandsMove_command.ipynb | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 MininaVD/docs2/data2/commandsMove_command.ipynb diff --git a/MininaVD/docs2/data2/commandsMove_command.ipynb b/MininaVD/docs2/data2/commandsMove_command.ipynb new file mode 100644 index 0000000..8bcd6d7 --- /dev/null +++ b/MininaVD/docs2/data2/commandsMove_command.ipynb @@ -0,0 +1,84 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "492dd9b1-922e-4c95-9112-4b2df086eae6", + "metadata": {}, + "outputs": [], + "source": [ + "from typing import Optional\n", + "from commandsCommand import Command\n", + "from commandsPlayer import Player\n", + "from modelsMaze import Maze\n", + "from modelsCell import Cell\n", + "\n", + "class MoveCommand(Command):\n", + " \"\"\"Команда перемещения игрока.\"\"\"\n", + " \n", + " # Направления\n", + " DIRECTIONS = {\n", + " 'w': (0, -1), # вверх\n", + " 's': (0, 1), # вниз\n", + " 'a': (-1, 0), # влево\n", + " 'd': (1, 0), # вправо\n", + " }\n", + " \n", + " def __init__(self, player: Player, maze: Maze, direction: str):\n", + " self.player = player\n", + " self.maze = maze\n", + " self.direction = direction.lower()\n", + " self._target_cell: Optional[Cell] = None\n", + " self._executed = False\n", + " \n", + " def execute(self) -> bool:\n", + " \"\"\"Выполнить перемещение.\"\"\"\n", + " if self.direction not in self.DIRECTIONS:\n", + " return False\n", + " \n", + " dx, dy = self.DIRECTIONS[self.direction]\n", + " x = self.player.current_cell.x + dx\n", + " y = self.player.current_cell.y + dy\n", + " \n", + " self._target_cell = self.maze.get_cell(x, y)\n", + " \n", + " if self._target_cell and self._target_cell.is_passable():\n", + " self.player.move_to(self._target_cell)\n", + " self._executed = True\n", + " return True\n", + " \n", + " return False\n", + " \n", + " def undo(self) -> bool:\n", + " \"\"\"Отменить перемещение.\"\"\"\n", + " if self._executed:\n", + " success = self.player.undo_move()\n", + " if success:\n", + " self._executed = False\n", + " return True\n", + " return False" + ] + } + ], + "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 +}