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; }
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; }
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); } } }
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); }
bool IsOtherBoard(TileBoardController board) { return(board != centerTile.Board); }