コード例 #1
0
ファイル: Block.cs プロジェクト: Lidbera/3Match-Puzzle
    public void Click(int click)
    {
        if (!control.clickable || kind.Equals(BlockKind.WALL))
        {
            return;
        }

        if (click.Equals(1))
        {
            mat.color = new Color(1.5f, 1.5f, 1.5f);
            control.CallByBlock(1, this);
        }
        else if (click.Equals(2))
        {
            if (control.first == null)
            {
                return;
            }

            if (control.first.coord.x >= 0 && control.first.coord.y >= 0)
            {
                if (control.first.coord.IsJoin(coord))
                {
                    control.CallByBlock(2, this);
                }
            }
        }
    }
コード例 #2
0
    private List <Block> ExplodeTrigger(Coord[] coord)
    {
        //폭발 조건
        List <Block> explodelist = new List <Block>();

        int[] mxcount = new int[coord.Length], pxcount = new int[coord.Length];
        int[] mycount = new int[coord.Length], pycount = new int[coord.Length];

        for (int i = 0; i < coord.Length; i++)
        {
            if (batchedblocks[coord[i].x, coord[i].y] == null)
            {
                continue;
            }
            BlockKind kind = batchedblocks[coord[i].x, coord[i].y].Kind;

            int mx = coord[i].x - 1;
            while (mx >= 0 && mx < game.size.x)
            {
                if (batchedblocks[mx, coord[i].y] == null)
                {
                    break;
                }
                if (batchedblocks[mx, coord[i].y].Kind.Equals(kind) &&
                    !kind.Equals(BlockKind.WALL))
                {
                    mx--;
                    mxcount[i]++;
                }
                else
                {
                    break;
                }
            }

            int px = coord[i].x + 1;
            while (px >= 0 && px < game.size.x)
            {
                if (batchedblocks[px, coord[i].y] == null)
                {
                    break;
                }
                if (batchedblocks[px, coord[i].y].Kind.Equals(kind) &&
                    !kind.Equals(BlockKind.WALL))
                {
                    px++;
                    pxcount[i]++;
                }
                else
                {
                    break;
                }
            }

            int my = coord[i].y - 1;
            while (my >= 0 && my < game.size.y)
            {
                if (batchedblocks[coord[i].x, my] == null)
                {
                    break;
                }
                if (batchedblocks[coord[i].x, my].Kind.Equals(kind) &&
                    !kind.Equals(BlockKind.WALL))
                {
                    my--;
                    mycount[i]++;
                }
                else
                {
                    break;
                }
            }

            int py = coord[i].y + 1;
            while (py >= 0 && py < game.size.y)
            {
                if (batchedblocks[coord[i].x, py] == null)
                {
                    break;
                }
                if (batchedblocks[coord[i].x, py].Kind.Equals(kind) &&
                    !kind.Equals(BlockKind.WALL))
                {
                    py++;
                    pycount[i]++;
                }
                else
                {
                    break;
                }
            }
        }

        for (int i = 0; i < coord.Length; i++)
        {
            if (mxcount[i] + 1 + pxcount[i] >= 3)
            {
                ExplodeListAdd(coord[i], 0, 0, ref explodelist);
                for (int j = 1; j <= mxcount[i]; j++)
                {
                    ExplodeListAdd(coord[i], -j, 0, ref explodelist);
                }
                for (int j = 1; j <= pxcount[i]; j++)
                {
                    ExplodeListAdd(coord[i], j, 0, ref explodelist);
                }
            }
            if (mycount[i] + 1 + pycount[i] >= 3)
            {
                ExplodeListAdd(coord[i], 0, 0, ref explodelist);
                for (int j = 1; j <= mycount[i]; j++)
                {
                    ExplodeListAdd(coord[i], 0, -j, ref explodelist);
                }
                for (int j = 1; j <= pycount[i]; j++)
                {
                    ExplodeListAdd(coord[i], 0, j, ref explodelist);
                }
            }
        }

        if (explodelist.Count > 0)
        {
            return(explodelist);
        }
        else
        {
            return(null);
        }
    }