示例#1
0
    void MarkMatchTiles()
    {
        List <TileBehaviorVer2> neighbourTiles = new List <TileBehaviorVer2>();

        int xPos = Mathf.RoundToInt(transform.position.x);
        int yPos = Mathf.RoundToInt(transform.position.y);

        if (yPos <= 3)
        {
            TileBehaviorVer2 tileAbove = GridManagerVer2.instance.tile[xPos, yPos + 1];
            neighbourTiles.Add(tileAbove);
        }
        if (yPos >= 1)
        {
            TileBehaviorVer2 tileBelow = GridManagerVer2.instance.tile[xPos, yPos - 1];
            neighbourTiles.Add(tileBelow);
        }
        if (xPos <= 3)
        {
            TileBehaviorVer2 tileToright = GridManagerVer2.instance.tile[xPos + 1, yPos];
            neighbourTiles.Add(tileToright);
        }
        if (xPos >= 1)
        {
            TileBehaviorVer2 tileToleft = GridManagerVer2.instance.tile[xPos - 1, yPos];
            neighbourTiles.Add(tileToleft);
        }

        List <TileBehaviorVer2> matchTiles = new List <TileBehaviorVer2>();

        // how to use while loop to search all matched neighbours?
        for (int i = 0; i < neighbourTiles.Count; i++)
        {
            if (neighbourTiles[i].rend.sprite == rend.sprite)
            {
                matchTiles.Add(neighbourTiles[i]);
            }
        }

        if (matchTiles.Count >= 2)
        {
            inMatch = true;
            for (int i = 0; i < matchTiles.Count; i++)
            {
                matchTiles[i].inMatch = true;
            }
        }
    }
示例#2
0
 private void Deselect()
 {
     isSelected   = false;
     rend.color   = Color.white;
     prevSelected = null;
 }
示例#3
0
 private void Select()
 {
     isSelected   = true;
     rend.color   = selectedColor;
     prevSelected = gameObject.GetComponent <TileBehaviorVer2>();
 }
示例#4
0
 bool SameTileType(TileBehaviorVer2 tile1, TileBehaviorVer2 tile2)
 {
     return(tile1.rend.sprite == tile2.rend.sprite);
 }