Exemple #1
0
    public bool CheckMerge()
    {
        //Checks if a merge should happen and enacts it

        //gets all pieces of the current player
        Character[] pieces = GameData.GetCurrPlayer().GetPieces();
        //gets position of the active piece
        Vector3 activePosition = GameData.GetActivePiece().transform.position;
        //gets the active piece
        Character activePiece = GameData.GetActivePiece();
        //the position of the starting tile
        Vector3 startPosition = GetStartTile().transform.position;


        //checks every piece of the current player for a merge
        foreach (Character piece in pieces)
        {
            //merges cannot occure at start or with a piece and itself
            if (activePiece.GetCurrTile() != GetStartTile() && !piece.Equals(activePiece) && !piece.Equals(GetFinishTile()) &&
                piece.GetCurrTile() == activePiece.GetCurrTile())
            {
                //adjusting the size of the character after the merge
                int prevSize = activePiece.GetSize();
                activePiece.AdjustSize(piece.GetSize());

                //remove one of the pieces after the merge
                piece.gameObject.SetActive(false);
                GameData.GetCurrPlayer().RemovePiece(piece);

                //adjusting the visual size of the piece
                activePiece.transform.localScale = activePiece.GetSize() / prevSize * activePiece.transform.localScale;

                //show merge screen for explanation
                GameGUI.ShowMergeScreen(activePiece.GetCurrTile());
                return(true);
            }
        }

        return(false);
    }