ICANN认证国际域名顶级注册机构
网站建设,域名注册,空间租用,软件销售,广告设计 域名注册,空间租用, 网站建设,东莞网页设计,域名注册,网站推广,网站开发,网页设计 网站推广,,百度推广,新浪推广,雅虎推广,网易推广 标志设计,画册设计,包装设计,VI策划,企业形象顾问 连邦软件加盟店,提供销遥行,管家婆,速达,用友ERP,诺顿等软件报价及销售 建站必读 腾达网络,上网帮助中心, 腾达为东莞等地,提供网站建设,网站推广,广告设计,软件销售等优质服务!
建站必读


 
 
当前位置:首页 -> 建站必读 -> .NET技术
去年用c#写的五子棋程序
c#写的五子棋程序,供学习WinForms的鼠标事件和使用GDI+







前几天没事(是去年的事了),写了一个小程序,可以用于学习C#。

程序使用了VS.NET环境编译,你的机器只要安装了.NET Framework SDK就可以运行。

源码和执行文件可以下载

http://www.wh-adv.com/download/five.zip

你不想下载也可读一下源码(图片资源等需要下载)。

namespace Leimom.FiveChess

{

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.WinForms;

using System.Data;

/// <summary>

/// Summary description for Form1.

/// </summary>

public class FiveForm : System.WinForms.Form

{

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components;

private System.WinForms.ImageList imageListbw;

//define the hot Rectangle

private Rectangle[] pointSquares;

//chess information

private int[] chessTable;

private int nextTurn;

private const int bTurn = 1;

private const int wTurn = 2;

private Stack chessIndex;

public FiveForm()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

//

// TODO: Add any constructor code after InitializeComponent call

//

chessIndex = new Stack();

nextTurn = bTurn;

chessTable = new int[225];

pointSquares = new Rectangle[225];

Size size = new Size(18,18);

int x = 0;

int y = 0;

for(int i = 0;i < 225;i++)

{

x = i%15;

y = i/15;

pointSquares[i].Size = size;

pointSquares[i].Offset(9+x*20,6+y*20);

chessTable[i] = 0;

}

}



protected override void OnPaint(PaintEventArgs e)

{

//you may paint

Graphics g = e.Graphics;

}

protected override void OnMouseDown(System.WinForms.MouseEventArgs e)

{

switch( e.Button )

{

//take left button down

case MouseButtons.Left:

OnLButtonDown(new Point(e.X,e.Y));

break;

//take right button down

case MouseButtons.Right:

OnRButtonDown(new Point(e.X,e.Y));

break;

}

base.OnMouseDown(e);

}

private void OnLButtonDown(Point p)

{

int nPos = GetRectID(p);

//click hot Rectangle witch have no chess

if(nPos != -1&&chessTable[nPos] == 0)

{

Graphics g = this.CreateGraphics();

if(nextTurn==bTurn)

{

//draw white chess

DrawBlack(g,nPos);

chessTable[nPos] = bTurn;

nextTurn = wTurn;

chessIndex.Push(bTurn);

chessIndex.Push(nPos);

}

else

{

//draw Black chess

DrawWhite(g,nPos);

chessTable[nPos] = wTurn;

nextTurn = bTurn;

chessIndex.Push(wTurn);

chessIndex.Push(nPos);

}

g.Dispose();

//witch win

CheckGameResult(nPos,nextTurn);

}

}

private void CheckGameResult(int nPos,int nextTurn)

{

//witch win

Stack isFive = new Stack();

int thisTurn = (nextTurn == bTurn)?wTurn:bTurn;

int x = nPos%15;

int y = nPos/15;

//scan x have five

for(int i=0;i<15;i++)

{

if(chessTable[y*15+i] == thisTurn)

{

isFive.Push(y*15+i);

if(isFive.Count == 5)

{

MessageBox.Show("Game Over","Notes",MessageBox.OK);

ReSetGame();

return;

}

}

else

{

isFive.Clear();

}

}

isFive.Clear();

//scan y have five

for(int i=0;i<15;i++)

{

if(chessTable[i*15+x] == thisTurn)

{

isFive.Push(i*15+x);

if(isFive.Count == 5)

{

MessageBox.Show("Game Over","Notes",MessageBox.OK);

ReSetGame();

return;

}

}

else

{

isFive.Clear();

}

}

isFive.Clear();

//scan x=y have five

for(int i=-14;i<15;i++)

{

if(x+i<0||x+i>14||y-i<0||y-i>14)

{

continue;

}

else

{

if(chessTable[(y-i)*15+x+i] == thisTurn)

{

isFive.Push((y-i)*15+x+i);

if(isFive.Count == 5)

{

MessageBox.Show("Game Over","Notes",MessageBox.OK);

ReSetGame();

return;

}

}

els
 
 
本站关键词:
|东莞财务软件|东莞ERP软件|东莞电脑维护|网页开发|域名注册|空间租用|东莞网站开发|东莞企业网站建设|国际内域名注册|石龙 虎门 中堂|望牛墩 麻涌镇 石碣镇|高埗镇 洪梅镇 道滘镇||东莞财务软件|东莞ERP软件|东莞电脑维护|网页开发|域名注册|空间租用|东莞网站开发|东莞企业网站建设|国际内域名注册|石龙 虎门 中堂|望牛墩 麻涌镇 石碣镇|高埗镇 洪梅镇 道滘镇||东莞财务软件|东莞ERP软件|东莞电脑维护|网页开发|域名注册|空间租用|东莞网站开发|东莞企业网站建设|国际内域名注册|石龙 虎门 中堂|望牛墩 麻涌镇 石碣镇|高埗镇 洪梅镇 道滘镇||东莞财务软件|东莞ERP软件|东莞电脑维护|网页开发|域名注册|空间租用|东莞网站开发|东莞企业网站建设|国际内域名注册|石龙 虎门 中堂|望牛墩 麻涌镇 石碣镇|高埗镇 洪梅镇 道滘镇||东莞财务软件|东莞ERP软件|东莞电脑维护|网页开发|域名注册|空间租用|东莞网站开发|东莞企业网站建设|国际内域名注册|石龙 虎门 中堂|望牛墩 麻涌镇 石碣镇|高埗镇 洪梅镇 道滘镇||东莞财务软件|东莞ERP软件|东莞电脑维护|网页开发|域名注册|空间租用|东莞网站开发|东莞企业网站建设|国际内域名注册|石龙 虎门 中堂|望牛墩 麻涌镇 石碣镇|高埗镇 洪梅镇 道滘镇||东莞财务软件|东莞ERP软件|东莞电脑维护|网页开发|域名注册|空间租用|东莞网站开发|东莞企业网站建设|国际内域名注册|石龙 虎门 中堂|望牛墩 麻涌镇 石碣镇|高埗镇 洪梅镇 道滘镇||东莞财务软件|东莞ERP软件|东莞电脑维护|网页开发|域名注册|空间租用|东莞网站开发|东莞企业网站建设|国际内域名注册|石龙 虎门 中堂|望牛墩 麻涌镇 石碣镇|高埗镇 洪梅镇 道滘镇||东莞财务软件|东莞ERP软件|东莞电脑维护|网页开发|域名注册|空间租用|东莞网站开发|东莞企业网站建设|国际内域名注册|石龙 虎门 中堂|望牛墩 麻涌镇 石碣镇|高埗镇 洪梅镇 道滘镇||东莞财务软件|东莞ERP软件|东莞电脑维护|网页开发|域名注册|空间租用|东莞网站开发|东莞企业网站建设|国际内域名注册|石龙 虎门 中堂|望牛墩 麻涌镇 石碣镇|高埗镇 洪梅镇 道滘镇||东莞财务软件|东莞ERP软件|东莞电脑维护|网页开发|域名注册|空间租用|东莞网站开发|东莞企业网站建设|国际内域名注册|石龙 虎门 中堂|望牛墩 麻涌镇 石碣镇|高埗镇 洪梅镇 道滘镇||东莞财务软件|东莞ERP软件|东莞电脑维护|网页开发|域名注册|空间租用|东莞网站开发|东莞企业网站建设|国际内域名注册|石龙 虎门 中堂|望牛墩 麻涌镇 石碣镇|高埗镇 洪梅镇 道滘镇||东莞财务软件|东莞ERP软件|东莞电脑维护|网页开发|域名注册|空间租用|东莞网站开发|东莞企业网站建设|国际内域名注册|石龙 虎门 中堂|望牛墩 麻涌镇 石碣镇|高埗镇 洪梅镇 道滘镇||东莞财务软件|东莞ERP软件|东莞电脑维护|网页开发|域名注册|空间租用|东莞网站开发|东莞企业网站建设|国际内域名注册|石龙 虎门 中堂|望牛墩 麻涌镇 石碣镇|高埗镇 洪梅镇 道滘镇|
域名注册 | 虚拟主机 | 网站建设 | 网站推广 | 广告设计 | 帮助中心 | 软件中心 | 关于腾达
东莞市腾达信息工程有限公司      本站网络实名: 东莞网站建设
地址:东莞市新城市中心区第一国际B座610   邮编:523007
电话:0769-22026071 22026072 传真:0769-22026076 24小时服务热线:13712032014
© 2002~2005 腾达网络   版权所有