五子棋C语言代码(共8页).docx





《五子棋C语言代码(共8页).docx》由会员分享,可在线阅读,更多相关《五子棋C语言代码(共8页).docx(8页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上#include graphics.h /*图形系统头文件*/#define LEFT 0x4b00 /*光标左键值*/#define RIGHT 0x4d00 /*光标右键值*/#define DOWN 0x5000 /*光标下键值*/#define UP 0x4800 /*光标上键值*/#define ESC 0x011b /* ESC键值*/#define ENTER 0x1c0d /* 回车键值*/int a88=0,key,score1,score2;/*具体分数以及按键与存放棋子的变量*/char playone3,playtwo3;/*两个人的得分转换成
2、字符串输出*/void playtoplay(void);/*人人对战函数*/void DrawQp(void);/*画棋盘函数*/void SetPlayColor(int x);/*设置棋子第一次的颜色*/void MoveColor(int x,int y);/*恢复原来棋盘状态*/int QpChange(int x,int y,int z);/*判断棋盘的变化*/void DoScore(void);/*处理分数*/void PrintScore(int n);/*输出成绩*/void playWin(void);/*输出胜利者信息*/*主函数*/void main(void) in
3、t gd=DETECT,gr; initgraph(&gd,&gr,c:tc); /*初始化图形系统*/ DrawQp();/*画棋盘*/ playtoplay();/*人人对战*/ getch(); closegraph();/*关闭图形系统*/void DrawQp()/*画棋盘*/ int i,j; score1=score2=0;/*棋手一开始得分都为0*/ setbkcolor(BLUE); for(i=100;i=64-score1-score2) /*如果尝试超过空格数则停步*/ MoveColor(x,y); fillellipse(x,y,15,15); break; els
4、e continue;/*如果按键无效*/ DoScore();/*分数的改变*/ break;/*棋盘变化了,则轮对方走棋*/ else/*已经有棋子就继续按键*/ continue; else /*四个方向按键的判断*/ if(key=LEFT&x120)/*左方向键*/ MoveColor(x,y); fillellipse(x,y,15,15); SetPlayColor(t); x-=40; fillellipse(x,y,15,15); else if(key=RIGHT&x80)/*右方向键*/ MoveColor(x,y); fillellipse(x,y,15,15); Se
5、tPlayColor(t); x+=40; fillellipse(x,y,15,15); else if(key=UP&y120)/*上方向键*/ MoveColor(x,y); fillellipse(x,y,15,15); SetPlayColor(t); y-=40; fillellipse(x,y,15,15); else if(key=DOWN&y400)/*下方向键*/ MoveColor(x,y); fillellipse(x,y,15,15); SetPlayColor(t); y+=40; fillellipse(x,y,15,15); if(key=ESC)/*结束游戏*
6、/ break; if(score1+score2)=64|score1=0|score2=0)/*格子已经占满或一方棋子为0判断胜负*/ playWin();/*输出最后结果*/ break; t=t%2+1; /*一方走后,改变棋子颜色即轮对方走*/ cc=0; /*计数值恢复为0*/ /*endwhile*/void SetPlayColor(int t)/*设置棋子颜色*/ if(t%2=1) setfillstyle(SOLID_FILL,15);/*白色*/ else setfillstyle(SOLID_FILL,8);/*灰色*/void MoveColor(int x,int
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 五子棋 语言 代码

限制150内