コード例 #1
0
    /// <summary>
    /// Destroys gem at the given location
    /// and performs actions according to its bonus
    /// </summary>
    /// <param name="x">X-pos of the gem to be destroyed</param>
    /// <param name="y">Y-pos of the gem to be destroyed</param>
    public int DestroyGem(int x, int y)
    {
        bool needToDestroy = true;
        int  localScore    = 0;

        if (grid[x, y].Gem.IsBonus())
        {
            switch (grid[x, y].Gem.Bonus)
            {
            case (int)ParamUnit.Bonus.METEOR:
                gu.ActivateMeteorBonus(x, y);
                localScore += pu.scoreUnit;
                break;

            case (int)ParamUnit.Bonus.SAME_COLOR:
                if (!bonusIsWorking)
                {
                    bonusIsWorking = true;
                    // Search for gems with the same color
                    int color = grid[x, y].Gem.Color;
                    for (int _x = 0; _x < gSizeX; _x++)
                    {
                        for (int _y = 0; _y < gSizeY; _y++)
                        {
                            if (!grid[_x, _y].IsEmpty() && grid[_x, _y].Gem.Color == color)
                            {
                                gu.DestroyGem(_x, _y, color);
                                localScore += DestroyGem(_x, _y);
                            }
                        }
                    }
                }
                localScore    += pu.scoreUnit;
                bonusIsWorking = false;
                break;

            case (int)ParamUnit.Bonus.ENERGY:
                IncreaseSuboptimal();
                localScore += pu.scoreUnit;
                break;

            case (int)ParamUnit.Bonus.ICE_1:
                needToDestroy        = false;
                grid[x, y].Gem.Bonus = (int)ParamUnit.Bonus.ICE_2;
                gu.RespawnGem(x, y, grid[x, y].Gem.Color, grid[x, y].Gem.Bonus);
                localScore += pu.scoreUnit / 2;
                break;

            case (int)ParamUnit.Bonus.ICE_2:
                needToDestroy        = false;
                grid[x, y].Gem.Bonus = (int)ParamUnit.Bonus.ICE_3;
                gu.RespawnGem(x, y, grid[x, y].Gem.Color, grid[x, y].Gem.Bonus);
                localScore += pu.scoreUnit / 2;
                break;

            case (int)ParamUnit.Bonus.ICE_3:
                needToDestroy        = false;
                grid[x, y].Gem.Bonus = (int)ParamUnit.Bonus.NONE;
                gu.RespawnGem(x, y, grid[x, y].Gem.Color, grid[x, y].Gem.Bonus);
                localScore += pu.scoreUnit / 2;
                break;
            }
        }

        if (needToDestroy)
        {
            if (grid[x, y].Gem != null)
            {
                if (colorsMetal.Contains(grid[x, y].Gem.Color))
                {
                    collectedMetal++;
                }
                if (colorsFuel.Contains(grid[x, y].Gem.Color))
                {
                    collectedFuel++;
                }
                localScore += pu.scoreUnit;
            }

            grid[x, y].Gem = null;
        }
        needToCheck = true;
        return(localScore);
    }