已阅读5页,还剩8页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
C+语言五子棋源程序C+语言五子棋源程序 (利用坐标确定棋子位置) * C+语言五子棋源程序 * 运行环境:TC3.0 (vc6.0不支持画图函数,无法画出棋盘和棋子) * #define backcolor CYAN #define defaultcolor BLACK #define linecolor MAGENTA #define player1_color RED #define player2_color WHITE #define error_color RED #define winner_color RED const int left=40; const int top=390; const int d=30; const int line_num=9; const int turn=0; const int r=d/3; const int j=10; int x,y,k=1,step=(line_num+1)*(line_num+1); union REGS regs1,regs2; class player1; class player2; class qipan public: qipan(); qipan(); void init_qipan(); friend void fall(player1 &num1,player2 &num2,qipan &num); friend void input(player1 &num1,player2 &num2,qipan &num); private: int pointline_num+1line_num+1; ; class player1 public: player1(); player1(); friend void fall(player1 &num1,player2 &num2,qipan &num); friend void input(player1 &num1,player2 &num2); friend int judge_winner(player1 &num1,player2 &num2); private: int point1line_num+1line_num+1; ; class player2 public: player2(); player2(); friend void fall(player1 &num1,player2 &num2,qipan &num); friend void input(player1 &num1,player2 &num2,qipan &num); friend int judge_winner(player1 &num1,player2 &num2); private: int point2line_num+1line_num+1; ; void input(player1 &num1,player2 &num2); void fall(player1 &num1,player2 &num2,qipan &num); int judge_winner(qipan &num,player1 &num1,player2 &num2); void inputerror(); void display_winner(int); void main() int driver=DETECT,mode; initgraph(&driver,&mode,e:tc30bgi); qipan num; player1 num1; player2 num2; while(step-) input(num1,num2,num); fall(num1,num2,num); if(judge_winner(num1,num2) display_winner(k); / getchar(); qipan:qipan(void) int j,i; char ch2=0; setbkcolor(backcolor); setcolor(linecolor); for(i=0;i=line_num;i+) line(left,top-i*d,left+line_num*d,top-i*d); for(i=0;i=line_num;i+) line(left+i*d,top,left+i*d,top-line_num*d); for(i=0;i=line_num;i+) if(*ch=9+1) *ch=a; settextstyle(DEFAULT_FONT,HORIZ_DIR,1); outtextxy(left+i*d-2,top+r+3,ch); (*ch)=(*ch)+1; *ch=0; for(i=0;i=line_num;i+) if(*ch=9+1) *ch=a; settextstyle(DEFAULT_FONT,HORIZ_DIR,1); outtextxy(left-r-10,top-d*i-3,ch); (*ch)=(*ch)+1; setcolor(defaultcolor); for(i=0;i=line_num;i+) for(j=0;j=line_num;j+) pointij=0; void fall(player1 &num1,player2 &num2,qipan &num) int flag=k%2; if(flag) setcolor(player2_color); num2.point2xy=1; num.pointxy=2; circle(left+d*x,top-d*y,r); setfillstyle(1,player2_color); floodfill(left+d*x,top-d*y,player2_color); else num1.point1xy=1; num.pointxy=1; setcolor(player1_color); circle(left+d*x,top-d*y,r); setfillstyle(1,player1_color); floodfill(left+d*x,top-d*y,player1_color); setcolor(defaultcolor); void input(player1 &num1,player2 &num2,qipan &num) char xx,yy; k+; while(1) regs1.h.ah=0; xx=int86(22,s1,s1)-0; if(xx=(q-0)|xx=(Q-0) step=0; return; regs1.h.ah=0; yy=int86(22,s1,s1)-0; if(yy=(q-0)|yy=(Q-0) step=0; return ; if(xxline_num) inputerror(); continue; if(yyline_num) inputerror(); continue; if(num.pointxxyy=0) break; else inputerror(); continue; x=(int)xx; y=(int)yy; setcolor(backcolor); settextstyle(DEFAULT_FONT,HORIZ_DIR,1); outtextxy(left+d*line_num/3,top+d*2,Input error); setcolor(defaultcolor); player1:player1() int i,j; for(i=0;i=line_num;i+) for(j=0;j=line_num;j+) point1ij=0; player2:player2() int i,j; for(i=0;i=line_num;i+) for(j=0;j=line_num;j+) point2ij=0; void inputerror(void) setcolor(error_color); settextstyle(DEFAULT_FONT,HORIZ_DIR,1); outtextxy(left+d*line_num/3,top+d*2,Input error); setcolor(defaultcolor); int judge_winner(player1 &num1,player2 &num2) int count=0,m=0,n=0,a=0,b=0,xx0,yy0; int flag=k%2; xx0=x; yy0=y; if(!flag) /left right while(xx0=1&m4) xx0-;m+; while(n9&xx0=line_num) if(num1.point1xx0y=1) count+; if(count=5) return 1; else count=0; n+; xx0+; /up down count=0; xx0=x; m=0; n=0; while(yy0=1&m4)yy0-;m+; while(n9&yy0=1&m4) xx0-; a+; m+; m=0; while(yy0=line_num&m4) yy0+; b+; m+; if(a=b) xx0=x-a; yy0=y+a; else xx0=x-b; yy0=y+b; while(xx0=0&n9) if(num1.point1xx0yy0=1) count+; if(count=5) return 1; else count=0; xx0+; yy0-; n+; /right up left down count=0; a=0; b=0; n=0; m=0; xx0=x; yy0=y; while(xx0while(yy0if(a=0&yy0=0&n9) if(num1.point1xx0yy0=1) count+; if(count=5) return 1; else count=0; xx0-; yy0-; n+; /no winer return 0; else /left right while(xx0=1&m4) xx0-;m+; while(n9&xx0=line_num) if(num1.point1xx0y=1) count+; if(count=5) return 1; else count=0; n+; xx0+; /up down count=0; xx0=x; m=0; n=0; while(yy0=1&m4)yy0-;m+; while(n9&yy0=1&m4) xx0-; a+; m+; m=0; while(yy0=line_num&m4) yy0+; b+; m+; if(a=b) xx0=x-a; yy0=y+a; else xx0=x-b; yy0=y+b; while(xx0=0&n9) if(num2.point2xx0yy0=1) count+; if(count=5) return 1; else count=0; xx0+; yy0-; n+; /right up left down count=0; a=0; b=0; n=0; m=0; xx0=x; yy0=y; while(xx0while(yy0if(a=0&yy0=0&n9) if(num2.point2xx0yy0=1) count+; if(count=5) return 1; else count=0; xx0-; yy0-; n+; /no winer return 0; void display_winner(int k) int flag=k%2; if(!flag) setcolor(winner_color); settextstyle(DE
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年审计实务操作技能情景模拟题库
- 2026年各乡镇防汛抗旱应急预案题库
- 2026年天津中石化新材料岗招聘笔试题库
- 2026年发改系统资源综合利用案例考核题库
- 2026年政府采购政策与实务测试题库
- 2026年物流与供应链管理专业知识题
- 2026年艺术系列戏曲专业职称考试唱腔与身段考核指南
- 2026年眼镜制配场所计量器具配备与强制检定考核
- 2026年职场礼仪与商务沟通技能考核题目
- 2026年网络安全技术与管理单选题库培训专用
- 数据安全管理员(高级技师)职业技能鉴定考试题库(共500题)
- 年中考化学酸碱盐复习课件
- 消防安全法律法规知识培训内容
- 2025年中考盐城试卷及答案物理
- 2025上海小额贷款合同范本
- 2025年CCAA国家注册审核员考试(IATF16949内审员基础)综合能力测试题
- HB20542-2018航空用高闪点溶剂型清洗剂规范
- 2025年全国同等学力申硕考试(生物学)历年参考题库含答案详解(5卷)
- ESG基础知识培训课件
- 工贸行业隐患排查指导手册
- DB31∕T 1487-2024 国际医疗服务规范
评论
0/150
提交评论