Esempio n. 1
0
        /// <summary>
        /// Returns the cells that are adjecent to given cell, are not checked yet and are not blocked by a wall
        /// </summary>
        /// <param name="cell"></param>
        /// <returns></returns>
        public List <MazeCell> GetNextCellsInPath(MazeCell cell)
        {
            List <MazeCell> cells = new List <MazeCell>();

            MazeCell top = generationService.GetTopNeighbour(cell);

            if (top != null && !top.IsChecked && cell.HasPassageTowardsCell(top))
            {
                cells.Add(top);
            }

            MazeCell bottom = generationService.GetBottomNeighbour(cell);

            if (bottom != null && !bottom.IsChecked && cell.HasPassageTowardsCell(bottom))
            {
                cells.Add(bottom);
            }

            MazeCell left = generationService.GetLeftNeighbour(cell);

            if (left != null && !left.IsChecked && cell.HasPassageTowardsCell(left))
            {
                cells.Add(left);
            }

            MazeCell right = generationService.GetRightNeighbour(cell);

            if (right != null && !right.IsChecked && cell.HasPassageTowardsCell(right))
            {
                cells.Add(right);
            }

            return(cells);
        }
Esempio n. 2
0
        /// <summary>
        /// Sets the given next cell in path if it can find it relative to given cell's direction. Returns whether it succeeded
        /// </summary>
        /// <param name="cell"></param>
        /// <param name="direction"></param>
        /// <param name="nextCellInPath"></param>
        /// <returns></returns>
        public bool GetNextCellInPathRelative(MazeCell cell, Vector2Int direction, ref MazeCell nextCellInPath)
        {
            MazeCell validCellNextInPath = null;

            if (direction == Vector2Int.up)
            {
                validCellNextInPath = generationService.GetTopNeighbour(cell);
            }
            else if (direction == Vector2Int.down)
            {
                validCellNextInPath = generationService.GetBottomNeighbour(cell);
            }
            else if (direction == Vector2Int.right)
            {
                validCellNextInPath = generationService.GetRightNeighbour(cell);
            }
            else if (direction == Vector2Int.left)
            {
                validCellNextInPath = generationService.GetLeftNeighbour(cell);
            }

            if (validCellNextInPath != null && cell.HasPassageTowardsCell(validCellNextInPath))
            {
                nextCellInPath = validCellNextInPath;
                return(true);
            }
            else
            {
                return(false);
            }
        }