コード例 #1
0
ファイル: PuzzleEffectControl.cs プロジェクト: pb0/ID0_Test
    public void ShowAll()
    {
        OverlapChecker matrix = new OverlapChecker(PuzzleOption.BlockCountX, PuzzleOption.BlockCountY);

        foreach (var entity in inARowHorizontal)
        {
            int effectWidth = 3;
            int effectHeight = 1;
            int blockCount = entity.pattern.Count;

            float centerX = entity.x + (entity.pattern.width - 1) / 2f;
            float centerY = entity.y + (entity.pattern.height - 1) / 2f;
            AdjustEffectPos(matrix, effectWidth, effectHeight, blockCount, ref centerX, ref centerY);

            matrix.IncreaseOverlap(effectWidth, effectHeight, centerX, centerY);
            panel.AttachChild(UIEffectInARow.Create(blockCount), new Vector2(centerX, centerY), 1f);
        }

        foreach (var entity in inARowVertical)
        {
            int effectWidth = 3;
            int effectHeight = 1;
            int blockCount = entity.pattern.Count;

            float centerX = entity.x + (entity.pattern.width - 1) / 2f;
            float centerY = entity.y + (entity.pattern.height - 1) / 2f;
            AdjustEffectPos(matrix, effectWidth, effectHeight, blockCount, ref centerX, ref centerY);

            matrix.IncreaseOverlap(effectWidth, effectHeight, centerX, centerY);
            panel.AttachChild(UIEffectInARow.Create(blockCount), new Vector2(centerX, centerY), 1f);
        }

        // chains
        if (chainCount >= 3)
        {
            int effectWidth = 3;
            int effectHeight = 1;
            
            int minOverlap = int.MaxValue;
            float minOverlapX = 0;
            float minOverlapY = 0;
            foreach (var entity in matches)
            {
                int blockCount = entity.pattern.Count;
                float centerX = entity.x + (entity.pattern.width - 1) / 2f;
                float centerY = entity.y + (entity.pattern.height - 1) / 2f;
                AdjustEffectPos(matrix, effectWidth, effectHeight, blockCount, ref centerX, ref centerY);

                int overlap = matrix.GetOverlap(effectWidth, effectHeight, centerX, centerY);
                if (minOverlap > overlap)
                {
                    minOverlap = overlap;
                    minOverlapX = centerX;
                    minOverlapY = centerY;
                }
            }
            matrix.IncreaseOverlap(effectWidth, effectHeight, minOverlapX, minOverlapY);
            panel.AttachChild(UIEffectChain.Create(chainCount), new Vector2(minOverlapX, minOverlapY), 1f);
        }

        // multi-matches
        if (matches.Count >= 3)
        {
            int effectWidth = 2;
            int effectHeight = 1;

            int minOverlap = int.MaxValue;
            float minOverlapX = 0;
            float minOverlapY = 0;
            foreach (var entity in matches)
            {
                int blockCount = entity.pattern.Count;
                float centerX = entity.x + (entity.pattern.width - 1) / 2f;
                float centerY = entity.y + (entity.pattern.height - 1) / 2f;
                AdjustEffectPos(matrix, effectWidth, effectHeight, blockCount, ref centerX, ref centerY);

                int overlap = matrix.GetOverlap(effectWidth, effectHeight, centerX, centerY);
                if (minOverlap > overlap)
                {
                    minOverlap = overlap;
                    minOverlapX = centerX;
                    minOverlapY = centerY;
                }
            }
            matrix.IncreaseOverlap(effectWidth, effectHeight, minOverlapX, minOverlapY);
            panel.AttachChild(UIEffectMatch.Create(matches.Count), new Vector2(minOverlapX, minOverlapY), 1f);
        }

        // for test
        //matrix.DumpMatrix();
        //Debug.Break();
    }
コード例 #2
0
ファイル: PuzzleEffectControl.cs プロジェクト: pb0/ID0_Test
    private static float AdjustEffectPosY(OverlapChecker matrix, int effectWidth, int effectHeight, int blockCount, float centerX, float centerY)
    {
        int minOverlap = int.MaxValue;
        int minOverlapY = 0;
        for (int i = 0; i < blockCount + 4; i++)    // +-2 of block range
        {
            float gap = (i + 1) / 2;
            float y = centerY + (IsEven(i) ? -gap : gap);
            int intY = Mathf.FloorToInt(y);
            if (0 <= intY && intY < PuzzleOption.BlockCountY)
            {
                int overlap = matrix.GetOverlap(effectWidth, effectHeight, centerX, intY);

                if (overlap < minOverlap)
                {
                    minOverlap = overlap;
                    minOverlapY = intY;
                }

                if (overlap == 0)
                {
                    break;
                }
            }
        }
        centerY = minOverlapY;
        return centerY;
    }