层次效果未解决 望高人解答
先往窗体托个圆形 就是ovalshape
然后把代码粘贴上去就能运行了
下面是下载地址
http://download.csdn.net/detail/xiaoshenyi2/4125059

解决方案 »

  1.   

    using System;
    using System.Drawing;
    using System.Windows.Forms;
    using Microsoft.VisualBasic.PowerPacks;namespace 围棋2//解决方案 使用数组解决问题 :将相邻的子放进一个数组 然后判断这些子的气 如果所有子的气为0 则遍历吃掉这些子
    {
        public partial class Form1 : Form
        {
            int[,] ai = new int[13, 13];//存数据的
            int[] bi = new int[100];//存黑棋和白棋
            int[] cc = new int[100];//分组存的
            static int bo = 0;//设置谁下
            ShapeContainer sh = new ShapeContainer();//画棋盘的容器
            const int f = 30, f2 = 40;//设置常量
            public Form1()
            {
                Text = "围棋--作者:彳亍乐儿";
                StartPosition = FormStartPosition.CenterScreen;
                BackColor = Color.Gray;
                Size = new Size(580, 590);
                Controls.Add(sh);
                KeyPreview = true;
                MouseDown += new MouseEventHandler(md);//布局
                for (int y = 1, x = 1, x2 = 13; y < 14; y++)//这个循环用来画棋盘
                {
                    LineShape a = new LineShape(x * f2, y * f2, x2 * f2, y * f2);
                    LineShape b = new LineShape(y * f2, x * f2, y * f2, x2 * f2);
                    a.Tag = b.Tag = 10000;
                    a.Enabled = b.Enabled = false;//这一步很重要
                    sh.Shapes.AddRange(new Shape[] { a, b });
                }
            }
            private void md(object sender, MouseEventArgs e)//鼠标点击事件
            {
                int d = dingwei(e.Location);
                if (d != 0)
                {
                    bo++;
                    OvalShape a = new OvalShape();
                    a.Size = new Size(f, f);
                    a.Location = new Point(d / 100 * f2 - f / 2, d % 100 * f2 - f / 2);
                    a.BackStyle = BackStyle.Opaque;
                    a.Tag = d-101;
                    if (bo % 2 == 0)
                    {
                        a.BackColor = Color.White;
                        panduan(1);
                    }
                    else
                        a.BackColor = Color.Black;
                    sh.Shapes.Add(a);
                    panduan(2);
                    panduan(1);
                }
            }
            int dingwei(Point p)//定位判断
            {
                for (int a = 1; a < 14; a++)
                    for (int b = 1; b < 14; b++)
                        if (Math.Abs(p.X - a * f2) < 15 && Math.Abs(p.Y - b * f2) < 15)
                        {
                            ai[a - 1, b - 1] = bo % 2 + 1;
                            return a * 100 + b;
                        }
                return 0;
            }
            void panduan(int h)
            {
                int b2=0;
                for (int i = 0; i < 13; i++)
                    for (int l = 0; l < 13; l++)
                        if (ai[i, l] == h)
                            bi[b2++] = i * 100 + l;//麻烦了点 还是弄到了所有黑子的坐标
                for (int i = 0; i < 100; i++)
                    cc[i] = 0;
                int t = 1;
                for (int i = 0; i < b2; i++)
                    if (cc[i] == 0)
                    {
                        cc[i] = t++;
                        xunzhao(bi[i], t - 1,b2);//将其分组
                    }
                for (int i = 1; i < t; i++)
                    zhaoqi(i, b2);         
            }
            void xunzhao(int x, int y, int z)//寻找 - -!强大的调用自己 第一次用
            {
                for (int i = 0; i < z; i++)
                    if (cc[i] != y)
                        if (x + 1 == bi[i] || x - 1 == bi[i] || x + 100 == bi[i] || x - 100 == bi[i])
                        {
                            cc[i] = y;
                            xunzhao(bi[i], y,z);
                        }
            }
            void zhaoqi(int x,int z)//找一个区域的子的气 如果这个区域没有气 则扼杀这个区域的所有子 x代表区域的编号
            {
                int t=0;
                for(int i=0;i<z;i++)
                    if (cc[i] == x)
                    {
                        if (bi[i]/100!=12&&ai[bi[i] / 100+1, bi[i] % 100] == 0)
                            t++;
                        if (bi[i]/100!=0&&ai[bi[i] / 100 - 1, bi[i] % 100] == 0)
                            t++;
                        if (bi[i]%100!=12&&ai[bi[i] / 100 , bi[i] % 100+1] == 0)
                            t++;
                        if (bi[i]%100!=0&&ai[bi[i] / 100 , bi[i] % 100-1] == 0)
                            t++;
                    }
                if(t==0)//嘿嘿
                    for(int i=0;i<z;i++)
                        if (cc[i] == x)
                        {
                            chidiao(bi[i]);
                            ai[bi[i] / 100, bi[i] % 100] = 0;
                        }
            }
            void chidiao(int p)//测试无误
            {
                foreach (Shape i in sh.Shapes)
                    if (p.ToString() == i.Tag.ToString())
                    {
                        sh.Shapes.Remove(i);
                        break;//遍历中删除元素必须退出
                    }
            }
        }
    }