c#写的五子棋程序,供学习WinForms的鼠标事件和使用GDI+(2)

五子棋软件


#1 c#写的五子棋程序,供学习WinForms的鼠标事件和使用GDI+(2) 作者:有志青年 发表时间:2007-4-14 21:58:20

原文地址:http://blog.sina.com.cn/kuang87929


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;
}
}
else
{
isFive.Clear();
}
}
}
isFive.Clear();
}
private void ReSetGame()
{
//reset game
nextTurn = bTurn;
for(int i=0;i
{
chessTable = 0;
}
this.Invalidate();
}
private int GetRectID(Point p)
{
//get witch rectangle click
for(int i = 0;i
{
if(pointSquares.Contains( p ))
{
return i;
}
}
return -1;
}
private void OnRButtonDown(Point p)
{
//regret chess
int nPos,x,y;
if(chessIndex.Count != 0)
{
nPos = (int)chessIndex.Pop();
x = nPos%15;
y = nPos/15;
chessTable[nPos] = 0;
nextTurn = (int)chessIndex.Pop();
this.Invalidate(new Rectangle(new Point(8+x*20,5+y*20),new Size(20,20)));
}
}
private void DrawBlack(Graphics g,int nPos)
{
//draw Black chess
int x,y;
x = nPos%15;
y = nPos/15;
imageListbw.DrawImage(g,8+20*x,5+20*y,20,20,0,0);
}
private void DrawWhite(Graphics g,int nPos)
{
//draw White chess
int x,y;
x = nPos%15;
y = nPos/15;
imageListbw.DrawImage(g,8+20*x,5+20*y,20,20,0,1);
}
///
/// Clean up any resources being used.
///
public override void Dispose()
{
base.Dispose();
components.Dispose();
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager (typeof(FiveForm));
this.components = new System.ComponentModel.Container ();
this.imageListbw = new System.WinForms.ImageList ();
//@this.TrayHeight = 90;
//@this.TrayLargeIcon = false;
//@this.TrayAutoArrange = true;
//@imageListbw.SetLocation (new System.Drawing.Point (7, 7));
imageListbw.ImageSize = new System.Drawing.Size (20, 20);
imageListbw.ImageStream = (System.WinForms.ImageListStreamer) resources.GetObject ("imageListbw.ImageStream");
imageListbw.ColorDepth = System.WinForms.ColorDepth.Depth8Bit;
imageListbw.TransparentColor = System.Drawing.Color.Yellow;
this.Text = "FiveForm";
this.MaximizeBox = false;
this.AutoScaleBaseSize = new System.Drawing.Size (6, 14);
this.BorderStyle = System.WinForms.FormBorderStyle.FixedSingle;
this.BackgroundImage = (System.Drawing.Image) resources.GetObject ("$this.BackgroundImage");
this.TransparencyKey = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size (314, 311);
}
///
/// The main entry point for the application.
///
public static int Main(string[] args)
{
Application.Run(new FiveForm());
return 0;
}
}
}