一个基于C#的点灯游戏问题 100分 创建一个复选框矩阵然后将所有的复选框都捆定到一个事件上在事件响应中判断当前所点击的Sender是哪一个复选框比如有5*5灯你点了[3,3]个则[2,3][4,3][3,2][3,4]就成为周围灯其状态取反 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 把关作为一个类,每一个类是一个实例,属性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??? } }只是一个想法,也没有尝试过,希望对你有点帮助。 TO lonk(小鱼): 抱歉,我是新手,很多术语还不知道。能不能告诉我什么是矩阵漏 请关注下面的贴子http://www.csdn.net/expert/topic/701/701403.xml?temp=.7961542 using System;using System.Drawing;using System.Collections;0Ausing System.ComponentModel;0Dusing 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 modify0A/// 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 ArrLocation0A{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);0Dthis.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 新建一winform apllication,把这个整个拷贝进去。run一下就行了。------------------------------我是一只小小鸟欢迎交流!MSN&Mail: [email protected]0A sorry! 可以更简化arrCB[al.i,al.j-1].Checked=!arrCB[al.i,al.j-1].Checked;------------------------------我是一只小小鸟欢迎交流!MSN&Mail: [email protected]0A vs2010安装失败,错误日志提示setup files failed verification C#中进制转换问题。。。。。 C# 结取文件,怎么获取指定的.jpg.bmp文件,并且可以有短文件名及完整文件名? C#/.NET 服务端与多客户端简单网络通信、发送消息 完整实例 求助、急 OpenFileDialog1_FileOk事件问题 请大家指点一下这个算法!!! 如何读取图片某一区域? winform中DataGrid如何添加CheckBox及读取选中的列的值 有个小程序! 请求帮忙 急求 如何制作安装程序 如何取得相对路径的当前目录??
而用灯的树组来表示当前关的所有灯。
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??? }
}只是一个想法,也没有尝试过,希望对你有点帮助。
抱歉,我是新手,很多术语还不知道。能不能告诉我什么是矩阵漏
http://www.csdn.net/expert/topic/701/701403.xml?temp=.7961542
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
------------------------------
我是一只小小鸟
欢迎交流!
MSN&Mail: [email protected]
0A
arrCB[al.i,al.j-1].Checked=!arrCB[al.i,al.j-1].Checked;
------------------------------
我是一只小小鸟
欢迎交流!
MSN&Mail: [email protected]
0A