Esempio n. 1
0
    public override bool TryToMoveTile(AbstractTile srcTile, AbstractTile dstTile)
    {
        if (srcTile == dstTile || srcTile == null || dstTile == null)
        {
            return(false);
        }

        if (CanMoveTile(srcTile, dstTile.BoardPiece))
        {
            Match3Tile srcMatch3Tile = srcTile as Match3Tile;
            Match3Tile dstMatch3Tile = dstTile as Match3Tile;

            if (OnUserStartedTilesSwitch != null)
            {
                OnUserStartedTilesSwitch(srcMatch3Tile, dstMatch3Tile);
            }

            srcMatch3Tile.RaiseEventTileTappedFirst();

            srcMatch3Tile.IsTileSwitching = true;
            dstMatch3Tile.IsTileSwitching = true;
            BoardAnimations.SwitchTilesAnim(true, srcMatch3Tile, dstMatch3Tile);

            return(true);
        }

        return(false);
    }
Esempio n. 2
0
    public void OnTilesSwitchAnimFinished(AbstractBoardAnimations sender, AbstractTile srcTile, AbstractTile dstTile)
    {
//		Debug.Log("Switch anim finished!");
        // Update the board positions of the animated tiles (update the board logic after the animation finishes).
        boardData.SwitchTiles(srcTile, dstTile);

        Match3Tile srcMatch3Tile = srcTile as Match3Tile;
        Match3Tile dstMatch3Tile = dstTile as Match3Tile;

        bool foundMatches = matchesFinder.FindMatches();

        if ((!foundMatches || (!srcMatch3Tile.IsMatched && !dstMatch3Tile.IsMatched)) &&
            (srcMatch3Tile.SwitchBackOnMatchFail && dstMatch3Tile.SwitchBackOnMatchFail))
        {
            if (OnUserTilesSwitchBad != null)
            {
                OnUserTilesSwitchBad(srcMatch3Tile, dstMatch3Tile);
            }

            srcMatch3Tile.IsTileSwitching = true;
            dstMatch3Tile.IsTileSwitching = true;

            BoardAnimations.SwitchTilesAnim(false, srcMatch3Tile, dstMatch3Tile,
                                            (_sender, _srcTile, _dstTile) =>
            {
                boardData.SwitchTiles(_srcTile, _dstTile);
                _srcTile.IsTileSwitching = false;
                _dstTile.IsTileSwitching = false;
            }
                                            );

            srcMatch3Tile.RaiseEventSwitchBackOnFail(dstMatch3Tile);
            dstMatch3Tile.RaiseEventSwitchBackOnFail(srcMatch3Tile);
        }
        else if (srcMatch3Tile.IsMatched || dstMatch3Tile.IsMatched)
        {
            srcMatch3Tile.IsTileSwitching = false;
            dstMatch3Tile.IsTileSwitching = false;

            loseConditions.NewMove();

            srcMatch3Tile.RaiseEventSwitchSuccess(dstMatch3Tile);
            dstMatch3Tile.RaiseEventSwitchSuccess(srcMatch3Tile);
        }
        else if (!srcMatch3Tile.SwitchBackOnMatchFail || !dstMatch3Tile.SwitchBackOnMatchFail)
        {
            // Reset the "IsTileSwitching" property for tiles that don't switch back on match fail because they finished their switch animation.
            srcMatch3Tile.IsTileSwitching = false;
            dstMatch3Tile.IsTileSwitching = false;
        }

        DestroyLastFoundMatches();
    }