Exemple #1
0
        public override MazeSide GetCell(int row, int col)
        {
            CheckCellExists(row, col);
            MazeSide cell = AddExternalBorders(row, col, mazeMatrix[row, col]);

            return(cell);
        }
Exemple #2
0
        private List <MazePoint> Walk(MazePoint coord, int index)
        {
            int row = coord.Row;
            int col = coord.Col;

            List <MazePoint> openedPoints = new List <MazePoint>(4);

            ClusterCell(row, col, index);

            MazeSide currentCell = maze.GetCell(row, col);

            if (!currentCell.HasFlag(MazeSide.Bottom))
            {
                int nextRow = row + 1;
                if (ClusterCell(nextRow, col, index))
                {
                    openedPoints.Add(new MazePoint(nextRow, col));
                }
            }

            if (!currentCell.HasFlag(MazeSide.Right))
            {
                int nextCol = col + 1;
                if (ClusterCell(row, nextCol, index))
                {
                    openedPoints.Add(new MazePoint(row, nextCol));
                }
            }

            if (!currentCell.HasFlag(MazeSide.Top))
            {
                int nextRow = row - 1;
                if (ClusterCell(nextRow, col, index))
                {
                    openedPoints.Add(new MazePoint(nextRow, col));
                }
            }

            if (!currentCell.HasFlag(MazeSide.Left))
            {
                int nextCol = col - 1;
                if (ClusterCell(row, nextCol, index))
                {
                    openedPoints.Add(new MazePoint(row, nextCol));
                }
            }

            return(openedPoints);
        }
Exemple #3
0
    // Start is called before the first frame update
    void Start()
    {
        try
        {
            int rowCount = 35;
            int colCount = 35;

            CreateRightWall(0, colCount - 1, null, true);
            for (int row = 1; row < rowCount; row++)
            {
                CreateLeftWall(row, 0, true);
                CreateRightWall(row, colCount - 1, null, true);
            }

            for (int col = 0; col < colCount; col++)
            {
                CreateTopWall(0, col, true);
                CreateBottomWall(rowCount - 1, col, null, true);
            }

            IMazeGenerator generator = new EllerModMazeGenerator();

            IMazeView maze = generator.Generate(rowCount, colCount);
            for (int row = 0; row < rowCount; row++)
            {
                for (int col = 0; col < colCount; col++)
                {
                    MazeSide cell = maze.GetCell(row, col);
                    if (cell.HasFlag(MazeSide.Bottom))
                    {
                        CreateBottomWall(row, col);
                    }

                    if (cell.HasFlag(MazeSide.Right))
                    {
                        CreateRightWall(row, col);
                    }
                }
            }

            player.transform.position = new Vector3((colCount - 1) * 5f, 2.5f, 2.5f);
        }
        catch (Exception ex)
        {
            Debug.Log(ex);
        }
    }
Exemple #4
0
        void WalkCluster(int row, int col, int cluster)
        {
            if (processedMaze.IsCellExists(row, col))
            {
                if (clusters.IsNonclustered(row, col))
                {
                    MazeSide currentCell = processedMaze.GetCell(row, col);
                    clusters.SetClusterIndex(row, col, cluster);

                    if (processedMaze.IsCellExists(row - 1, col))
                    {
                        if (!currentCell.HasFlag(MazeSide.Top))
                        {
                            WalkCluster(row - 1, col, cluster);
                        }
                    }

                    if (processedMaze.IsCellExists(row + 1, col))
                    {
                        if (!currentCell.HasFlag(MazeSide.Bottom))
                        {
                            WalkCluster(row + 1, col, cluster);
                        }
                    }

                    if (processedMaze.IsCellExists(row, col - 1))
                    {
                        if (!currentCell.HasFlag(MazeSide.Left))
                        {
                            WalkCluster(row, col - 1, cluster);
                        }
                    }

                    if (processedMaze.IsCellExists(row, col + 1))
                    {
                        if (!currentCell.HasFlag(MazeSide.Right))
                        {
                            WalkCluster(row, col + 1, cluster);
                        }
                    }
                }
            }
        }
Exemple #5
0
        private void DrawClusters(Graphics painter, IMazeView maze, MazeClusters clusters)
        {
            CreateClusterBrushes(clusters);
            for (int row = 0; row < rowCount; row++)
            {
                for (int col = 0; col < colCount; col++)
                {
                    int index = clusters.GetClusterIndex(row, col);

                    if (index != 0)
                    {
                        int drawRow = row * 2 + 1;
                        int drawCol = col * 2 + 1;

                        DrawCell(painter, clustersBrushes[index - 1],
                                 drawRow, drawCol);

                        MazeSide cell = maze.GetCell(row, col);

                        if (!cell.HasFlag(MazeSide.Bottom))
                        {
                            DrawCell(painter, clustersBrushes[index - 1],
                                     drawRow + 1, drawCol);
                        }

                        if (!cell.HasFlag(MazeSide.Right))
                        {
                            DrawCell(painter, clustersBrushes[index - 1],
                                     drawRow, drawCol + 1);
                        }

                        if (!cell.HasFlag(MazeSide.Bottom) && !cell.HasFlag(MazeSide.Right))
                        {
                            DrawCell(painter, clustersBrushes[index - 1],
                                     drawRow + 1, drawCol + 1);
                        }
                    }
                }
            }
        }
Exemple #6
0
        private void DrawMaze(Graphics painter, IMazeView maze)
        {
            for (int row = 0; row < rowCount; row++)
            {
                for (int col = 0; col < colCount; col++)
                {
                    MazeSide cell    = maze.GetCell(row, col);
                    int      drawRow = row * 2 + 1;
                    int      drawCol = col * 2 + 1;

                    if (cell.HasFlag(MazeSide.Right))
                    {
                        DrawCell(painter, sideBrush, drawRow - 1, drawCol + 1);
                        DrawCell(painter, sideBrush, drawRow, drawCol + 1);
                        DrawCell(painter, sideBrush, drawRow + 1, drawCol + 1);
                    }

                    if (cell.HasFlag(MazeSide.Bottom))
                    {
                        DrawCell(painter, sideBrush, drawRow + 1, drawCol - 1);
                        DrawCell(painter, sideBrush, drawRow + 1, drawCol);
                        DrawCell(painter, sideBrush, drawRow + 1, drawCol + 1);
                    }

                    if (cell.HasFlag(MazeSide.Left))
                    {
                        DrawCell(painter, sideBrush, drawRow - 1, drawCol - 1);
                        DrawCell(painter, sideBrush, drawRow, drawCol - 1);
                        DrawCell(painter, sideBrush, drawRow + 1, drawCol - 1);
                    }

                    if (cell.HasFlag(MazeSide.Top))
                    {
                        DrawCell(painter, sideBrush, drawRow - 1, drawCol - 1);
                        DrawCell(painter, sideBrush, drawRow - 1, drawCol);
                        DrawCell(painter, sideBrush, drawRow - 1, drawCol + 1);
                    }
                }
            }
        }
Exemple #7
0
        private void UpdateNeighbourCells(int row, int col, MazeSide sides)
        {
            if (sides.HasFlag(MazeSide.Top))
            {
                int upperRow = row - 1;
                if (IsCellExists(upperRow, col))
                {
                    mazeMatrix[upperRow, col] |= MazeSide.Bottom;
                }
            }

            if (sides.HasFlag(MazeSide.Bottom))
            {
                int lowerRow = row + 1;
                if (IsCellExists(lowerRow, col))
                {
                    mazeMatrix[lowerRow, col] |= MazeSide.Top;
                }
            }

            if (sides.HasFlag(MazeSide.Right))
            {
                int rightCol = col + 1;
                if (IsCellExists(row, rightCol))
                {
                    mazeMatrix[row, rightCol] |= MazeSide.Left;
                }
            }

            if (sides.HasFlag(MazeSide.Left))
            {
                int leftCol = col - 1;
                if (IsCellExists(row, leftCol))
                {
                    mazeMatrix[row, leftCol] |= MazeSide.Right;
                }
            }
        }
        private void DrawMaze(Graphics painter, IMazeView maze)
        {
            using (Pen bluePen = new Pen(Color.Blue, 1))
            {
                for (int row = 0; row < maze.RowCount; row++)
                {
                    for (int col = 0; col < maze.ColCount; col++)
                    {
                        Single   BaseX       = col * cellSize;
                        Single   BaseY       = row * cellSize;
                        MazeSide currentCell = maze.GetCell(row, col);

                        if (currentCell.HasFlag(MazeSide.Top))
                        {
                            painter.DrawLine(bluePen, BaseX, BaseY, BaseX + cellSize, BaseY);
                        }

                        if (currentCell.HasFlag(MazeSide.Bottom))
                        {
                            painter.DrawLine(bluePen, BaseX, BaseY + cellSize,
                                             BaseX + cellSize, BaseY + cellSize);
                        }

                        if (currentCell.HasFlag(MazeSide.Right))
                        {
                            painter.DrawLine(bluePen, BaseX + cellSize, BaseY,
                                             BaseX + cellSize, BaseY + cellSize);
                        }

                        if (currentCell.HasFlag(MazeSide.Left))
                        {
                            painter.DrawLine(bluePen, BaseX, BaseY,
                                             BaseX, BaseY + cellSize);
                        }
                    }
                }
            }
        }
        protected MazeSide AddExternalBorders(int row, int col, MazeSide cell)
        {
            if (row == 0)
            {
                cell |= MazeSide.Top;
            }

            if (row == rowCount - 1)
            {
                cell |= MazeSide.Bottom;
            }

            if (col == 0)
            {
                cell |= MazeSide.Left;
            }

            if (col == colCount - 1)
            {
                cell |= MazeSide.Right;
            }

            return(cell);
        }
Exemple #10
0
 public void AddSides(int row, int col, MazeSide sides)
 {
     CheckCellExists(row, col);
     mazeMatrix[row, col] |= sides;
     UpdateNeighbourCells(row, col, sides);
 }
 public override MazeSide GetCell(int row, int col)
 {
     MazeSide cell = MazeSide.None;
     cell = AddExternalBorders(row, col, cell);
     return cell;
 }