C语言程序源代码中国象棋.docx
- 文档编号:3099600
- 上传时间:2022-11-17
- 格式:DOCX
- 页数:15
- 大小:16.55KB
C语言程序源代码中国象棋.docx
《C语言程序源代码中国象棋.docx》由会员分享,可在线阅读,更多相关《C语言程序源代码中国象棋.docx(15页珍藏版)》请在冰豆网上搜索。
C语言程序源代码中国象棋
#include
#include
#include
#include
#include
#include"c:
\tc\LIB\1.c"
#defineW119
#defineS115
#defineA97
#defineD100
#definespace32
#defineUP72
#defineDOWN80
#defineLEFT75
#defineRIGHT77
#defineENTER13
voidqipan();
voidjiemian(int);
voidguangbiao1(int,int);
voidguangbiao2(int,int);
voidxuanzhong(int,int);
voidgaizi(int,int);
chararray(int,int);
voidxiazi(int,int,int,int);
/*intpanding(char,int,int,int,int);*/
main()
{
intgdriver,gmode,i=0,c=0,x=190,y=190,m,n;
charp;
FILE*fp;
gdriver=DETECT;
gmode=0;
if((fp=fopen("file.txt","at"))==NULL)
{
printf("Cannotopenfile!
");
system("pause");
exit(0);
}
printf("%d,%d",gdriver,gmode);
registerbgidriver(EGAVGA_driver);
initgraph(&gdriver,&gmode,"c:
\\tc");
cleardevice();
while(c!
=27)
{
c=getch();
clrscr();
jiemian(i);
if(c==80)
{
fputs("down",fp);
i++;
if(i==4)
{
i=0;
}
}
if(i==1)
{
if(c==13)
{
fputs("enter",fp);
qipan();
c=getch();
while(c!
=27)
{
c=getch();
if(c==115)
{
fputs("S",fp);
y=y+40;
guangbiao1(x,y);
guangbiao2(x,y-40);
}
if(c==119)
{
fputs("W",fp);
y=y-40;
guangbiao1(x,y);
guangbiao2(x,y+40);
}
if(c==97)
{fputs("A\n",fp);
x=x-40;
guangbiao1(x,y);
guangbiao2(x+40,y);
}
if(c==100)
{fputs("D\n",fp);
x=x+40;
guangbiao1(x,y);
guangbiao2(x-40,y);
}
if(c==13)
{
fputs("enter\n",fp);
xuanzhong(x,y);
m=x;n=y;
}
if(c==32)
{
fputs("space\n",fp);
xiazi(m,n,x,y);
fputs("gaizi\n",fp);
gaizi(m,n);
}
if(x>350||y>390||x<30||y<30)
{
x=190;y=30;
}
}
}
}
}
getch();
closegraph();
fclose(fp);
restorecrtmode();
return0;
}
voidqipan()
{
inti,j;
setbkcolor(GREEN);
cleardevice();
setlinestyle(0,0,3);
setcolor
(1);
rectangle(10,10,370,410);
rectangle(30,30,350,390);
for(i=1;i<8;i++)
{
setlinestyle(0,0,3);
line(i*40+30,30,i*40+30,190);
line(i*40+30,230,i*40+30,390);
}
for(j=1;j<9;j++)
{
setlinestyle(0,0,3);
line(30,j*40+30,350,j*40+30);
}
setlinestyle(3,0,3);
line(150,30,230,110);
line(230,30,150,110);
line(150,310,230,390);
line(230,310,150,390);
setusercharsize(4,1,2,1);
settextstyle(1,0,4);
outtextxy(70,195,"chinesechess");
red_shuai(190,30);
red_shi(150,30);
red_shi(230,30);
red_xiang(110,30);
red_xiang(270,30);
red_ma(70,30);
red_ma(310,30);
red_ju(30,30);
red_ju(350,30);
red_pao(70,110);
red_pao(310,110);
red_bing(30,150);
red_bing(110,150);
red_bing(190,150);
red_bing(270,150);
red_bing(350,150);
black_jiang(190,390);
black_shi(150,390);
black_shi(230,390);
black_xiang(110,390);
black_xiang(270,390);
black_ma(70,390);
black_ma(310,390);
black_ju(30,390);
black_ju(350,390);
black_pao(70,310);
black_pao(310,310);
black_zu(30,270);
black_zu(110,270);
black_zu(190,270);
black_zu(270,270);
black_zu(350,270);
setcolor(BLUE);
rectangle(400,30,600,320);
setcolor(4);
settextstyle(1,0,2);
outtextxy(420,50,"A->shuaiB->shi");
outtextxy(420,80,"C->xiangD->ma");
outtextxy(420,110,"E->juF->pao");
outtextxy(420,140,"G->bing");
setcolor(8);
outtextxy(420,200,"H->jiangI->shi");
outtextxy(420,230,"J->xiangK->ma");
outtextxy(420,260,"L->juM->pao");
outtextxy(420,290,"N->zu");
}
voidjiemian(inti)
{
setbkcolor(GREEN);
cleardevice();
settextstyle(1,0,8);
setcolor(BLUE);
outtextxy(50,70,"chinesechess");
settextstyle(0,0,3);
setcolor(RED);
outtextxy(260,215,"start");
outtextxy(260,255,"again");
outtextxy(260,295,"undo");
outtextxy(260,335,"exit");
rectangle(250,210+i*40,390,240+i*40);
}
voidguangbiao1(intx,inty)
{
setcolor(WHITE);
setlinestyle(0,0,3);
line(x-17,y-7,x-17,y-17);
line(x-7,y-17,x-17,y-17);
line(x+7,y-17,x+17,y-17);
line(x+17,y-7,x+17,y-17);
line(x-7,y+17,x-17,y+17);
line(x-17,y+7,x-17,y+17);
line(x+17,y+7,x+17,y+17);
line(x+7,y+17,x+17,y+17);
}
voidguangbiao2(intx,inty)
{
setcolor(GREEN);
setlinestyle(0,0,3);
line(x-17,y-7,x-17,y-17);
line(x-7,y-17,x-17,y-17);
line(x+7,y-17,x+17,y-17);
line(x+17,y-7,x+17,y-17);
line(x-7,y+17,x-17,y+17);
line(x-17,y+7,x-17,y+17);
line(x+17,y+7,x+17,y+17);
line(x+7,y+17,x+17,y+17);
}
voidxuanzhong(intx,inty)
{
setcolor(CYAN);
setlinestyle(0,0,3);
circle(x,y,15);
}
voidgaizi(intx1,inty1)
{
setlinestyle(0,0,3);
setcolor(GREEN);
circle(x1,y1,15);
setfillstyle(0,3);
floodfill(x1,y1,GREEN);
setcolor
(1);
setlinestyle(0,0,3);
if((30 { line(x1-18,y1,x1+18,y1); line(x1,y1,x1,y1+18); } if((30 { line(x1-18,y1,x1+18,y1); line(x1,y1-18,x1,y1); } if((30 { line(x1,y1,x1+18,y1); line(x1,y1-18,x1,y1+18); } if((30 { line(x1-18,y1,x1,y1); line(x1,y1-18,x1,y1+18); } if((x1==3
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 程序 源代码 中国象棋