六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網(wǎng)中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

c#寫的5子棋程序,供學習WinForms的鼠標事件與使用GDI+

[摘要]前幾天沒事,寫了一個小程序,可以用于學習C#。 程序使用了VS.NET環(huán)境編譯,你的機器只要安裝了.NET Framework SDK就可以運行。源碼和執(zhí)行文件可以下載http://www.wh-adv.com/download/five.zip你不想下載也可讀一下源碼(圖片資源等需要下載)。na...
前幾天沒事,寫了一個小程序,可以用于學習C#。

程序使用了VS.NET環(huán)境編譯,你的機器只要安裝了.NET Framework SDK就可以運行。

源碼和執(zhí)行文件可以下載

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;

}

}

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;

}

}

else

{

isFive.Clear();

}

}

}

isFive.Clear();

}

private void ReSetGame()

{

//reset game

nextTurn = bTurn;

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

{

chessTable[i] = 0;

}

this.Invalidate();

}

private int GetRectID(Point p)

{

//get witch rectangle click

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

{

if(pointSquares[i].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);

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

public override void Dispose()

{

base.Dispose();

components.Dispose();

}

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

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);

}

/// <summary>

/// The main entry point for the application.

/// </summary>

public static int Main(string[] args)

{

Application.Run(new FiveForm());

return 0;

}

}

}





主站蜘蛛池模板: 日日夜夜国产 | 亚洲国产三级在线观看 | 婷婷开心中文字幕 | 午夜高清视频 | 在线波多野结衣 | 日本三级精品 | 欧美一级片观看 | 日本午夜在线视频 | 在线aa| 西西人体大胆77777视频 | 亚洲 欧美 中文 日韩专区 | 视频在线观看40分钟免费 | 四川一级护士一级毛片 | 日本特黄特色aa大片免费 | 日韩不卡视频在线 | 欧美丝袜一区二区三区 | 性色午夜视频免费男人的天堂 | 深夜福利日韩 | 欧美综合一区二区三区 | 亚洲欧美成aⅴ人在线观看 亚洲欧美不卡 | 影音先锋男人资源站 | 神马热 | 天天上天天操 | 天天碰夜夜 | 伊人成人在线 | 四虎永久在线精品免费影视 | 欧美在线 在线播放 | 亚洲精品亚洲人成在线 | 色网在线观看 | 天天碰夜夜| 四虎影院精品在线观看 | 日韩精品专区 | 性欧美大战久久久久久久久 | 欧日韩不卡在线视频 | 色欧美视频 | 深爱开心激情 | 四虎影永久在线观看精品 | 午夜影院在线视频 | 天堂网www在线观看 天堂网www在线 | 日本一区二区视频免费播放 | 四虎影院成人在线观看 |