资源描述:
《C语言程序源代码---中国象棋》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include#include#include#include#include#include"c:tcLIB1.c"#defineW119#defineS115#defineA97#defineD100#definespace32#defineUP72#defineDOWN80#defineLEFT75#defineRIGHT77#defineENTER13voidqipan();voidjiemi
2、an(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=DETE
3、CT;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)
4、;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
5、+40);}if(c==97){fputs("A",fp);x=x-40;guangbiao1(x,y);guangbiao2(x+40,y);}if(c==100){fputs("D",fp);x=x+40;guangbiao1(x,y);guangbiao2(x-40,y);}if(c==13){fputs("enter",fp);xuanzhong(x,y);m=x;n=y;}if(c==32){fputs("space",fp);xiazi(m,n,x,y);fputs("gaiz
6、i",fp);gaizi(m,n);}if(x>350
7、
8、y>390
9、
10、x<30
11、
12、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
13、);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(
14、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_j