Пример #1
0
        private void OnDrawGizmos()
        {
            if (!Application.isPlaying)
            {
                if (sceneSettings == null)
                {
                    sceneSettings = GameObject.FindGameObjectWithTag("SceneSettings")?.
                                    GetComponent <SceneSettings>();
                }

                if (sceneSettings != null)
                {
                    boardProfile = sceneSettings.boardProfile;

                    if (boardProfile == null || boardProfile.tilePack == null)
                    {
                        return;
                    }

                    Vector2Int tilesDimesions = sceneSettings.boardProfile.size;
                    Vector2    tileSize       = sceneSettings.boardProfile.tilePack.boardTiles[0].size;

                    boardOriginPosition = sceneSettings.boardOrigin.position +
                                          new Vector3(-tilesDimesions.x * (tileSize.x * 0.5f), tilesDimesions.y * (tileSize.y * 0.5f), 0f);
                }
            }

            if (boardProfile == null)
            {
                return;
            }

            DrawBoard(boardOriginPosition, boardProfile);
        }
Пример #2
0
        private void DrawBoard(Vector3 originPosition, BoardProfile profile)
        {
            if (originPosition == null || profile.tilePack == null)
            {
                return;
            }

            Vector3   startPosition = originPosition;
            BoardTile prefab        = profile.tilePack.boardTiles[0];

            for (int x = 0; x < profile.size.x; x++)
            {
                for (int y = 0; y < profile.size.y; y++)
                {
                    Vector3 position = new Vector3(startPosition.x + (prefab.size.x * 0.5f) + (prefab.size.x * x),
                                                   startPosition.y - (prefab.size.y * 0.5f) - (prefab.size.y * y), 0);

                    DrawRect(position, prefab.size, x, y);

                    if (debug)
                    {
                        // --- Debug Coordinates ---
                        if (debugCoordinates.x == x && debugCoordinates.y == y)
                        {
                            foreach (Vector2Int adjacentItem in GetAdjacent(new Vector2Int(x, y)))
                            {
                                Vector3 position2 = new Vector3(startPosition.x + (prefab.size.x * 0.5f) + (prefab.size.x * adjacentItem.x),
                                                                startPosition.y - (prefab.size.y * 0.5f) - (prefab.size.y * adjacentItem.y), 0);

                                DrawRect(position2, prefab.size, adjacentItem.x, adjacentItem.y);
                            }
                        }
                    }
                }
            }
        }
Пример #3
0
        private void CreateBoard(BoardProfile profile)
        {
            // --- Set Board Variables ---
            BoardTile[] tilesetLibrary = profile.tilePack.boardTiles; // TileSet
            int         tilesetLength  = tilesetLibrary.Length;

            tiles          = new BoardTile[profile.size.x, profile.size.y]; // board array2D
            tileSize       = profile.tilePack.boardTiles[0].size;
            tilesDimesions = new Vector2Int(profile.size.x, profile.size.y);

            boardOriginPosition = boardOrigin.position +
                                  new Vector3(-tilesDimesions.x * (tileSize.x * 0.5f), tilesDimesions.y * (tileSize.y * 0.5f), 0f);

            // Variables for recognition
            int[] previousLeft  = new int[profile.size.y];
            int   previousAbove = -1;

            previousLeftAbove = new int[profile.size.y];

            tweenMatchTileDelay = profile.matchTileDelay;
            tweenRefillRowDelay = profile.refillRowDelay;

            // --- Board Loop ---
            for (int x = 0; x < profile.size.x; x++)
            {
                for (int y = 0; y < profile.size.y; y++)
                {
                    // -- Create Possible TileList --
                    List <int> possibleBoardTiles = new List <int>();

                    for (int i = 0; i < tilesetLength; i++)
                    {
                        if (i != previousAbove && i != previousLeft[y])
                        {
                            if (diagonalOption && x > 0 && y > 0)
                            {
                                bool digAbove = tiles[x - 1, y - 1].id != tilesetLibrary[i].id;

                                if (y < tilesDimesions.y - 1)
                                {
                                    bool digBelow = tiles[x - 1, y + 1].id != tilesetLibrary[i].id;

                                    if (digAbove && digBelow)
                                    {
                                        possibleBoardTiles.Add(i);
                                    }
                                }
                                else if (digAbove)
                                {
                                    possibleBoardTiles.Add(i);
                                }
                            }
                            else
                            {
                                possibleBoardTiles.Add(i);
                            }
                        }
                    }

                    // -- Create Tileset --
                    int       tileIndex = possibleBoardTiles[Random.Range(0, possibleBoardTiles.Count)];
                    BoardTile prefab    = tilesetLibrary[tileIndex];
                    Vector3   position  = new Vector3(boardOriginPosition.x + (prefab.size.x * 0.5f) + (prefab.size.x * x),
                                                      boardOriginPosition.y - (prefab.size.y * 0.5f) - (prefab.size.y * y), 0);

                    BoardTile newTile = Instantiate(prefab, position, prefab.transform.rotation, boardOrigin);
                    tiles[x, y] = newTile;

                    // -- Remember last Tile --
                    previousLeft[y] = tileIndex;

                    if (y > 0)
                    {
                        previousLeftAbove[y - 1] = tileIndex;
                    }

                    previousAbove = tileIndex;
                }
            }

            // --- Check Playability ---
            if (!CheckBoardPlayable())
            {
                RecreateBoard();
            }
        }
Пример #4
0
 public void InitializeBoard(SceneSettings sceneSettings)
 {
     this.boardProfile = sceneSettings.boardProfile;
     this.boardOrigin  = sceneSettings.boardOrigin;
 }