Esempio n. 1
0
    // slides a tile in given SlideController.Direction
    // returns true if the tile slides into a match, false otherwise
    public bool Slide(SlideController.Direction dir)
    {
        GridPosition myPos  = transform.parent.gameObject.GetComponent <GridPosition>();
        GridPosition newPos = myPos.GetNext(dir);

        if (newPos)
        {
            RectTransform newCell = newPos.GetComponent <RectTransform>();
            if (newCell.childCount < 1) // if there isn't a tile in the next cell
            {
                ChangeParent(newCell);
            }
            else if (newCell.GetComponentInChildren <DrugTile>() && CheckMatch(newCell.GetComponentInChildren <DrugTile>())) // if there is a tile and they match
            {
                Instantiate(matchParticles, newCell.position - new Vector3(0, 0, 20), Quaternion.identity);
                ChangeParent(newCell);
                foreach (Transform child in newCell)
                {
                    controller.tilesOnScreen.Remove(child.GetComponent <DrugTile>()); //remove this tile from the list of active tiles
                    child.GetComponent <DrugTile>().markedToDestroy = true;
                }
                StartCoroutine(Wait(newCell));
                return(true);
            }
        }
        return(false);
    }
Esempio n. 2
0
    // returns true if the tile can slide in the given direction, false otherwise
    public bool CanSlide(SlideController.Direction dir)
    {
        GridPosition myPos  = transform.parent.gameObject.GetComponent <GridPosition>();
        GridPosition newPos = myPos.GetNext(dir);

        if (newPos)
        {
            RectTransform newCell = newPos.GetComponent <RectTransform>();
            if (newCell.childCount < 1) // if there isn't a tile in the next cell
            {
                return(true);
            }
            else if (newCell.GetComponentInChildren <DrugTile>() && CheckMatch(newCell.GetComponentInChildren <DrugTile>())) // if there is a tile and they match
            {
                return(true);
            }
        }
        return(false);
    }