public Maze(MazeParams mazeParams, IMirrorFactory mirrorFactory) { this.mazeParams = mazeParams; rooms = new IMirror[mazeParams.Width, mazeParams.Length]; SetupRoomsWithDefaultMirrors(mirrorFactory); SetupRoomWithSpecialMirrors(mirrorFactory); }
private static void RunMaze(string filePath) { var mazeReader = new MazeReader(new StreamReaderWrapper(filePath)); var mazeParams = new MazeParams(); mazeReader.Read(mazeParams); var maze = new Maze(mazeParams, new MirrorFactory()); var endLaserPosition = maze.ShootLaser(); Print(mazeParams, endLaserPosition); }
private void ReadMirrors(MazeParams mazeParams) { string line; const string sectionEndDelimeter = "-1"; mazeParams.Mirrors = new List <MetaPosition>(); while (null != (line = streamReader.ReadLine()) && sectionEndDelimeter != line) { ReadMirror(line, mazeParams); } }
private void ReadMirror(string line, MazeParams mazeParams) { var positionAndOrientationSplitter = new Regex("(?<=[0-9,])(?=[LR])"); try { var mirror = ReadPositionAndOrientation(positionAndOrientationSplitter, line); mazeParams.Mirrors.Add(mirror); } catch (SystemException) { Console.WriteLine("Exception while reading maze mirror"); } }
private void ReadDimensions(MazeParams mazeParams) { try { var dimensions = streamReader.ReadLine().Split(','); mazeParams.Width = Int32.Parse(dimensions[0]); mazeParams.Length = Int32.Parse(dimensions[1]); ReadDummySectionEndDelimeter(); } catch (SystemException) { Console.WriteLine("Exception while reading maze dimensions"); } }
private void ReadLaserStart(MazeParams mazeParams) { var positionAndOrientationSplitter = new Regex("(?<=[0-9,])(?=[HV])"); var line = streamReader.ReadLine(); try { var laserStart = ReadPositionAndOrientation(positionAndOrientationSplitter, line); mazeParams.LaserStart = laserStart; } catch (SystemException) { Console.WriteLine("Exception while reading maze laser start"); } ReadDummySectionEndDelimeter(); }
public void Read(MazeParams mazeParams) { ReadDimensions(mazeParams); ReadMirrors(mazeParams); ReadLaserStart(mazeParams); }
private static void Print(MazeParams mazeParams, MetaPosition endPosition) { Console.WriteLine("(X,Y) = ({0},{1})", mazeParams.Width, mazeParams.Length); Console.WriteLine("start: {0}", MetaPositionStringFormatter.Format(mazeParams.LaserStart)); Console.WriteLine("end: {0}", MetaPositionStringFormatter.Format(endPosition)); }