Esempio n. 1
0
    private IEnumerator CheckMatch3()
    {
        HashSet <Block>[] matchingBlocks = new HashSet <Block> [4];

        for (int i = 0; i < 4; i++)
        {
            Block block = Blocks[i];

            matchingBlocks[i] = new HashSet <Block>()
            {
                block
            };

            if (block.BlockDef.BlockType == BlockType.Bomb)
            {
                block.GetSurroundingNeighbors(matchingBlocks[i], 2f);
            }
            else
            {
                block.GetMatchingNeighbors(matchingBlocks[i]);
            }
        }

        for (int i = 0; i < 4; i++)
        {
            var matchSet = matchingBlocks[i];

            for (int j = i + 1; j < 4; j++)
            {
                if (matchingBlocks[j].Any(x => matchSet.Contains(x)))
                {
                    foreach (var item in matchingBlocks[j])
                    {
                        matchSet.Add(item);
                    }

                    matchingBlocks[j].Clear();
                }
            }
        }

        for (int i = 0; i < 4; i++)
        {
            var matchSet = matchingBlocks[i];

            if (matchSet.Count >= 3)
            {
                foreach (var block in matchSet)
                {
                    block.SetToBeDestroyed();
                }
            }
        }

        yield return(new WaitForSeconds(0.4f));

        for (int i = 0; i < 4; i++)
        {
            var matchSet = matchingBlocks[i];

            if (matchSet.Count >= 3)
            {
                if (matchSet.Any(x => x.BlockDef.BlockType == BlockType.Explosive))
                {
                    SoundPlayer.Play(ExplosiveSound);

                    var pointsDisplay = Instantiate(PointsDisplayPrefab, Blocks[i].transform.position, Quaternion.identity);

                    int points = ScoreManager.AddPoints(-matchSet.Count(x => x.BlockDef.BlockType == BlockType.Coin));

                    Health.RemoveHealth(points);
                    pointsDisplay.SetPointsText(points);
                }
                else if (matchSet.Any(x => x.BlockDef.BlockType == BlockType.Bomb))
                {
                    SoundPlayer.Play(BombSound);
                }
                else if (matchSet.Any(x => x.BlockDef.BlockType == BlockType.Coin))
                {
                    SoundPlayer.Play(CoinSound);

                    var pointsDisplay = Instantiate(PointsDisplayPrefab, Blocks[i].transform.position, Quaternion.identity);

                    int points = ScoreManager.AddPoints(matchSet.Count);

                    Health.AddHealth(points);
                    pointsDisplay.SetPointsText(points);
                }
                else
                {
                    SoundPlayer.Play(MatchedSound);
                }

                foreach (var block in matchSet)
                {
                    block.gameObject.transform.SetParent(null);
                    Destroy(block.gameObject);
                }
            }
        }

        //Board.Instance.MakeBlocksFall();

        ScoreManager.AddTetromino();

        if (ScoreManager.TetrominoCount % 15 == 0)
        {
            ScoreManager.AddLevel();
            FallDelay *= 0.6f;
        }

        TetrominoSpawner.Spawn();

        Destroy(gameObject);
    }
Esempio n. 2
0
    private void ChangeLevel()
    {
        switch (i)
        {
        case 0:
            if (scoreScript.myScore == 1)
            {
                i++;
            }
            break;

        case 1:
            if (scoreScript.myScore == 10)
            {
                BAM.ChangeMusic(BackPlay1);
                speed = 4f;
                scoreScript.AddLevel(2);
                i++;
            }
            break;


        case 2:
            if (scoreScript.myScore == 20)
            {
                speed = 5f;
                scoreScript.AddLevel(3);
                i++;
            }
            break;

        case 3:

            if (scoreScript.myScore == 35)
            {
                BAM.ChangeMusic(BackPlay2);
                speed = 6f;
                scoreScript.AddLevel(4);

                i++;
            }
            break;

        case 4:
            if (scoreScript.myScore == 55)
            {
                speed = 7.5f;
                scoreScript.AddLevel(5);
                i++;
            }
            break;

        case 5:
            if (scoreScript.myScore == 80)
            {
                BAM.ChangeMusic(BackPlay3);
                speed = 8.2f;
                scoreScript.AddLevel(6);
                i++;
            }
            break;

        case 6:
            if (scoreScript.myScore == 100)
            {
                BAM.ChangeMusic(BackPlay4);
                speed = 9.5f;
                scoreScript.AddLevel(7);
                i++;
            }
            break;

        case 7:
            if (scoreScript.myScore == 150)
            {
                speed = 11f;
                scoreScript.AddLevel(8);
            }
            break;
        }
    }