private List <INode> GenerateNewMaze(MazeTypes mazeType, int mazeDimensions)
        {
            List <INode> newMaze;

            newMaze = MazeGridFactory.GenerateMaze(mazeType, mazeDimensions);
            return(newMaze);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Error: expected filename as first argument to editor program.  Exiting.");
                Environment.Exit(1);
            }

            if (!File.Exists(args[0]))
            {
                Console.WriteLine("Error: file {0} not found.", args[0]);
                Environment.Exit(2);
            }

            using (StreamReader rawMazeData = File.OpenText(args[0]))
            {
                int size = Int32.Parse(rawMazeData.ReadLine());
                MazeTypes[,] editableMaze = new MazeTypes[size * 2 - 1, size * 2 - 1];
                for (int i = 0; i < size * 2 - 1; i++)
                {
                    string line = rawMazeData.ReadLine();
                    for (int j = 0; j < size * 2 - 1; j++)
                    {
                        switch (line[j])
                        {
                        case ' ':
                            editableMaze[i, j] = MazeTypes.Empty;
                            break;

                        case '+':
                            editableMaze[i, j] = MazeTypes.Node;
                            break;

                        case '-':
                            goto case '|';

                        case '|':
                            editableMaze[i, j] = MazeTypes.Hallway;
                            break;

                        case 'j':
                            editableMaze[i, j] = MazeTypes.Junk;
                            break;

                        case 'S':
                            editableMaze[i, j] = MazeTypes.Start;
                            break;

                        case 'E':
                            editableMaze[i, j] = MazeTypes.End;
                            break;
                        }
                    }
                }
                rawMazeData.Close();
                Console.WriteLine("Remember that the lines drawn are the pathways, not the blank space between them.  When rendering, they will behave like you expect them to.");
                MazeEditor.EnterEditMode(editableMaze);
            }
        }
Exemple #3
0
    MazeTypes[,] ReadFile(string filename)
    {
        try
        {
            using (StreamReader rawMazeData = File.OpenText(filename))
            {
                int size = int.Parse(rawMazeData.ReadLine());
                MazeTypes[,] editableMaze = new MazeTypes[size * 2 - 1, size * 2 - 1];
                for (int i = 0; i < size * 2 - 1; i++)
                {
                    string line = rawMazeData.ReadLine();
                    for (int j = 0; j < size * 2 - 1; j++)
                    {
                        switch (line[j])
                        {
                        case ' ':
                            editableMaze[i, j] = MazeTypes.Empty;
                            break;

                        case '+':
                            editableMaze[i, j] = MazeTypes.Node;
                            break;

                        case '-':
                            goto case '|';

                        case '|':
                            editableMaze[i, j] = MazeTypes.Hallway;
                            break;

                        case 'j':
                            editableMaze[i, j] = MazeTypes.Junk;
                            break;

                        case 'E':
                            editableMaze[i, j] = MazeTypes.End;
                            break;

                        case 'S':
                            editableMaze[i, j] = MazeTypes.Start;
                            break;
                        }
                    }
                }
                rawMazeData.Close();
                return(editableMaze);
            }
        }
        catch (Exception e)
        {
            unableToRead = true;
            print(e);
            return(null);
        }
    }
Exemple #4
0
 private static MazeTypes[,] CopyMaze(MazeTypes[,] maze)
 {
     MazeTypes[,] newMaze = new MazeTypes[maze.GetLength(0), maze.GetLength(1)];
     for (int i = 0; i < maze.GetLength(0); i++)
     {
         for (int j = 0; j < maze.GetLength(1); j++)
         {
             newMaze[i, j] = maze[i, j];
         }
     }
     return(newMaze);
 }
        public DefaultCreator(int corridorBias, int seed, Directions start, Directions end, MazeTypes mazeType, int roomDensity, int roomDistance, int roomMinSize, int roomMaxSize)
        {
            _corridorBias = corridorBias;
            _mazeType     = mazeType;

            _startDirection = start;
            _endDirection   = end;

            _roomDensity  = roomDensity;
            _roomDistance = roomDistance;
            _roomMinSize  = roomMinSize;
            _roomMaxSize  = roomMaxSize;


            _pathRandomizer     = new Random(seed);
            _startEndRandomizer = new Random(seed);
            _roomRandomizer     = new Random(seed);
        }
        private void EventCreateNewMaze(object sender, EventArgs e)
        {
            try
            {
                int       newMazeDimension = View.MazeDimensionsSelected;
                MazeTypes newMazeType      = (MazeTypes)View.CurrentMazeTypeSelected;

                SetMazeGrid(newMazeType, newMazeDimension);
                SetMazeStart();
                SetMazeEnd(newMazeDimension);
                Maze.MazeSolution.Solution = null;

                //Update View to display maze
                UpdateViewDisplayMaze(Maze.MazeGrid.Grid);
                UpdateViewDisplayStart(Maze.Start);
                UpdateViewDisplayEnd(Maze.End);
                UpdateViewDrawGrid();
            }
            catch (Exception ex)
            {
                View.DisplayErrorDetailsDebugging(ex);
            }
        }
Exemple #7
0
        public static List <INode> GenerateMaze(MazeTypes type, int mazeDimension)
        {
            List <INode> mazeGrid = new List <INode>();

            switch (type)
            {
            case MazeTypes.Blank:
                mazeGrid = MazeGridFactory.GenerateBlankMaze(mazeDimension);
                break;

            case MazeTypes.Scatter:
                mazeGrid = MazeGridFactory.GenerateScatterMaze(mazeDimension, 20);
                break;

            case MazeTypes.Traditional:
                mazeGrid = null;
                break;

            default:
                mazeGrid = null;
                break;
            }
            return(mazeGrid);
        }
Exemple #8
0
        private static void OneEdge(MazeTypes[,] maze)
        {
            savedSinceLastEdit = false;
            Console.WriteLine("Remember that this counts by the + symbols, starting at 0 and counting up.");
            Console.Write("Which node do you want to start with?  Enter row number first, followed by the column: ");
            int node_x;
            int node_y;

OneEdgeTwoIntInput:
            try
            {
                string[] node = Console.ReadLine().Split(null);
                node_x = int.Parse(node[0]);
                node_y = int.Parse(node[1]);
            }
            catch (FormatException e)
            {
                Console.WriteLine("Unable to parse two inputs as integers");
                goto OneEdgeTwoIntInput;
            }
            catch (IndexOutOfRangeException e)
            {
                Console.WriteLine("Not enough inputs");
                goto OneEdgeTwoIntInput;
            }
            if (node_x >= maze.GetLength(0) / 2 + 1 || node_x < 0 || node_y >= maze.GetLength(1) / 2 + 1 || node_y < 0)
            {
                Console.WriteLine("Numbers entered are out of bounds");
                goto OneEdgeTwoIntInput;
            }
            Console.Write("What direction do you want to go? (u)p, (d)own, (l)eft, (r)ight: ");
            char direction = '\0';

OneEdgeDirectionInput:
            string input = Console.ReadLine().ToLower();

            switch (input)
            {
            case "u":
                direction = 'u';
                break;

            case "d":
                direction = 'd';
                break;

            case "l":
                direction = 'l';
                break;

            case "r":
                direction = 'r';
                break;

            default:
                Console.WriteLine("Invalid option: {0}\n", input);
                goto OneEdgeDirectionInput;
            }
            Console.Write("What operation would you like to perform? (a)dd hallway, (r)emove hallway: ");
            bool addingHallway = true;

OneEdgeAddRemovePrompt:
            input = Console.ReadLine().ToLower();
            switch (input)
            {
            case "a":
                addingHallway = true;
                break;

            case "r":
                addingHallway = false;
                break;

            default:
                Console.WriteLine("Invalid option: {0}", input);
                goto OneEdgeAddRemovePrompt;
            }
            //finally we can do the operation
            try
            {
                MazeTypes edge = (addingHallway ? MazeTypes.Hallway : MazeTypes.Empty);
                switch (direction)
                {
                case 'r':
                    maze[node_x * 2, node_y * 2 + 1] = edge;
                    break;

                case 'l':
                    maze[node_x * 2, node_y * 2 - 1] = edge;
                    break;

                case 'u':
                    maze[node_x * 2 - 1, node_y * 2] = edge;
                    break;

                case 'd':
                    maze[node_x * 2 + 1, node_y * 2] = edge;
                    break;
                }
            }
            catch (IndexOutOfRangeException e)
            {
                Console.WriteLine("\n\nThe hallway you have attempted to change has gone off the edge of the map.  Unable to perform operation.\n\n");
            }
        }
 private void SetMazeGrid(MazeTypes type, int dimensions)
 {
     Maze.MazeGrid.SetNewMazeGrid(GenerateNewMaze(type, dimensions), dimensions);
 }