public Match3Tile SpawnTileAt(int rowIdx, int columnIdx, bool offBoardTile = false, bool noLockedTiles = false, bool isBoardSetup = false)
    {
        int rand;

        if (noLockedTiles)
        {
            //TODO: temporary spawn hack to spawn only new normal tiles on the board.
            rand = Random.Range(0, 6);             //a normal tile
        }
        else
        {
            rand = Random.Range(0, 100);             // current chance for locked tile is 6/100 = 6%
            if (rand < 6)
            {
                rand += 6;                 //a locked tile
            }
            else
            {
                rand = Random.Range(0, 6);                 //a normal tile
            }
        }

        Match3Tile newTilePrefab = tilesPrefabs[rand].GetComponent <Match3Tile>();

        return(SpawnSpecificTileAt(rowIdx, columnIdx, newTilePrefab.GetType(), newTilePrefab.TileColor, offBoardTile, isBoardSetup));
    }
	protected void OnAnyTileDestroyedEvent(Match3Tile tile)
	{
		if(tile.GetType() == typeof(NormalTile))
		{
			tileColorCount[(int)tile.TileColor]--;
			tileTotalCount--;
			colorProbability[genericColorsIndexes[(int)tile.TileColor]] = 1f - (tileTotalCount == 0 ? 0f : tileColorCount[(int)tile.TileColor] / tileTotalCount);
		}
	}
示例#3
0
 protected void OnAnyTileDestroyedEvent(Match3Tile tile)
 {
     if (tile.GetType() == typeof(NormalTile))
     {
         tileColorCount[(int)tile.TileColor]--;
         tileTotalCount--;
         colorProbability[genericColorsIndexes[(int)tile.TileColor]] = 1f - (tileTotalCount == 0 ? 0f : tileColorCount[(int)tile.TileColor] / tileTotalCount);
     }
 }
//	public override void RaiseBoardFinishedSetupEvent ()
//	{
//		base.RaiseBoardFinishedSetupEvent();
//
//		BoardTilesInitializer initializer = new BoardTilesInitializer(Board);
//		initializer.Initialize();
//	}

    /// <summary>
    /// Setup the board tiles prefabs specified in the <see cref="tilesPrefabs"/> array,
    /// based on their type and color for quick access at run-time.
    /// </summary>
    public override void SetupBoardTiles()
    {
        tilesDictionary = new TilesDictionary();

        for (int i = 0; i < tilesPrefabs.Length; i++)
        {
            Match3Tile tile = tilesPrefabs[i].GetComponent <Match3Tile>();
            tilesDictionary[tile.GetType(), tile.TileColor] = tile;
        }
    }
	protected void OnTileAttachedToBoardEvent(Match3Tile tile)
	{
//		Debug.LogError("[Spawner]++");
		if(tile.GetType() == typeof(NormalTile))
		{	
			tileTotalCount++;
			tileColorCount[(int)tile.TileColor]++;
			colorProbability[genericColorsIndexes[(int)tile.TileColor]] = 1f - (tileTotalCount == 0 ? 0f : tileColorCount[(int)tile.TileColor] / tileTotalCount);
		}
	}
示例#6
0
    protected void OnTileAttachedToBoardEvent(Match3Tile tile)
    {
//		Debug.LogError("[Spawner]++");
        if (tile.GetType() == typeof(NormalTile))
        {
            tileTotalCount++;
            tileColorCount[(int)tile.TileColor]++;
            colorProbability[genericColorsIndexes[(int)tile.TileColor]] = 1f - (tileTotalCount == 0 ? 0f : tileColorCount[(int)tile.TileColor] / tileTotalCount);
        }
    }
    public override void RaiseEventTileSwitchAnimBegan(Match3Tile _neighborTile)
    {
        base.RaiseEventTileSwitchAnimBegan(_neighborTile);

        //One of the few cases were the color bomb swipe is invalid and a switchback is required
        if (!lastNeighborTile.IsDestructible)
        {
            SwitchBackOnMatchFail = true;
            return;
        }

        destroyColor = lastNeighborTile.TileColor;

        // Disable colliders for this tile and it's neighbor tile if the neighbor is a ColorBomb tile.
        // Because these will do a combine effect and they shouldn't be picked up by other destroy sensors in the meantime.
        if (lastNeighborTile is ColorBombTile)
        {
            DisableTileLogic();
            lastNeighborTile.DisableTileLogic();
        }

        // Cached the "TappedFirst" property here for this tile because it will be reset in "RaiseEventTileSwitchAnimEnded" event.
        wasFirstTapped = TappedFirst;

        if (lastNeighborTile is DirectionalDestroyTile)
        {
            lastNeighborTile.CanBeMatched = false;
        }

        if (lastNeighborTile is BombTile)
        {
            lastNeighborTile.CanBeMatched = false;
        }

        if (_neighborTile.GetType() == typeof(NormalTile) /* && wasFirstTapped*/)
        {
            (_neighborTile as NormalTile).CanBeMatched = false;
            if (!wasFirstTapped)
            {
                Match3BoardGameLogic.Instance.loseConditions.NewMove();
            }
        }
    }
示例#8
0
    IEnumerator FreeFall()
    {
        freeFalling = true;

        yield return(StartCoroutine(DestroyAllTriggerTiles()));

        LoseMoves loseConditionMoves = loseConditions as LoseMoves;

        if (loseConditionMoves == null || loseConditionMoves.RemainingMoves == 0)
        {
            OnStableBoard += FreeFallFinished;
            IsBoardStable  = false;
            TryCheckStableBoard();
            yield break;
        }

        List <Match3BoardPiece> allNormalBoardPieces = new List <Match3BoardPiece>();
        SoundEffectController   sndDirectionalCreate = SoundManager.Instance["winter_create_sfx"];

        float waitTime = 0.5f;

        while (loseConditionMoves.RemainingMoves > 0)
        {
            if (callFreeFallEvent)
            {
                callFreeFallEvent = false;
                OnFreeFall.RaiseEvent();

                yield return(new WaitForSeconds(1.5f));
            }

            yield return(new WaitForSeconds(waitTime));

            waitTime = Mathf.Clamp(waitTime - 0.03f, 0.03f, 0.5f);

            allNormalBoardPieces.Clear();

            boardData.ApplyActionToAll((boardPiece) => {
                Match3Tile tile = boardPiece.Tile as Match3Tile;
                if (tile != null && !tile.IsMoving && tile.IsDestructible && !tile.IsDestroying && tile.GetType() == typeof(NormalTile))
                {
                    allNormalBoardPieces.Add(boardPiece as Match3BoardPiece);
                }
            });

            loseConditions.NewMove();
            loseConditionMoves.RemainingMoves--;             //because the lose condition is paused at this time

            if (allNormalBoardPieces.Count <= 0)
            {
                continue;
            }

            int index = Random.Range(0, allNormalBoardPieces.Count);
            Match3BoardPiece chosenPiece = allNormalBoardPieces[index];
            Match3Tile       chosenTile  = chosenPiece.Tile as Match3Tile;
            allNormalBoardPieces.RemoveAt(index);

            chosenPiece.Tile = (boardRenderer as Match3BoardRenderer).SpawnSpecificTileAt(chosenPiece.BoardPosition.row,
                                                                                          chosenPiece.BoardPosition.col, (Random.Range(0, 2) == 0) ? typeof(RowDestroyTile) : typeof(ColumnDestroyTile), TileColorType.None);
            (chosenPiece.Tile as Match3Tile).TileColor = chosenTile.TileColor;
            (chosenPiece.Tile as DirectionalDestroyTile).UpdateMaterial();
            Destroy(chosenTile.gameObject);
            ScoreSystem.Instance.AddScore(TweaksSystem.Instance.intValues["MovesScoreMultiplier"], false);

            SoundManager.Instance.PlayOneShot(sndDirectionalCreate);

            if (loseConditionMoves.RemainingMoves == 0)
            {
                break;
            }

            TryCheckStableBoard();
        }

        yield return(new WaitForSeconds(1f));

        yield return(StartCoroutine(DestroyAllTriggerTiles()));

        OnStableBoard += FreeFallFinished;
        IsBoardStable  = false;
        TryCheckStableBoard();
    }
	public override void RaiseEventTileSwitchAnimBegan(Match3Tile _neighborTile) 
	{
		base.RaiseEventTileSwitchAnimBegan(_neighborTile);
		
		//One of the few cases were the color bomb swipe is invalid and a switchback is required
		if(!lastNeighborTile.IsDestructible) {
			SwitchBackOnMatchFail = true;
			return;
		}
		
		destroyColor = lastNeighborTile.TileColor;

		// Disable colliders for this tile and it's neighbor tile if the neighbor is a ColorBomb tile.
		// Because these will do a combine effect and they shouldn't be picked up by other destroy sensors in the meantime.
		if (lastNeighborTile is ColorBombTile) {
			DisableTileLogic();
			lastNeighborTile.DisableTileLogic();
		}
		
		// Cached the "TappedFirst" property here for this tile because it will be reset in "RaiseEventTileSwitchAnimEnded" event.
		wasFirstTapped = TappedFirst;
		
		if(lastNeighborTile is DirectionalDestroyTile) {
			lastNeighborTile.CanBeMatched = false;
		}
		
		if(lastNeighborTile is BombTile) {
			lastNeighborTile.CanBeMatched = false;
		}
		
		if(_neighborTile.GetType() == typeof(NormalTile)/* && wasFirstTapped*/)
		{
			(_neighborTile as NormalTile).CanBeMatched = false;
			if ( !wasFirstTapped ) 
			{
				Match3BoardGameLogic.Instance.loseConditions.NewMove();
			}
		}	
	}