中国象棋游戏源代码.docx

上传人:b****3 文档编号:6776054 上传时间:2023-05-10 格式:DOCX 页数:18 大小:17.16KB
下载 相关 举报
中国象棋游戏源代码.docx_第1页
第1页 / 共18页
中国象棋游戏源代码.docx_第2页
第2页 / 共18页
中国象棋游戏源代码.docx_第3页
第3页 / 共18页
中国象棋游戏源代码.docx_第4页
第4页 / 共18页
中国象棋游戏源代码.docx_第5页
第5页 / 共18页
中国象棋游戏源代码.docx_第6页
第6页 / 共18页
中国象棋游戏源代码.docx_第7页
第7页 / 共18页
中国象棋游戏源代码.docx_第8页
第8页 / 共18页
中国象棋游戏源代码.docx_第9页
第9页 / 共18页
中国象棋游戏源代码.docx_第10页
第10页 / 共18页
中国象棋游戏源代码.docx_第11页
第11页 / 共18页
中国象棋游戏源代码.docx_第12页
第12页 / 共18页
中国象棋游戏源代码.docx_第13页
第13页 / 共18页
中国象棋游戏源代码.docx_第14页
第14页 / 共18页
中国象棋游戏源代码.docx_第15页
第15页 / 共18页
中国象棋游戏源代码.docx_第16页
第16页 / 共18页
中国象棋游戏源代码.docx_第17页
第17页 / 共18页
中国象棋游戏源代码.docx_第18页
第18页 / 共18页
亲,该文档总共18页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

中国象棋游戏源代码.docx

《中国象棋游戏源代码.docx》由会员分享,可在线阅读,更多相关《中国象棋游戏源代码.docx(18页珍藏版)》请在冰点文库上搜索。

中国象棋游戏源代码.docx

中国象棋游戏源代码

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Linq;

usingSystem.Text;

usingSystem.Windows.Forms;

namespace象棋

{

enumplayer

{

blank,

red,

blue,

};

enumchesstype

{

blank,

jiang,

che,

ma,

pao,

xiang,

zu,

shi

};

structchess

{

publicplayerside;

publicchesstypetype;

};

//下载于

structblock

{

publicPictureBoxcontainer;

publicchessitem;

};

publicpartialclassForm1:

Form

{

publicForm1()

{

InitializeComponent();

pictureboxlist=newList(81);

Matrix=newblock[10][];

inti,j;

for(i=0;i<10;i++)

{

Matrix[i]=newblock[9];

}

for(i=0;i<10;i++)

{

for(j=0;j<9;j++)

{

Control[]col=this.Controls.Find("pictureBox"+(i*9+j+1),false);

Matrix[i][j].container=col[0]asPictureBox;

Matrix[i][j].container.Location=newPoint(60*j,60*i);

}

}

redcoll=newcollecter();

bluecool=newcollecter();

for(i=91;i<107;i++)

{

Control[]col=this.Controls.Find("pictureBox"+i,false);

bluecool.add(col[0]asPictureBox);

}

for(i=107;i<123;i++)

{

Control[]col=this.Controls.Find("pictureBox"+i,false);

redcoll.add(col[0]asPictureBox);

}

resetground();

}

Listpictureboxlist;

block[][]Matrix;

collecterredcoll;

collecterbluecool;

intchozenX;

intchozenY;

playercurrentside;

boolbeenchozen;

boolclickswitch;

privatevoidclick1(objectsender,EventArgse)

{

if(!

clickswitch)

{

resetground();

return;

}

stringname=(senderasPictureBox).Name;

stringnumber=name.Substring(10);

intindex=Convert.ToInt32(number);

inti,j;

boolflag=false;

i=(index-1)/9;

j=(index-1)%9;

//下载于

if(beenchozen)

{

Matrix[chozenX][chozenY].container.BorderStyle=BorderStyle.None;

Matrix[chozenX][chozenY].container.BackColor=Color.Transparent;

beenchozen=false;

if(Matrix[chozenX][chozenY].item.side==Matrix[i][j].item.side)

{

return;

}

if(Matrix[chozenX][chozenY].item.side!

=player.blank)

{

if(Matrix[i][j].item.type==chesstype.jiang)

{

flag=true;

}

if(!

movechess(i,j))

{

return;

}

if(flag)

{

if(currentside==player.red)

{

MessageBox.Show("红方胜利!

点击任意处重新开局");

}

else

{

MessageBox.Show("蓝方胜利!

点击任意处重新开局");

}

clickswitch=false;

}

}

if(currentside==player.red)

{

currentside=player.blue;

label1.Text="蓝方";

label1.ForeColor=Color.Blue;

}

else

{

currentside=player.red;

label1.Text="红方";

label1.ForeColor=Color.Red;

}

}

elseif(Matrix[i][j].item.side==currentside)

{

Matrix[i][j].container.BorderStyle=BorderStyle.FixedSingle;

Matrix[i][j].container.BackColor=Color.Brown;

chozenX=i;

chozenY=j;

beenchozen=true;

}

}

privatevoidresetground()

{

inti,j;

for(i=0;i<10;i++)

{

for(j=0;j<9;j++)

{

Matrix[i][j].container.Image=null;

Matrix[i][j].item.side=player.blank;

Matrix[i][j].item.type=chesstype.blank;

}

}

beenchozen=false;

clickswitch=true;

currentside=player.red;

label1.Text="红方";

label1.ForeColor=Color.Red;

redcoll.clear();

bluecool.clear();

Matrix[0][0].container.Image=global:

:

象棋.Properties.Resources.蓝车;

Matrix[0][1].container.Image=global:

:

象棋.Properties.Resources.蓝马;

Matrix[0][2].container.Image=global:

:

象棋.Properties.Resources.蓝象;

Matrix[0][3].container.Image=global:

:

象棋.Properties.Resources.蓝士;

Matrix[0][4].container.Image=global:

:

象棋.Properties.Resources.蓝将;

Matrix[0][5].container.Image=global:

:

象棋.Properties.Resources.蓝士;

Matrix[0][6].container.Image=global:

:

象棋.Properties.Resources.蓝象;

Matrix[0][7].container.Image=global:

:

象棋.Properties.Resources.蓝马;

Matrix[0][8].container.Image=global:

:

象棋.Properties.Resources.蓝车;

Matrix[2][1].container.Image=global:

:

象棋.Properties.Resources.蓝炮;

Matrix[2][7].container.Image=global:

:

象棋.Properties.Resources.蓝炮;

Matrix[3][0].container.Image=global:

:

象棋.Properties.Resources.蓝卒;

Matrix[3][2].container.Image=global:

:

象棋.Properties.Resources.蓝卒;

Matrix[3][4].container.Image=global:

:

象棋.Properties.Resources.蓝卒;

Matrix[3][6].container.Image=global:

:

象棋.Properties.Resources.蓝卒;

Matrix[3][8].container.Image=global:

:

象棋.Properties.Resources.蓝卒;

Matrix[6][0].container.Image=global:

:

象棋.Properties.Resources.红卒;

Matrix[6][2].container.Image=global:

:

象棋.Properties.Resources.红卒;

Matrix[6][4].container.Image=global:

:

象棋.Properties.Resources.红卒;

Matrix[6][6].container.Image=global:

:

象棋.Properties.Resources.红卒;

Matrix[6][8].container.Image=global:

:

象棋.Properties.Resources.红卒;

Matrix[7][1].container.Image=global:

:

象棋.Properties.Resources.红炮;

Matrix[7][7].container.Image=global:

:

象棋.Properties.Resources.红炮;

Matrix[9][0].container.Image=global:

:

象棋.Properties.Resources.红车;

Matrix[9][1].container.Image=global:

:

象棋.Properties.Resources.红马;

Matrix[9][2].container.Image=global:

:

象棋.Properties.Resources.红象;

Matrix[9][3].container.Image=global:

:

象棋.Properties.Resources.红士;

Matrix[9][4].container.Image=global:

:

象棋.Properties.Resources.红将;

Matrix[9][5].container.Image=global:

:

象棋.Properties.Resources.红士;

Matrix[9][6].container.Image=global:

:

象棋.Properties.Resources.红象;

Matrix[9][7].container.Image=global:

:

象棋.Properties.Resources.红马;

Matrix[9][8].container.Image=global:

:

象棋.Properties.Resources.红车;

//下载于

Matrix[0][0].item.side=player.blue;

Matrix[0][1].item.side=player.blue;

Matrix[0][2].item.side=player.blue;

Matrix[0][3].item.side=player.blue;

Matrix[0][4].item.side=player.blue;

Matrix[0][5].item.side=player.blue;

Matrix[0][6].item.side=player.blue;

Matrix[0][7].item.side=player.blue;

Matrix[0][8].item.side=player.blue;

Matrix[2][1].item.side=player.blue;

Matrix[2][7].item.side=player.blue;

Matrix[3][0].item.side=player.blue;

Matrix[3][2].item.side=player.blue;

Matrix[3][4].item.side=player.blue;

Matrix[3][6].item.side=player.blue;

Matrix[3][8].item.side=player.blue;

Matrix[6][0].item.side=player.red;

Matrix[6][2].item.side=player.red;

Matrix[6][4].item.side=player.red;

Matrix[6][6].item.side=player.red;

Matrix[6][8].item.side=player.red;

Matrix[7][1].item.side=player.red;

Matrix[7][7].item.side=player.red;

Matrix[9][0].item.side=player.red;

Matrix[9][1].item.side=player.red;

Matrix[9][2].item.side=player.red;

Matrix[9][3].item.side=player.red;

Matrix[9][4].item.side=player.red;

Matrix[9][5].item.side=player.red;

Matrix[9][6].item.side=player.red;

Matrix[9][7].item.side=player.red;

Matrix[9][8].item.side=player.red;

Matrix[0][0].item.type=chesstype.che;

Matrix[0][1].item.type=chesstype.ma;

Matrix[0][2].item.type=chesstype.xiang;

Matrix[0][3].item.type=chesstype.shi;

Matrix[0][4].item.type=chesstype.jiang;

Matrix[0][5].item.type=chesstype.shi;

Matrix[0][6].item.type=chesstype.xiang;

Matrix[0][7].item.type=chesstype.ma;

Matrix[0][8].item.type=chesstype.che;

Matrix[2][1].item.type=chesstype.pao;

Matrix[2][7].item.type=chesstype.pao;

Matrix[3][0].item.type=chesstype.zu;

Matrix[3][2].item.type=chesstype.zu;

Matrix[3][4].item.type=chesstype.zu;

Matrix[3][6].item.type=chesstype.zu;

Matrix[3][8].item.type=chesstype.zu;

Matrix[6][0].item.type=chesstype.zu;

Matrix[6][2].item.type=chesstype.zu;

Matrix[6][4].item.type=chesstype.zu;

Matrix[6][6].item.type=chesstype.zu;

Matrix[6][8].item.type=chesstype.zu;

Matrix[7][1].item.type=chesstype.pao;

Matrix[7][7].item.type=chesstype.pao;

Matrix[9][0].item.type=chesstype.che;

Matrix[9][1].item.type=chesstype.ma;

Matrix[9][2].item.type=chesstype.xiang;

Matrix[9][3].item.type=chesstype.shi;

Matrix[9][4].item.type=chesstype.jiang;

Matrix[9][5].item.type=chesstype.shi;

Matrix[9][6].item.type=chesstype.xiang;

Matrix[9][7].item.type=chesstype.ma;

Matrix[9][8].item.type=chesstype.che;

}

privateboolmovechess(intX,intY)

{

inti,j,k,n=0;

switch(Matrix[chozenX][chozenY].item.type)

{

casechesstype.che:

if(chozenX==X)

{

i=chozenY

chozenY:

Y;

j=chozenY>Y?

chozenY:

Y;

for(k=i+1;k

{

if(Matrix[X][k].item.side!

=player.blank)

{

returnfalse;

}

}

}

if(chozenY==Y)

{

i=chozenX

chozenX:

X;

j=chozenX>X?

chozenX:

X;

for(k=i+1;k

{

if(Matrix[k][Y].item.side!

=player.blank)

{

returnfalse;

}

}

}

setmove(X,Y);

returntrue;

casechesstype.jiang:

if(Matrix[X][Y].item.type==chesstype.jiang&&chozenY==Y)

{

i=chozenX

chozenX:

X;

j=chozenX>X?

chozenX:

X;

for(k=i+1;k

{

if(Matrix[k][Y].item.side!

=player.blank)

{

returnfalse;

}

}

setmove(X,Y);

returntrue;

}

if(Matrix[chozenX][chozenY].item.side==player.blue)

{

if(Y<3||Y>5||X>2)

{

returnfalse;

}

}

else

{

if(Y<3||Y>5||X<7)

{

returnfalse;

}

}

if((chozenX-X)*(chozenX-X)+(chozenY-Y)*(chozenY-Y)!

=1)

{

returnfalse;

}

setmove(X,Y);

returntrue;

casechesstype.ma:

if(Math.Abs(chozenX-X)==1&&Math.Abs(chozenY-Y)==2)

{

if(Matrix[chozenX][chozenY+(Y-chozenY)/Math.Abs(Y-chozenY)].item.side!

=player.blank)

{

returnfalse;

}

}

elseif(Math.Abs(chozenX-X)==2&&Math.Abs(chozenY-Y)==1)

{

if(Matrix[chozenX+(X-chozenX)/Math.Abs(X-chozenX)][chozenY].item.side!

=player.blank)

{

returnfalse;

}

}

else

{

returnfalse;

}

setmove(X,Y);

returntrue;

casechesstype.pao:

n=0;

if(chozenX==X)

{

i=chozenY

chozenY:

Y;

j=chozenY>Y?

chozenY:

Y;

n=0;

for(k=i+1;k

{

if(Matrix[X][k].item.side!

=player.blank)

{

n++;

}

}

if(n>1

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2