2026-rff_mp/pomelovsd/ExitMaze/Builder/Builder.py

28 lines
832 B
Python
Raw Normal View History

2026-05-23 10:37:43 +00:00
from Core.Cell import Cell
from Core.Maze import Maze
from Builder.BuilderInterface import MazeBuilders
class TextFileMazeBuilder(MazeBuilders):
def build_from_file(self, filename):
grid = []
start = None
exit = None
with open(filename, "r", encoding="utf-8") as f:
lines = [line.rstrip("\n") for line in f]
for y, line in enumerate(lines):
row = []
for x, ch in enumerate(line):
2026-05-25 10:45:18 +00:00
cell = Cell(x, y, isWall = (ch == "#"), isStart = (ch == "S"), isExit = (ch == "E"))
2026-05-23 10:37:43 +00:00
if (ch == "S"):
start = cell
if (ch == "E"):
exit = cell
row.append(cell)
grid.append(row)
return Maze(grid, start, exit)