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