示例#1
0
    public TileController[,] GenerateBoard(TileBoardController boardController)
    {
        // Spawn all the tiles randomly in the appropriate locations, while making sure there aren't too
        // many with the same type in a line.
        Vector3Int     location = Vector3Int.zero;
        TileController newTile  = null;

        for (int column = 0; column < numOfColumns; column++)
        {
            for (int row = 0; row < numOfRows; row++)
            {
                location.Set(column, row, 0);
                newTile                   = SpawnTileAt(location, boardController);
                newTile.BoardPos          = new Vector2Int(column, row);
                spawnedTiles[column, row] = newTile;

                if (backgroundTile != null)
                {
                    SpawnBackgroundTile(location);
                }
            }
        }

        return(spawnedTiles);
    }
    void SwapRegisteredBoardsBetween(TileController firstTile, TileController secondTile)
    {
        TileBoardController firstTilesBoard = firstTile.Board;

        firstTile.Board  = secondTile.Board;
        secondTile.Board = firstTilesBoard;
    }
示例#3
0
 protected virtual void Awake()
 {
     tileBoard = FindObjectOfType <TileBoardController>();
     TileController.AnyClicked += OnAnyTileClicked;
     swapDurationVar            = tileSwapVals.GetVariable("swapDuration") as FloatVariable;
     swapEnabledVar             = tileSwapVals.GetVariable("swapEnabled") as BooleanVariable;
     cancelAxisVar              = tileSwapVals.GetVariable("cancelAxis") as StringVariable;
     airTileVar           = gameVals.GetVariable("airTileType") as ObjectVariable;
     AnyPhysicalSwapMade += this.OnAnyPhysicalSwapMade;
 }
示例#4
0
 void HighlightTilesInBoard(TileBoardController board)
 {
     for (int x = 0; x < board.ColumnCount; x++)
     {
         for (int y = 0; y < board.RowCount; y++)
         {
             TileController tile           = board.Tiles[x, y];
             Transform      newHighlighter = SetupHighlighter();
             PlaceHighlighterOnTile(newHighlighter, tile);
             RegisterTileAsHighlighted(tile);
         }
     }
 }
示例#5
0
    TileController SpawnTileAt(Vector3Int boardCoord, TileBoardController boardTileIsFor)
    {
        // Generate a random number to decide which tile should be spawned, to go with
        // how each tile type has its own probability of being assigned to a tile
        float   randNum  = Random.Range(0f, 100f) / 10f;
        Vector3 localPos = (Vector3)boardCoord * adjustedBFootprint;

        bool done = false;

        while (!done)
        {
            foreach (GridUnit tile in Tiles)
            {
                if (randNum < tile.adjustedProbability)
                {
                    /* Although functional, this is wasteful on resources */
                    //if (RedundancyCheckTrue(boardCoord, Direction.All, maxInLine, tile)) { continue; }

                    // Checks for horizontal redundancy
                    if (RedundancyCheckTrue(boardCoord, Direction.Left, maxInLine, tile))
                    {
                        continue;
                    }

                    // Checks for vertical redundancy
                    if (RedundancyCheckTrue(boardCoord, Direction.Down, maxInLine, tile))
                    {
                        continue;
                    }

                    // If not redundant, creates a new tile
                    TileController newTile = Instantiate(tileSettings.baseTilePrefab, Vector3.zero,
                                                         Quaternion.identity);
                    newTile.transform.SetParent(tileHolder);
                    newTile.transform.localPosition = localPos;
                    newTile.Type  = tile.Type;
                    newTile.Board = boardTileIsFor;
                    done          = true;
                    return(newTile);
                }
            }
            // If end of tile list is reached, start from beginning of list
            if (randNum >= 10)
            {
                randNum -= 10;
            }

            // Failsafe for corner cases regarding bad initialization
            if (tileTypes.Count - 1 < Tiles.Count)
            {
                done = true;
            }
        }

        // If somehow everything fails from empty list of Tiles
        TileController newAltTile = Instantiate(tileSettings.baseTilePrefab, Vector3.zero,
                                                Quaternion.identity, tileHolder);

        newAltTile.transform.SetParent(tileHolder);
        newAltTile.transform.localPosition = localPos;
        newAltTile.Type  = Tiles[0].Type;
        newAltTile.Board = boardTileIsFor;
        return(newAltTile);
    }
示例#6
0
 bool IsOtherBoard(TileBoardController board)
 {
     return(board != centerTile.Board);
 }