您现在的位置是:爱问
五子棋棋盘怎么画
2021-04-23 05:45爱问
简介1 五子棋棋盘怎么画 横线竖线垂直相交,就是画方格,数量多多宜善。本回答被网友采纳 2 3 怎样用c语言画出五子棋棋盘 ************************************************************** C++语言五子棋源程序 **********************************************...
1
五子棋棋盘怎么画
横线竖线垂直相交,就是画方格,数量多多宜善。 本回答被网友采纳
2
3
怎样用c语言画出五子棋棋盘
************************************************************** C++语言五子棋源程序 ************************************************************* #include <graphics.h> #include <stdio.h> #include <stdlib.h> #include <dos.h> #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 point[line_num+1][line_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 point1[line_num+1][line_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 point2[line_num+1][line_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:\tc30\bgi"); 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 ch[2]="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++) point[i][j]=0; } } void fall(player1 &num1,player2 &num2,qipan &num) { int flag=k%2; if(flag) { setcolor(player2_color); num2.point2[x][y]=1; num.point[x][y]=2; circle(left+d*x,top-d*y,r); setfillstyle(1,player2_color); floodfill(left+d*x,top-d*y,player2_color); } else { num1.point1[x][y]=1; num.point[x][y]=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(xx<0||xx>line_num) { inputerror(); continue; } if(yy<0||yy>line_num) {inputerror(); continue; } if(num.point[xx][yy]==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++) point1[i][j]=0; } } player2::player2() { int i,j; for(i=0;i<=line_num;i++) { for(j=0;j<=line_num;j++) point2[i][j]=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&&m<4) {xx0--;m++;} while(n<9&&xx0<=line_num) { if(num1.point1[xx0][y]==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&&m<4){yy0--;m++;} while(n<9&&yy0<=line_num) { if(num1.point1[x][yy0]==1) { count++; if(count==5) return 1; } else { count=0; } n++; yy0++; } //left up ----- right down xx0=x; yy0=y; m=0; n=0; count=0; while(xx0>=1&&m<4){ xx0--; a++; m++;} m=0; while(yy0<=line_num&&m<4){ yy0++; b++; m++;} if(a<=b) { xx0=x-a; yy0=y+a; } else { xx0=x-b; yy0=y+b; } while(xx0<=line_num&&yy0>=0&&n<9) { if(num1.point1[xx0][yy0]==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(xx0<line_num&&m<4){ xx0++; m++; a++;} m=0; while(yy0<line_num&&m<4){ yy0--; m++; b++; } if(a<=b) { xx0=x+a; yy0=y+a; } else { xx0=x+b; yy0=y+b; } while(xx0>=0&&yy0>=0&&n<9) { if(num1.point1[xx0][yy0]==1) { count++; if(count==5) return 1; } else count=0; xx0--; yy0--; n++; } //no winer return 0; } else { //left <-------> right while(xx0>=1&&m<4) {xx0--;m++;} while(n<9&&xx0<=line_num) { if(num1.point1[xx0][y]==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&&m<4){yy0--;m++;} while(n<9&&yy0<=line_num) { if(num2.point2[x][yy0]==1) { count++; if(count==5) return 1; } else { count=0; } n++; yy0++; } //left up ----- right down xx0=x; yy0=y; m=0; n=0; count=0; while(xx0>=1&&m<4){ xx0--; a++; m++;} m=0; while(yy0<=line_num&&m<4){ yy0++; b++; m++;} if(a<=b) { xx0=x-a; yy0=y+a; } else { xx0=x-b; yy0=y+b; } while(xx0<=line_num&&yy0>=0&&n<9) { if(num2.point2[xx0][yy0]==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(xx0<line_num&&m<4){ xx0++; m++; a++;} m=0; while(yy0<line_num&&m<4){ yy0--; m++; b++; } if(a<=b) { xx0=x+a; yy0=y+a; } else { xx0=x+b; yy0=y+b; } while(xx0>=0&&yy0>=0&&n<9) { if(num2.point2[xx0][yy0]==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(DEFAULT_FONT,HORIZ_DIR,2); outtextxy(left+d*2,top+40,"Red is winner"); setcolor(defaultcolor); step=0; getchar(); } else { setcolor(winner_color); settextstyle(DEFAULT_FONT,HORIZ_DIR,2); outtextxy(left+2*d,top+40,"White is winner"); setcolor(defaultcolor); step=0; } }
4
五子棋棋盘怎么画
不用画。买个围棋盘就行。可以共用 。虽然围棋有点大。但能用。 本回答被网友采纳
5
6
五子棋的棋盘怎么画
都是正方形方格,越多越好
以上是关于五子棋棋盘怎么画的问答
Tags:五子棋棋盘怎么画,五子棋棋盘怎么画,怎样用c语言画出五子棋棋
下一篇:怎样围丝巾比较好看?
相关文章
随机图文
孩子一哭闹家长就妥协?正确教育孩子很重要,不要盲目
在逛商场的时候,相信大家也会看到有许多不一样的小朋友,比如说有很多的小朋友都会不买玩具誓不罢休,甚至...单位打印机冒出条尾巴!女子瑟瑟发抖,蛇怎么进入到办
是很多人都会比较害怕,无论是出现在外面又或者是出现在家中,相信在此时大部分人的心中都会觉得有些恐慌。...荔枝2元/斤?真的可以实现荔枝自由吗?,尽情享受
喜欢吃荔枝的一些武汉市民建议,在选购的时候还是应该选择多对比,或许在不经意之间就可以直接捡到一个大便...雪莲的遭遇是谁在推动?5毛的冰块雪糕为何被人质疑
有人说应该怎么去看待雪莲雪糕的辟谣,有无数的人都会为雪莲鸣不平,也同样是想要为自己的口袋找一些底气,...