forked from UNN/2026-rff_mp
81 lines
2.8 KiB
Python
81 lines
2.8 KiB
Python
|
|
import sys
|
|||
|
|
import os
|
|||
|
|
|
|||
|
|
sys.path.insert(0, r'C:\ivantsovma\docs\MazeProject')
|
|||
|
|
from builders import TextFileMazeBuilder
|
|||
|
|
from strategies import BFSStrategy
|
|||
|
|
from visualization import ConsoleView, GameController
|
|||
|
|
|
|||
|
|
def test_observer():
|
|||
|
|
print("ПАТТЕРН OBSERVER")
|
|||
|
|
# Загружаем лабиринт
|
|||
|
|
builder = TextFileMazeBuilder()
|
|||
|
|
maze = builder.build_from_file("mazes/small_maze.txt")
|
|||
|
|
|
|||
|
|
#создаём наблюдателя
|
|||
|
|
view = ConsoleView()
|
|||
|
|
|
|||
|
|
#уведомления о событии
|
|||
|
|
view.update("maze_loaded", maze)
|
|||
|
|
view.update("search_start", None)
|
|||
|
|
view.update("path_found", None)
|
|||
|
|
|
|||
|
|
print("\nObserver работает!")
|
|||
|
|
|
|||
|
|
def test_game_controller():
|
|||
|
|
print("ПАТТЕРН COMMAND (УПРАВЛЕНИЕ ИГРОКОМ)")
|
|||
|
|
|
|||
|
|
#pагружаем простой лабиринт
|
|||
|
|
builder = TextFileMazeBuilder()
|
|||
|
|
maze = builder.build_from_file("mazes/simple_maze.txt")
|
|||
|
|
|
|||
|
|
#cоздаём контроллер
|
|||
|
|
controller = GameController(maze)
|
|||
|
|
|
|||
|
|
print(f"Начальная позиция: ({controller.get_player_position().x}, {controller.get_player_position().y})")
|
|||
|
|
|
|||
|
|
#движение вправо
|
|||
|
|
controller.move((1, 0)) #Вправо
|
|||
|
|
print(f"После движения вправо: ({controller.get_player_position().x}, {controller.get_player_position().y})")
|
|||
|
|
|
|||
|
|
controller.move((1, 0)) #Вправо
|
|||
|
|
print(f"После движения вправо: ({controller.get_player_position().x}, {controller.get_player_position().y})")
|
|||
|
|
|
|||
|
|
#отменяем последние движения
|
|||
|
|
controller.undo()
|
|||
|
|
print(f"После отмены: ({controller.get_player_position().x}, {controller.get_player_position().y})")
|
|||
|
|
|
|||
|
|
controller.undo()
|
|||
|
|
print(f"После второй отмены: ({controller.get_player_position().x}, {controller.get_player_position().y})")
|
|||
|
|
|
|||
|
|
print("\nCommand работает!")
|
|||
|
|
|
|||
|
|
def test_integration():
|
|||
|
|
print("ИНТЕГРАЦИЯ ВСЕХ КОМПОНЕНТОВ")
|
|||
|
|
|
|||
|
|
# Загружаем лабиринт
|
|||
|
|
builder = TextFileMazeBuilder()
|
|||
|
|
maze = builder.build_from_file("mazes/small_maze.txt")
|
|||
|
|
|
|||
|
|
# Находим путь
|
|||
|
|
bfs = BFSStrategy()
|
|||
|
|
path = bfs.find_path(maze, maze.start, maze.exit)
|
|||
|
|
|
|||
|
|
# Создаём отображение
|
|||
|
|
view = ConsoleView()
|
|||
|
|
view.maze = maze
|
|||
|
|
view.path = path
|
|||
|
|
view.render()
|
|||
|
|
|
|||
|
|
print("\nИнтеграция работает!")
|
|||
|
|
|
|||
|
|
def run_interactive_game():
|
|||
|
|
print("ИНТЕРАКТИВНАЯ ИГРА")
|
|||
|
|
print("Для запуска интерактивной игры используйте:")
|
|||
|
|
print("python play_maze.py")
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
test_observer()
|
|||
|
|
test_game_controller()
|
|||
|
|
test_integration()
|
|||
|
|
run_interactive_game()
|