Пример #1
0
    private List <AnimalItem> GetVerticalMatch(AnimalItem item)
    {
        List <AnimalItem> matchList = new List <AnimalItem>();

        matchList.Add(item);
        for (int i = item.y - 1; i >= 0; i--)
        {
            if (gridAnimalItems[item.x, i].GetRenderer().sprite == item.GetRenderer().sprite)
            {
                matchList.Add(gridAnimalItems[item.x, i]);
            }
            else
            {
                break;
            }
        }
        for (int i = item.y + 1; i < ySize; i++)
        {
            if (gridAnimalItems[item.x, i].GetRenderer().sprite == item.GetRenderer().sprite)
            {
                matchList.Add(gridAnimalItems[item.x, i]);
            }
            else
            {
                break;
            }
        }
        return(matchList);
    }
Пример #2
0
    private void InitGrid(float offsetX, float offsetY)
    {
        float startX = transform.position.x;
        float startY = transform.position.y;

        for (int x = 0; x < xSize; x++)
        {
            for (int y = 0; y < ySize; y++)
            {
                AnimalItem newItem = null;
                if (!gridAnimalItems[x, y])
                {
                    newItem = Instantiate(tile, new Vector3(startX + (offsetX * x), startY + (offsetY * y), transform.position.z), tile.transform.rotation);
                }
                else
                {
                    newItem = gridAnimalItems[x, y];
                }
                gridAnimalItems[x, y]   = newItem;
                gridAnimalItems[x, y].x = x;
                gridAnimalItems[x, y].y = y;
                newItem.transform.SetParent(transform);
                newItem.GetRenderer().sprite = itemSprites[Random.Range(0, itemSprites.Count)];
                while (isNeedFix(newItem))
                {
                    newItem.GetRenderer().sprite = itemSprites[Random.Range(0, itemSprites.Count)];
                }
            }
        }
    }
Пример #3
0
    private List <AnimalItem> GetHorizaontalMatch(AnimalItem item)
    {
        List <AnimalItem> matchList = new List <AnimalItem>();

        matchList.Add(item);
        for (int i = item.x - 1; i >= 0; i--)
        {
            if (gridAnimalItems[i, item.y].GetRenderer().sprite == item.GetRenderer().sprite)
            {
                matchList.Add(gridAnimalItems[i, item.y]);
            }
            else
            {
                break;
            }
        }
        for (int i = item.x + 1; i < xSize; i++)
        {
            if (gridAnimalItems[i, item.y].GetRenderer().sprite == item.GetRenderer().sprite)
            {
                matchList.Add(gridAnimalItems[i, item.y]);
            }
            else
            {
                break;
            }
        }
        return(matchList);
    }
Пример #4
0
 private void SwapAnimal(AnimalItem item)
 {
     if (IsNeighbor(item))
     {
         Sprite swapSprite = firstItemSelected.GetRenderer().sprite;
         firstItemSelected.GetRenderer().sprite = item.GetRenderer().sprite;
         item.GetRenderer().sprite           = swapSprite;
         List <List <AnimalItem> > matchList = new List <List <AnimalItem> >();
         matchList.Add(GetVerticalMatch(firstItemSelected));
         matchList.Add(GetHorizaontalMatch(firstItemSelected));
         matchList.Add(GetVerticalMatch(item));
         matchList.Add(GetHorizaontalMatch(item));
         bool foundMatch = false;
         for (int i = 0; i < matchList.Count; i++)
         {
             if (matchList[i].Count >= minMatch)
             {
                 foundMatch = true;
                 ClearMatches(matchList[i]);
             }
         }
         if (foundMatch)
         {
             if (helpItemIsActive)
             {
                 StopAllCoroutines();
                 ReRotateItem(helpAnimalItem);
                 helpItemIsActive = false;
             }
             FillingBoard();
             timerHelp = 0;
         }
         else
         {
             SfxPlayHandler(SfxEffect.CantSwap);
             swapSprite = firstItemSelected.GetRenderer().sprite;
             firstItemSelected.GetRenderer().sprite = item.GetRenderer().sprite;
             item.GetRenderer().sprite = swapSprite;
         }
         Deselect(firstItemSelected);
     }
     else
     {
         SfxPlayHandler(SfxEffect.CantSwap);
         Deselect(firstItemSelected);
     }
 }
Пример #5
0
    private bool CanSwap(AnimalItem item, AnimalItem item2)
    {
        bool   can        = false;
        Sprite swapSprite = item2.GetRenderer().sprite;

        item2.GetRenderer().sprite = item.GetRenderer().sprite;
        item.GetRenderer().sprite  = swapSprite;
        if (GetVerticalMatch(item).Count >= minMatch || GetHorizaontalMatch(item).Count >= minMatch || GetHorizaontalMatch(item2).Count >= minMatch || GetVerticalMatch(item2).Count >= minMatch)
        {
            can = true;
        }
        else
        {
            can = false;
        }
        swapSprite = item2.GetRenderer().sprite;
        item2.GetRenderer().sprite = item.GetRenderer().sprite;
        item.GetRenderer().sprite  = swapSprite;
        return(can);
    }
Пример #6
0
    IEnumerator RotateForHelp(AnimalItem item)
    {
        helpAnimalItem   = item;
        helpItemIsActive = true;
        float deltaAngle = 5f;
        float maxAngle   = 20f;

        for (float angle = 0; angle <= maxAngle; angle += deltaAngle)
        {
            item.GetRenderer().transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
            yield return(new WaitForSeconds(.05f));
        }
        for (float angle = maxAngle; angle >= -maxAngle; angle -= deltaAngle)
        {
            item.GetRenderer().transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
            yield return(new WaitForSeconds(.05f));
        }
        for (float angle = -maxAngle; angle <= 0; angle += deltaAngle)
        {
            item.GetRenderer().transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
            yield return(new WaitForSeconds(.05f));
        }
        helpItemIsActive = false;
    }
Пример #7
0
 private void ReRotateItem(AnimalItem item)
 {
     item.GetRenderer().transform.rotation = Quaternion.identity;
 }
Пример #8
0
 private void Deselect(AnimalItem item)
 {
     item.GetRenderer().color = Color.white;
     firstItemSelected = null;
 }
Пример #9
0
 private void Select(AnimalItem item)
 {
     item.GetRenderer().color = selectedColor;
     firstItemSelected = item;
     SfxPlayHandler(SfxEffect.Select);
 }