Exemplo n.º 1
0
        private bool CanPlaceObstacle(PathCell[,] inCells, PathCell atCell)
        {
            foreach (Vector2Int location in atCell.GetNeighboursLocations())
            {
                // Make sure we don't create a dead end for the player.
                if (inCells.Contains(location) && inCells[location.x, location.y].CellType == PathCell.Type.OBSTACLE)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        private void GenerateLevel(TilesLayout.TilesLayout tilesLayout, TilesLayout.TilesLayoutContent content)
        {
            var obstaclePositioner  = new ObstaclePositioner();
            var emptyCellPositioner = new EmptyCellPositioner();

            var cells = new PathCell[content.Columns, content.Rows];

            cells.ForeachIndexed((x, y, cell) => cells[x, y] = new PathCell(x, y));

            int pathLength   = EnsurePathExists(cells);
            var letters      = GenerateLetters(pathLength);
            int maxObstacles = cells.Length - (letters.Count >= pathLength ? (letters.Count) : (pathLength));

            obstaclePositioner.PlaceObstacles(cells, maxObstacles);
            PlaceRemainingLetters(cells, pathLength, letters);
            emptyCellPositioner.PlaceEmptyCells(cells);

            cells.Print();

            GenerateGameObjects(cells, tilesLayout, content, letters);
        }
Exemplo n.º 3
0
        public static Vector2Int?GetNeighbour(this PathCell cell, PathDirection direction, PathCell[,] cells)
        {
            Vector2Int neighbour;

            switch (direction)
            {
            case PathDirection.LEFT:
                neighbour = cell.LeftNeighbour;
                break;

            case PathDirection.UP:
                neighbour = cell.TopNeighbour;
                break;

            case PathDirection.RIGHT:
                neighbour = cell.RightNeighbour;
                break;

            case PathDirection.DOWN:
                neighbour = cell.BottomNeighour;
                break;

            default:
                return(null);
            }

            var isInBounds = cells.Contains(neighbour);
            var visited    = isInBounds ? cells[neighbour.x, neighbour.y].Visited : false;

            if (isInBounds && !visited)
            {
                return(neighbour);
            }
            else
            {
                return(null);
            }
        }