Example #1
0
 private void FillMaze(Maze maze)
 {
     for (int x = 0; x < maze.width; x++)
     {
         for (int y = 0; y < maze.height; y++)
         {
             Point2D  point = new Point2D(x, y);
             MazeWall wall  = new MazeWall(point);
             maze.addWall(wall);
         }
     }
 }
Example #2
0
        private MazeCell?GetNeighborCell(MazeWall wall, int mazeSize)
        {
            MazeCell cell = new MazeCell()
            {
                X = -1, Y = -1
            };

            switch (wall.Wall)
            {
            case Wall.Bottom:
                if (wall.Cell.X < mazeSize - 1)
                {
                    cell.X = wall.Cell.X + 1;
                    cell.Y = wall.Cell.Y;
                }
                break;

            case Wall.Left:
                if (wall.Cell.Y > 0)
                {
                    cell.Y = wall.Cell.Y - 1;
                    cell.X = wall.Cell.X;
                }
                break;

            case Wall.Right:
                if (wall.Cell.Y < mazeSize - 1)
                {
                    cell.Y = wall.Cell.Y + 1;
                    cell.X = wall.Cell.X;
                }
                break;

            case Wall.Top:
                if (wall.Cell.X > 0)
                {
                    cell.X = wall.Cell.X - 1;
                    cell.Y = wall.Cell.Y;
                }
                break;

            default: break;
            }
            if (cell.X < 0 || cell.Y < 0)
            {
                return(null);
            }

            return(cell);
        }
Example #3
0
 private void AddOuterWalls(MazeRoom mazeRoom)
 {
     for (int y = 0; y < mazeRoom.height; y++)
     {
         for (int x = 0; x < mazeRoom.width; x++)
         {
             Point2D point = new Point2D(x, y);
             if (IsOuterWall(mazeRoom.maze, x, y) & !mazeRoom.isAnExit(point))
             {
                 MazeWall wall = new MazeWall(point);
                 mazeRoom.maze.addWall(wall);
             }
         }
     }
 }
Example #4
0
        private void CarveMaze(Maze maze, Point2D current, Random rnd)
        {
            if (maze.hasWallAt(current))
            {
                MazeWall wall = new MazeWall(current);
                maze.removeWall(wall);
            }

            List <Point2D> possiblePoints = GetPossibleNextPoints(maze, current);

            Console.WriteLine("Possible Next Moves: " + possiblePoints.Count);

            if (possiblePoints.Count > 0)
            {
                int     randomIndex = rnd.Next(possiblePoints.Count);
                Point2D nextPoint   = possiblePoints[randomIndex];

                CarveMaze(maze, nextPoint, rnd);
            }
        }
Example #5
0
        private MazeRoom MergeMazeWalls(MazeRoom mainMaze, MazeRoom subMaze, Point2D offset)
        {
            for (int x = 0; x < mainMaze.width; x++)
            {
                for (int y = 0; y < mainMaze.height; y++)
                {
                    if (IsOuterWall(mainMaze.maze, x, y))
                    {
                        continue;
                    }

                    Point2D point = new Point2D(x, y);
                    if (mainMaze.maze.hasWallAt(point))
                    {
                        continue;
                    }
                    if (x < offset.x)
                    {
                        continue;
                    }
                    if (y < offset.y)
                    {
                        continue;
                    }

                    Point2D subMazePoint = new Point2D(x - offset.x, y - offset.y);
                    if (!subMaze.maze.hasWallAt(subMazePoint))
                    {
                        continue;
                    }
                    // Console.WriteLine("adding wall from sub maze at: "+point.ToString());
                    MazeWall wall = new MazeWall(point);
                    mainMaze.maze.addWall(wall);
                }
            }

            return(mainMaze);
        }
Example #6
0
 public void removeWall(MazeWall wall)
 {
     walls.removeWall(wall);
 }
Example #7
0
 public void addWall(MazeWall wall)
 {
     walls.addWall(wall);
 }
Example #8
0
 public void removeWall(MazeWall wall)
 {
     walls.Remove(wall.point);
 }
Example #9
0
 public void addWall(MazeWall wall)
 {
     walls.Add(wall.point, wall);
 }