Esempio n. 1
0
 public Maze(MazeParams mazeParams, IMirrorFactory mirrorFactory)
 {
     this.mazeParams = mazeParams;
     rooms           = new IMirror[mazeParams.Width, mazeParams.Length];
     SetupRoomsWithDefaultMirrors(mirrorFactory);
     SetupRoomWithSpecialMirrors(mirrorFactory);
 }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        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");
            }
        }
Esempio n. 5
0
 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");
     }
 }
Esempio n. 6
0
        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();
        }
Esempio n. 7
0
 public void Read(MazeParams mazeParams)
 {
     ReadDimensions(mazeParams);
     ReadMirrors(mazeParams);
     ReadLaserStart(mazeParams);
 }
Esempio n. 8
0
 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));
 }