创建一个复选框矩阵
然后将所有的复选框都捆定到一个事件上
在事件响应中
判断当前所点击的Sender是哪一个复选框
比如有5*5灯
你点了[3,3]个
则[2,3][4,3][3,2][3,4]
就成为周围灯
其状态取反

解决方案 »

  1.   

    把关作为一个类,每一个类是一个实例,属性Rows,Lines来表示灯的行列数,
    而用灯的树组来表示当前关的所有灯。
    class Levels
    ( protected int Rows,Lines;
      protected stamp[,] allStamps; 
      public Levels()
      {
        //初始,给Rows,Lines赋值,并初始stamp[Rows,Lines]
      }
      public changeStamp(integer x,y)
      {
         //操作,将Stamp[x,y].IsOpen及其他灯取相应的值.
      }
      public bool IsAllOpen()
      {
        //判断是否顺利过关 
      }
    )
    class Stamp
    {
      protected bool IsOpen;
      public Stamp()
      {
        //初始灯,随机赋IsOpen???  }
      
    }只是一个想法,也没有尝试过,希望对你有点帮助。
      

  2.   

    TO lonk(小鱼): 
        抱歉,我是新手,很多术语还不知道。能不能告诉我什么是矩阵漏
      

  3.   

    请关注下面的贴子
    http://www.csdn.net/expert/topic/701/701403.xml?temp=.7961542
      

  4.   

    using System;
    using System.Drawing;
    using System.Collections;
    0Ausing System.ComponentModel;0D
    using System.Windows.Forms;
    using System.Data;namespace WindowsApplication11
    {
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.CheckBox checkBoxSeed;
    CheckBox[,] arrCB;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;public Form1()
    {
    //
    // Required for Windows Form Designer support
    //
    InitializeComponent();//
    // TODO: Add any constructor code after InitializeComponent call
    //
    }/// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    0A}#region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    0A/// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.checkBoxSeed = new System.Windows.Forms.CheckBox();
    this.button1 = new System.Windows.Forms.Button();
    this.SuspendLayout();
    // 
    // checkBoxSeed
    // 
    this.checkBoxSeed.Location = new System.Drawing.Point(80, 96);
    this.checkBoxSeed.Name = "checkBoxSeed";
    this.checkBoxSeed.Size = new System.Drawing.Size(16, 16);
    this.checkBoxSeed.TabIndex = 0;
    this.checkBoxSeed.Text = "checkBoxSeed";
    this.checkBoxSeed.Click += new System.EventHandler(this.checkBoxSeed_CheckedChanged);0D
    // 
    // button1
    // 
    this.button1.Location = new System.Drawing.Point(16, 8);
    this.button1.Name = "button1";
    this.button1.Size = new System.Drawing.Size(184, 40);
    this.button1.TabIndex = 1;
    this.button1.Text = "button1";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(292, 273);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {0D
      this.button1,
      this.checkBoxSeed});
    this.Name = "Form1";
    this.Text = "Form1";
    this.Load += new System.EventHandler(this.Form1_Load);
    this.ResumeLayout(false);
    0A
    }
    #endregion/// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());0D
    }private void button1_Click(object sender, System.EventArgs e)
    {
    AddCheckBox(10,10);
    }
    private struct ArrLocation
    0A{
    public ArrLocation(int ii,int ij)
    {
    i=ii;
    j=ij;
    }
    public int i;
    public int j;
    }
    public void AddCheckBox(int row,int colomn){
    arrCB=new CheckBox[row,colomn];
    0APoint po=checkBoxSeed.Location;
    Point p=po;for(int i=0;i<10;i++)
    {
                    p.Y=po.Y;
    p.Offset(20,0);
    for(int j=0;j<10;j++)
    {
    arrCB[i,j]=new CheckBox();
    // 
    // checkBoxSeed
    // 
    p.Offset(0,20);
    arrCB[i,j].Location=p;
    arrCB[i,j].Name = "checkBox" + i.ToString() + j.ToString();
    arrCB[i,j].Size = checkBoxSeed.Size;
    arrCB[i,j].TabIndex = 0;
    arrCB[i,j].Tag=new ArrLocation(i,j);
    arrCB[i,j].Text = "";
    arrCB[i,j].Click += new System.EventHandler(this.checkBoxSeed_CheckedChanged);0D
    this.Controls.Add(arrCB[i,j]);}
    }
    this.ResumeLayout();}private void checkBoxSeed_CheckedChanged(object sender, System.EventArgs e)
    {
    CheckBox cb=(CheckBox)sender;
    ArrLocation al=(ArrLocation)cb.Tag;try
    {
    if(arrCB[al.i,al.j+1].Checked)arrCB[al.i,al.j+1].Checked=false;
    else arrCB[al.i,al.j+1].Checked=true;if(arrCB[al.i,al.j-1].Checked)arrCB[al.i,al.j-1].Checked=false;
    else arrCB[al.i,al.j-1].Checked=true;if(arrCB[al.i+1,al.j].Checked)arrCB[al.i+1,al.j].Checked=false;
    else arrCB[al.i+1,al.j].Checked=true;if(arrCB[al.i-1,al.j].Checked)arrCB[al.i-1,al.j].Checked=false;
    else arrCB[al.i-1,al.j].Checked=true;
    }
    catch(Exception ex)
    {
    Console.Write(ex);
    }}
    }
    }------------------------------
    我是一只小小鸟
    欢迎交流!
    MSN&Ma
      

  5.   

    新建一winform apllication,把这个整个拷贝进去。run一下就行了。
    ------------------------------
    我是一只小小鸟
    欢迎交流!
    MSN&Mail: [email protected]
    0A
      

  6.   

    sorry! 可以更简化
    arrCB[al.i,al.j-1].Checked=!arrCB[al.i,al.j-1].Checked;
    ------------------------------
    我是一只小小鸟
    欢迎交流!
    MSN&Mail: [email protected]
    0A