📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication1
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.ComponentModel.IContainer components;
private int i, j, k, m, n, icount;
private int[,] board = new int [10,10];
private bool[,,] ptable = new bool[10,10,192];
private bool[,,] ctable = new bool[10,10,192];
private int[,] cgrades = new int[10,10];
private int[,] pgrades = new int[10,10];
private int cgrade,
pgrade;
private int[,] win = new int[2,192];
private int pcount,
ccount;
private bool player,
computer,
over,
pwin,
cwin,
tie ,
start;
private int mat,
nat,
mde,
nde;
private System.Drawing.Image bgbmp = System.Drawing.Image.FromFile("bgbmp.bmp");
private System.Drawing.Image green = System.Drawing.Image.FromFile("green.bmp");
private System.Drawing.Image purple = System.Drawing.Image.FromFile("purple.bmp");
private int oldx,oldy;
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.MenuItem menuItem7;
private System.Windows.Forms.MenuItem menuItem6;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 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()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
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.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem5});
this.mainMenu1.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("mainMenu1.RightToLeft")));
//
// menuItem1
//
this.menuItem1.Enabled = ((bool)(resources.GetObject("menuItem1.Enabled")));
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem3,
this.menuItem4});
this.menuItem1.Shortcut = ((System.Windows.Forms.Shortcut)(resources.GetObject("menuItem1.Shortcut")));
this.menuItem1.ShowShortcut = ((bool)(resources.GetObject("menuItem1.ShowShortcut")));
this.menuItem1.Text = resources.GetString("menuItem1.Text");
this.menuItem1.Visible = ((bool)(resources.GetObject("menuItem1.Visible")));
//
// menuItem2
//
this.menuItem2.Enabled = ((bool)(resources.GetObject("menuItem2.Enabled")));
this.menuItem2.Index = 0;
this.menuItem2.Shortcut = ((System.Windows.Forms.Shortcut)(resources.GetObject("menuItem2.Shortcut")));
this.menuItem2.ShowShortcut = ((bool)(resources.GetObject("menuItem2.ShowShortcut")));
this.menuItem2.Text = resources.GetString("menuItem2.Text");
this.menuItem2.Visible = ((bool)(resources.GetObject("menuItem2.Visible")));
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// menuItem3
//
this.menuItem3.Enabled = ((bool)(resources.GetObject("menuItem3.Enabled")));
this.menuItem3.Index = 1;
this.menuItem3.Shortcut = ((System.Windows.Forms.Shortcut)(resources.GetObject("menuItem3.Shortcut")));
this.menuItem3.ShowShortcut = ((bool)(resources.GetObject("menuItem3.ShowShortcut")));
this.menuItem3.Text = resources.GetString("menuItem3.Text");
this.menuItem3.Visible = ((bool)(resources.GetObject("menuItem3.Visible")));
//
// menuItem4
//
this.menuItem4.Enabled = ((bool)(resources.GetObject("menuItem4.Enabled")));
this.menuItem4.Index = 2;
this.menuItem4.Shortcut = ((System.Windows.Forms.Shortcut)(resources.GetObject("menuItem4.Shortcut")));
this.menuItem4.ShowShortcut = ((bool)(resources.GetObject("menuItem4.ShowShortcut")));
this.menuItem4.Text = resources.GetString("menuItem4.Text");
this.menuItem4.Visible = ((bool)(resources.GetObject("menuItem4.Visible")));
this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
//
// menuItem5
//
this.menuItem5.Enabled = ((bool)(resources.GetObject("menuItem5.Enabled")));
this.menuItem5.Index = 1;
this.menuItem5.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem6,
this.menuItem7});
this.menuItem5.Shortcut = ((System.Windows.Forms.Shortcut)(resources.GetObject("menuItem5.Shortcut")));
this.menuItem5.ShowShortcut = ((bool)(resources.GetObject("menuItem5.ShowShortcut")));
this.menuItem5.Text = resources.GetString("menuItem5.Text");
this.menuItem5.Visible = ((bool)(resources.GetObject("menuItem5.Visible")));
//
// menuItem6
//
this.menuItem6.Enabled = ((bool)(resources.GetObject("menuItem6.Enabled")));
this.menuItem6.Index = 0;
this.menuItem6.Shortcut = ((System.Windows.Forms.Shortcut)(resources.GetObject("menuItem6.Shortcut")));
this.menuItem6.ShowShortcut = ((bool)(resources.GetObject("menuItem6.ShowShortcut")));
this.menuItem6.Text = resources.GetString("menuItem6.Text");
this.menuItem6.Visible = ((bool)(resources.GetObject("menuItem6.Visible")));
this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click);
//
// menuItem7
//
this.menuItem7.Enabled = ((bool)(resources.GetObject("menuItem7.Enabled")));
this.menuItem7.Index = 1;
this.menuItem7.Shortcut = ((System.Windows.Forms.Shortcut)(resources.GetObject("menuItem7.Shortcut")));
this.menuItem7.ShowShortcut = ((bool)(resources.GetObject("menuItem7.ShowShortcut")));
this.menuItem7.Text = resources.GetString("menuItem7.Text");
this.menuItem7.Visible = ((bool)(resources.GetObject("menuItem7.Visible")));
this.menuItem7.Click += new System.EventHandler(this.menuItem7_Click);
//
// Form1
//
this.AccessibleDescription = resources.GetString("$this.AccessibleDescription");
this.AccessibleName = resources.GetString("$this.AccessibleName");
this.AutoScaleBaseSize = ((System.Drawing.Size)(resources.GetObject("$this.AutoScaleBaseSize")));
this.AutoScroll = ((bool)(resources.GetObject("$this.AutoScroll")));
this.AutoScrollMargin = ((System.Drawing.Size)(resources.GetObject("$this.AutoScrollMargin")));
this.AutoScrollMinSize = ((System.Drawing.Size)(resources.GetObject("$this.AutoScrollMinSize")));
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = ((System.Drawing.Size)(resources.GetObject("$this.ClientSize")));
this.Enabled = ((bool)(resources.GetObject("$this.Enabled")));
this.Font = ((System.Drawing.Font)(resources.GetObject("$this.Font")));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("$this.ImeMode")));
this.KeyPreview = true;
this.Location = ((System.Drawing.Point)(resources.GetObject("$this.Location")));
this.MaximizeBox = false;
this.MaximumSize = ((System.Drawing.Size)(resources.GetObject("$this.MaximumSize")));
this.Menu = this.mainMenu1;
this.MinimizeBox = false;
this.MinimumSize = ((System.Drawing.Size)(resources.GetObject("$this.MinimumSize")));
this.Name = "Form1";
this.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("$this.RightToLeft")));
this.StartPosition = ((System.Windows.Forms.FormStartPosition)(resources.GetObject("$this.StartPosition")));
this.Text = resources.GetString("$this.Text");
this.TopMost = true;
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
this.Load += new System.EventHandler(this.Form1_Load);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void startGame()
{
for(i=0;i<10;i++)
for(j=0;j<10;j++)
{
pgrades[i,j] = 0;
cgrades[i,j] = 0;
board[i,j] = 2;
}
for(i=0;i<10;i++)
for(j=0;j<6;j++)
{
for(k=0;k<5;k++)
{
ptable[j+k,i,icount] = true;
ctable[j+k,i,icount] = true;
}
icount++;
}
for(i=0;i<10;i++)
for(j=0;j<6;j++)
{
for(k=0;k<5;k++)
{
ptable[i,j+k,icount] = true;
ctable[i,j+k,icount] = true;
}
icount++;
}
for(i=0;i<6;i++)
for(j=0;j<6;j++)
{
for(k=0;k<5;k++)
{
ptable[j+k,i+k,icount] = true;
ctable[j+k,i+k,icount] = true;
}
icount++;
}
for(i=0;i<6;i++)
for(j=9;j>=4;j--)
{
for(k=0;k<5;k++)
{
ptable[j-k,i+k,icount] = true;
ctable[j-k,i+k,icount] = true;
}
icount++;
}
for(i=0;i<=1;i++)
for(j=0;j<192;j++)
win[i,j] = 0;
Random rdm1 = new Random(unchecked((int)DateTime.Now.Ticks));
if(rdm1.Next()%2==0)
computer = true;
else
player = true;
icount = 0;
ccount = 0;
pcount = 0;
start = true;
over = false;
pwin = false;
cwin = false;
tie = false;
}
private void updatePaint()
{
System.Drawing.Graphics g= this.CreateGraphics();
g.DrawImage(bgbmp,0,0,bgbmp.Width,bgbmp.Height);
if(!over)
{
if(computer)
ComTurn();
for(i=0;i<=1;i++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -