Ejemplo n.º 1
0
        // TODO: Delete
        private static MazeGrid GetMaze3(string mazeFilePath)
        {
            var lines = new StreamReader(new FileStream(mazeFilePath, FileMode.Open)).ReadToEnd().Replace(" ", "")
                        .Split(new[] { Environment.NewLine }, StringSplitOptions.None);

            var  builder      = new MazeApp.MazeBuilder();
            char currentState = ' ';

            foreach (var line in lines)
            {
                if (line == "#Walls")
                {
                    currentState = '#';
                }
                else if (line == "#Open")
                {
                    currentState = '.';
                }
                else if (line == "#Start")
                {
                    currentState = 'S';
                }
                else if (line == "#Finish")
                {
                    currentState = 'F';
                }
                else
                {
                    var point = Point.FromString(line);

                    switch (currentState)
                    {
                    case '#':
                        builder.WithClosedPoint(point);
                        break;

                    case 'S':
                        builder.WithStartPoint(point);
                        break;

                    case 'F':
                        builder.WithEndPoint(point);
                        break;

                    case '.':
                        builder.WithOpenPoint(point);
                        break;

                    default:
                        // NOP
                        break;
                    }
                }
            }

            return(builder.Build());
        }
Ejemplo n.º 2
0
        // TODO: Delete
        private static MazeGrid GetMaze2(string mazeFilePath)
        {
            // todo: handle \n newline characters instead of Environment.NewLine when you download a zip file
            var lines = new StreamReader(new FileStream(mazeFilePath, FileMode.Open)).ReadToEnd().Replace(" ", "")
                        .Split(new[] { Environment.NewLine }, StringSplitOptions.None);

            int currentRow = 0;
            var builder    = new MazeApp.MazeBuilder();

            foreach (var line in lines)
            {
                int currentCol = 0;

                foreach (var point in line)
                {
                    switch (point)
                    {
                    case '#':
                        builder.WithClosedPoint(currentCol, currentRow);
                        break;

                    case 'S':
                        builder.WithStartPoint(currentCol, currentRow);
                        break;

                    case 'F':
                        builder.WithEndPoint(currentCol, currentRow);
                        break;

                    case '.':
                        builder.WithOpenPoint(currentCol, currentRow);
                        break;

                    default:
                        throw new Exception("Maze input string contains invalid characters");
                    }

                    currentCol++;
                }

                currentRow++;
            }

            return(builder.Build());
        }