https://www.myziyuan.com/
- 1264737478
- 这个程序还需要两个文件,告诉我你邮箱,我发给你源程序前半部分/*加载头文件*/#include<stdio.h>#include<stdlib.h>#include<graphics.h>#include<bios.h>#include<conio.h>/*编译预处理,定义按键码*/#define LEFT 0x4b00 #define RIGHT 0x4d00 #define DOWN 0x5000 #define UP 0x4800 /*若想在游戏中途退出, 可按 Esc 键*/#define ESC 0x011b /*SPACE键表示落子*/#define SPACE 0x3920/*设置偏移量*/#define OFFSET 20#define OFFSET_x 4#define OFFSET_y 3/*定义数组大小*/#define N 19 /*定义全局变量*/int status[N][N]; /*定义的数组,保存状态*/int step_x,step_y;/*行走的坐标*/int key ; /*获取按下的键盘的键*/int flag; /*玩家标志*//*自定义函数原型*/void DrawBoard();void DrawCircle(int x,int y,int color);void Alternation();void JudgePlayer(int x,int y);void Done();int ResultCheck(int x,int y);void WelcomeInfo();void ShowMessage();/*定义函数*//*显示欢迎信息函数*/void WelcomeInfo(){ char ch ; /*移动光标到指定位置*/ gotoxy(12,4); /*显示欢迎信息*/ printf("Welcome you to gobang word!"); gotoxy(12,6); printf("1.You can use the up,down,left and right key to move the chessman,"); gotoxy(12,8); printf(" and you can press Space key to enter after you move it !"); gotoxy(12,10); printf("2.You can use Esc key to exit the game too !"); gotoxy(12,12); printf("3.Don not move the pieces out of the chessboard !"); gotoxy(12,14); printf("DO you want to continue ?(Y/N)"); ch=getchar(); /*判断程序是否要继续进行*/ if(ch=='n'||ch=='N') /*如果不继续进行,则推出程序*/ exit(0);}/*画棋盘函数*/void DrawBoard(){ int x1,x2; int y1,y2; /*设置背景色*/ setbkcolor(2); /*设置线条颜色*/ setcolor(1); /*设置线条风格、宽度*/ setlinestyle(DOTTED_LINE,1,1); /*按照预设的偏移量开始画棋盘*/ for(x1=1,y1=1,y2=18;x1<=18;x1++) line((x1+OFFSET_x)*OFFSET,(y1+OFFSET_y)*OFFSET,(x1+OFFSET_x)*OFFSET,(y2+OFFSET_y)*OFFSET); for(x1=1,y1=1,x2=18;y1<=18;y1++) line((x1+OFFSET_x)*OFFSET,(y1+OFFSET_y)*OFFSET,(x2+OFFSET_x)*OFFSET,(y1+OFFSET_y)*OFFSET); /*将各个点的状态设置为0*/ for(x1=1;x1<=18;x1++) for(y1=1;y1<=18;y1++) status[x1][y1]=0; /*显示帮助信息*/ setcolor(14); /*设置字体、大小*/ settextstyle(1,0,1); outtextxy((19+OFFSET_x)*OFFSET,(2+OFFSET_y)*OFFSET,"Player key:"); setcolor(9); settextstyle(3,0,1); outtextxy((19+OFFSET_x)*OFFSET,(4+OFFSET_y)*OFFSET,"UP--up "); outtextxy((19+OFFSET_x)*OFFSET,(6+OFFSET_y)*OFFSET,"DOWN--down "); outtextxy((19+OFFSET_x)*OFFSET,(8+OFFSET_y)*OFFSET,"LEFT--left"); outtextxy((19+OFFSET_x)*OFFSET,(10+OFFSET_y)*OFFSET,"RIGHT--right"); outtextxy((19+OFFSET_x)*OFFSET,(12+OFFSET_y)*OFFSET,"ENTER--space"); setcolor(14); settextstyle(1,0,1); outtextxy((19+OFFSET_x)*OFFSET,(14+OFFSET_y)*OFFSET,"Exit:"); setcolor(9); settextstyle(3,0,1); outtextxy((19+OFFSET_x)*OFFSET,(16+OFFSET_y)*OFFSET,"ESC");}/*画圆函数*/void DrawCircle(int x,int y,int color){ setcolor(color); /*设置画圆线条的风格,宽度,这里设置为虚线*/ setlinestyle(SOLID_LINE,0,1); x=(x+OFFSET_x)*OFFSET; y=(y+OFFSET_y)*OFFSET; /*以(x,y)为圆心,8为半径画圆*/ circle(x,y,8);} /*交换行棋方函数*/void Alternation(){ if(flag==1) flag=2 ; else flag=1 ;} /*对不同的行棋方画不同颜色的圆函数*/void JudgePlayer(int x,int y){ if(flag==1) DrawCircle(x,y,15); if(flag==2) DrawCircle(x,y,4);}/*判断当前行棋方是否获胜函数*/int ResultCheck(int x,int y){ int j,k; int n1,n2 ; while(1) { /*对水平方向进行判断是否有5个同色的圆*/ n1=0; n2=0; /*水平向左数*/ for(j=x,k=y;j>=1;j--) { if(status[j][k]==flag) n1++; else break; } /*水平向右数*/ for(j=x,k=y;j<=18;j++) { if(status[j][k]==flag) n2++; else break; } if(n1+n2-1>=5) { return(1); } /*对垂直方向进行判断是否有5个同色的圆*/ n1=0; n2=0; /*垂直向上数*/ for(j=x,k=y;k>=1;k--) { if(status[j][k]==flag) n1++; else break ; } /*垂直向下数*/ for(j=x,k=y;k<=18;k++) { if(status[j][k]==flag) n2++; else break ; } if(n1+n2-1>=5) { return(1); } /*从左上方到右下方进行判断是否有5个同色的圆*/ n1=0; n2=0; /*向左上方数*/ for(j=x,k=y;(j>=1)&&(k>=1);j--,k--) { if(status[j][k]==flag) n1++; else break; } /*向右下方数*/ for(j=x,k=y;(j<=18)&&(k<=18);j++,k++) { if(status[j][k]==flag) n2++; else break; } if(n1+n2-1>=5) { return(1); } /*从右上方到左下方进行判断是否有5个同色的圆*/ n1=0; n2=0; /*向右上方数*/ for(j=x,k=y;(j<=18)&&(k>=1);j++,k--) { if(status[j][k]==flag) n1++; else break; } /*向左下方数*/ for(j=x,k=y;(j>=1)&&(k<=18);j--,k++) { if(status[j][k]==flag) n2++; else break; } if(n1+n2-1>=5) { return(1); } return(0); }}
- 2021-03-25 02:05:01
- nij
- Image img=Toolkit.getDefaultToolkit().getImage(路径文件名);
- 2021-02-12 13:02:19
- 追梦
- 网页版五子棋小游戏源代码下载那里有,网页版五子棋,源代码下载,在线演示,请访问http://www.zhangxueen.com/index.asp?boardid=5祝福你学有所成,我们共同进步!!
- 2021-02-12 13:02:19