using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data;
namespace WindowsApplication2 { /// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.MainMenu mainMenu1; private System.Windows.Forms.MenuItem menuItem1; private System.Windows.Forms.MenuItem menuItem2; private System.Windows.Forms.MenuItem menuItem3; private System.Windows.Forms.MenuItem menuItem4; private System.Windows.Forms.MenuItem menuItem5; private System.Windows.Forms.Label label1; /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; SolidBrush brush1=new SolidBrush (Color.Black); SolidBrush brush2=new SolidBrush (Color.White); string who; private int win=0; private int[,] place; public Form1() { // // Windows 窗体设计器支持所必需的 place=new int[14,14]; for(int i=0;i<=13;i++ ) for(int j=0;j<=13;j++) place[i,j]=-1; //初值表示该位子没下过 who="Black"; InitializeComponent();
// // TOD 在 InitializeComponent 调用后添加任何构造函数代码 // }
/// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); }
#region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.mainMenu1 = new System.Windows.Forms.MainMenu(); this.menuItem1 = new System.Windows.Forms.MenuItem(); this.menuItem2 = new System.Windows.Forms.MenuItem(); this.menuItem3 = new System.Windows.Forms.MenuItem(); this.menuItem5 = new System.Windows.Forms.MenuItem(); this.menuItem4 = new System.Windows.Forms.MenuItem(); this.label1 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // mainMenu1 // this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem1, this.menuItem4}); // // menuItem1 // this.menuItem1.Index = 0; this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem2, this.menuItem3, this.menuItem5}); this.menuItem1.Text = "File"; // // menuItem2 // this.menuItem2.Index = 0; this.menuItem2.Text = "twins"; this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click); // // menuItem3 // this.menuItem3.Index = 1; this.menuItem3.Text = "conputer"; // // menuItem5 // this.menuItem5.Index = 2; this.menuItem5.Text = "Exit"; // // menuItem4 // this.menuItem4.Index = 1; this.menuItem4.Text = ""; // // label1 // this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.label1.Cursor = System.Windows.Forms.Cursors.Default; this.label1.Font = new System.Drawing.Font("宋体", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134))); this.label1.Location = new System.Drawing.Point(456, 72); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(112, 24); this.label1.TabIndex = 0; this.label1.Text = "黑方先下:"; this.label1.Click += new System.EventHandler(this.label1_Click); this.label1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.label1_MouseDown); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(704, 321); this.Controls.Add(this.label1); this.Cursor = System.Windows.Forms.Cursors.Hand; this.Menu = this.mainMenu1; this.Name = "Form1"; this.Text = "Form1"; this.WindowState = System.Windows.Forms.FormWindowState.Maximized; this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown); this.Load += new System.EventHandler(this.Form1_Load); this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyUp); this.ResumeLayout(false);
} #endregion
/// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } protected override void OnPaint( PaintEventArgs paintEvent ) { Graphics g = paintEvent.Graphics; Pen pen = new Pen( Color.Blue );
for(int i=45;i<=435;i+=30) g.DrawLine( pen, 45, i, 435, i ); for(int h=45;h<=435;h+=30) g.DrawLine(pen, h,45,h,435 );
}
private void menuItem2_Click(object sender, System.EventArgs e) { }
private void Form1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e) { }
private void Form1_Load(object sender, System.EventArgs e) { }
private void label1_Click(object sender, System.EventArgs e) { }
private void label1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { }
private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { if(e.X<40||e.X>440||e.Y<40||e.Y>440) return ; int x=e.X-e.X%30; int y=e.Y-e.Y%30; if(place[x/30-1,y/30-1]==-1) { Graphics g=CreateGraphics(); label1.Text=who; if(who=="Black") { g.FillEllipse(brush2, x, y, 30, 30); place[x/30-1,y/30-1]=0; who="White"; } else { g.FillEllipse(brush1, x,y, 30, 30); place[x/30-1,y/30-1]=1; who="Black"; }
就是这段,我想判断横的五个棋子相同就获胜为什么没效果 for(int k=1;k<=5;k++) { for(int i=x/30-k;i<=x/30+(5-k);i++) { if(i<0||i>13) //continue; break; else win+=place[i,y/30-1]; } if(win==0||win==5) MessageBox.Show(who,"win",MessageBoxButtons.OK,MessageBoxIcon.Information ); else win=0; } } else { MessageBox.Show(who,"error",MessageBoxButtons.OK,MessageBoxIcon.Information ); } }
} }