中国象棋游戏源代码文档格式.docx
《中国象棋游戏源代码文档格式.docx》由会员分享,可在线阅读,更多相关《中国象棋游戏源代码文档格式.docx(18页珍藏版)》请在冰豆网上搜索。
publicPictureBoxcontainer;
publicchessitem;
publicpartialclassForm1:
Form
publicForm1()
InitializeComponent();
pictureboxlist=newList<
PictureBox>
(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;
107;
+i,false);
bluecool.add(col[0]asPictureBox);
for(i=107;
123;
redcoll.add(col[0]asPictureBox);
resetground();
List<
pictureboxlist;
block[][]Matrix;
collecterredcoll;
collecterbluecool;
intchozenX;
intchozenY;
playercurrentside;
boolbeenchozen;
boolclickswitch;
privatevoidclick1(objectsender,EventArgse)
if(!
clickswitch)
return;
stringname=(senderasPictureBox).Name;
stringnumber=name.Substring(10);
intindex=Convert.ToInt32(number);
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)
if(Matrix[chozenX][chozenY].item.side!
=player.blank)
if(Matrix[i][j].item.type==chesstype.jiang)
flag=true;
movechess(i,j))
if(flag)
if(currentside==player.red)
MessageBox.Show("
红方胜利!
点击任意处重新开局"
);
else
蓝方胜利!
clickswitch=false;
{
currentside=player.blue;
label1.Text="
蓝方"
;
label1.ForeColor=Color.Blue;
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;
Matrix[i][j].container.Image=null;
Matrix[i][j].item.side=player.blank;
Matrix[i][j].item.type=chesstype.blank;
clickswitch=true;
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:
Matrix[0][6].container.Image=global:
Matrix[0][7].container.Image=global:
Matrix[0][8].container.Image=global:
Matrix[2][1].container.Image=global:
象棋.Properties.Resources.蓝炮;
Matrix[2][7].container.Image=global:
Matrix[3][0].container.Image=global:
象棋.Properties.Resources.蓝卒;
Matrix[3][2].container.Image=global:
Matrix[3][4].container.Image=global:
Matrix[3][6].container.Image=global:
Matrix[3][8].container.Image=global:
Matrix[6][0].container.Image=global:
象棋.Properties.Resources.红卒;
Matrix[6][2].container.Image=global:
Matrix[6][4].container.Image=global:
Matrix[6][6].container.Image=global:
Matrix[6][8].container.Image=global:
Matrix[7][1].container.Image=global:
象棋.Properties.Resources.红炮;
Matrix[7][7].container.Image=global:
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:
Matrix[9][6].container.Image=global:
Matrix[9][7].container.Image=global:
Matrix[9][8].container.Image=global:
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<
Y?
chozenY:
Y;
j=chozenY>
for(k=i+1;
k<
j;
k++)
if(Matrix[X][k].item.side!
returnfalse;
if(chozenY==Y)
i=chozenX<
X?
chozenX:
X;
j=chozenX>
for(k=i+1;
k<
j;
k++)
if(Matrix[k][Y].item.side!
returnfalse;
setmove(X,Y);
returntrue;
casechesstype.jiang:
if(Matrix[X][Y].item.type==chesstype.jiang&
&
chozenY==Y)
returntrue;
if(Matrix[chozenX][chozenY].item.side==player.blue)
{
if(Y<
3||Y>
5||X>
2)
5||X<
7)
if((chozenX-X)*(chozenX-X)+(chozenY-Y)*(chozenY-Y)!
=1)
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!
elseif(Math.Abs(chozenX-X)==2&
Math.Abs(chozenY-Y)==1)
if(Matrix[chozenX+(X-chozenX)/Math.Abs(X-chozenX)][chozenY].item.side!
casechesstype.pao:
n=0;
i=chozenY<
if(Matrix[X][k].item.side!
n