1、1C 语言游戏之五子棋源代码#include #include #include #include #include #define LEFT 0x4b00 #define RIGHT 0x4d00 #define DOWN 0x5000 #define UP 0x4800 #define ESC 0x011b #define SPACE 0x3920 #define BILI 20 #define JZ 4 #define JS 3 #define N 19 int boxNN; int step_x,step_y ; int key ; int flag=1 ; void draw_box
2、(); void draw_cicle(int x,int y,int color); void change(); void judgewho(int x,int y); void judgekey(); int judgeresult(int x,int y); void attentoin(); void attention() char ch ; window(1,1,80,25); textbackground(LIGHTBLUE); textcolor(YELLOW); clrscr(); gotoxy(15,2); printf(“游戏操作规则:“); gotoxy(15,4);
3、 printf(“Play Rules:“); gotoxy(15,6); printf(“1、按左右上下方向键移动棋子“); gotoxy(15,8); printf(“1. Press Left,Right,Up,Down Key to move Piece“); gotoxy(15,10); printf(“2、按空格确定落棋子“); gotoxy(15,12); printf(“2. Press Space to place the Piece“); gotoxy(15,14); printf(“3、禁止在棋盘外按空格“); gotoxy(15,16); printf(“3. DO N
4、OT press Space outside of the chessboard“); gotoxy(15,18); printf(“你是否接受上述的游戏规则(Y/N)“); gotoxy(15,20); printf(“Do you accept the above Playing Rules? Y/N:“); while(1) gotoxy(60,20); ch=getche(); if(ch=Y|ch=y) break ; else if(ch=N|ch=n) window(1,1,80,25); textbackground(BLACK); textcolor(LIGHTGRAY);
5、clrscr(); exit(0); gotoxy(51,12); printf(“ “); void draw_box() 2 int x1,x2,y1,y2 ; setbkcolor(LIGHTBLUE); setcolor(YELLOW); gotoxy(7,2); printf(“Left, Right, Up, Down KEY to move, Space to put, ESC-quit.“); for(x1=1,y1=1,y2=18;x1=1;i-) if(boxij=0) draw_circle(step_x,step_y,LIGHTBLUE); break ; if(i18
6、) break ; else for(i=step_x+1,j=step_y;i18)break ; step_x=i ; judgewho(step_x,step_y); break ; case DOWN : if(step_y+1)18) break ; else for(i=step_x,j=step_y+1;j18)break ; step_y=j ; judgewho(step_x,step_y); break ; case UP : if(step_y-1)=1;j-) if(boxij=0) draw_circle(step_x,step_y,LIGHTBLUE); break
7、 ; if(j=1j-) if(boxjk=flag) n1+; else break ; /*水平向右数*/ for(j=x,k=y;j=5) return(1); break ; /*垂直向上数*/ n1=0 ; n2=0 ; for(j=x,k=y;k=1;k-) if(boxjk=flag) n1+; else break ; /*垂直向下数*/ for(j=x,k=y;k=5) return(1); break ; /*向左上方数*/ n1=0 ; n2=0 ; for(j=x,k=y;j=1,k=1;j-,k-) if(boxjk=flag) n1+; else break ; /
8、*向右下方数*/ for(j=x,k=y;j=5) return(1); break ; /*向右上方数*/ n1=0 ; n2=0 ; for(j=x,k=y;j=1;j+,k-) if(boxjk=flag)n1+; else break ; /*向左下方数*/ for(j=x,k=y;j=1,k=5) return(1); break ; return(0); break ; void main() int gdriver=VGA,gmode=VGAHI; clrscr(); attention(); initgraph( /* setwritemode(XOR_PUT);*/ flag=1 ; draw_box(); do step_x=0 ; step_y=0 ; /*draw_circle(step_x,step_y,8); */ judgewho(step_x-1,step_y-1); do while(bioskey(1)=0); key=bioskey(0); judgekey(); while(key!=SPACE while(key!=ESC); closegraph(); 6