C语言游戏之五子棋源代码.doc
上传人:qw****27 上传时间:2024-09-11 格式:DOC 页数:5 大小:33KB 金币:15 举报 版权申诉
预览加载中,请您耐心等待几秒...

C语言游戏之五子棋源代码.doc

C语言游戏之五子棋源代码.doc

预览

在线预览结束,喜欢就下载吧,查找使用更方便

15 金币

下载此文档

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

C语言游戏之五子棋源代码#include<stdio.h>#include<stdlib.h>#include<graphics.h>#include<bios.h>#include<conio.h>#defineLEFT0x4b00#defineRIGHT0x4d00#defineDOWN0x5000#defineUP0x4800#defineESC0x011b#defineSPACE0x3920#defineBILI20#defineJZ4#defineJS3#defineN19intbox[N][N];intstep_x,step_y;intkey;intflag=1;voiddraw_box();voiddraw_cicle(intx,inty,intcolor);voidchange();voidjudgewho(intx,inty);voidjudgekey();intjudgeresult(intx,inty);voidattentoin();voidattention(){charch;window(1,1,80,25);textbackground(LIGHTBLUE);textcolor(YELLOW);clrscr();gotoxy(15,2);printf("游戏操作规则:");gotoxy(15,4);printf("PlayRules:");gotoxy(15,6);printf("1、按左右上下方向键移动棋子");gotoxy(15,8);printf("1.PressLeft,Right,Up,DownKeytomovePiece");gotoxy(15,10);printf("2、按空格确定落棋子");gotoxy(15,12);printf("2.PressSpacetoplacethePiece");gotoxy(15,14);printf("3、禁止在棋盘外按空格");gotoxy(15,16);printf("3.DONOTpressSpaceoutsideofthechessboard");gotoxy(15,18);printf("你是否接受上述的游戏规则(Y/N)");gotoxy(15,20);printf("DoyouaccepttheabovePlayingRules?[Y/N]:");while(1){gotoxy(60,20);ch=getche();if(ch=='Y'||ch=='y')break;elseif(ch=='N'||ch=='n'){window(1,1,80,25);textbackground(BLACK);textcolor(LIGHTGRAY);clrscr();exit(0);}gotoxy(51,12);printf("");}}voiddraw_box(){intx1,x2,y1,y2;setbkcolor(LIGHTBLUE);setcolor(YELLOW);gotoxy(7,2);printf("Left,Right,Up,DownKEYtomove,Spacetoput,ESC-quit.");for(x1=1,y1=1,y2=18;x1<=18;x1++)line((x1+JZ)*BILI,(y1+JS)*BILI,(x1+JZ)*BILI,(y2+JS)*BILI);for(x1=1,y1=1,x2=18;y1<=18;y1++)line((x1+JZ)*BILI,(y1+JS)*BILI,(x2+JZ)*BILI,(y1+JS)*BILI);for(x1=1;x1<=18;x1++)for(y1=1;y1<=18;y1++)box[x1][y1]=0;}voiddraw_circle(intx,inty,intcolor){setcolor(color);setlinestyle(SOLID_LINE,0,1);x=(x+JZ)*BILI;y=(y+JS)*BILI;circle(x,y,8);}voidjudgekey(){inti;intj;switch(key){caseLEFT:if(step_x-1<0)break;else{for(i=step_x-1,j=step_y;i>=1;i--)if(box[i][j]==0){draw_circle(step_x,step_y,LIGHTBLUE);break;}if(i<1)break;step_x=i;judgewho(step_x,step_y);break;}caseRIGHT:if(step_x+1>18)break;else{for(i=step_x+1,j=step_y;i<=18;i++)if(box[i][j]==0){draw_circl