发布网友 发布时间:2022-04-20 04:13
共2个回答
热心网友 时间:2023-06-24 16:09
黑白棋游戏#include"graphics.h"/*图形系统头文件*/#defineLEFT0x4b00/*光标左键值*/#defineRIGHT0x4d00/*光标右键值*/#defineDOWN0x5000/*光标下键值*/#defineUP0x4800/*光标上键值*/#defineESC0x011b/*ESC键值*/#defineENTER0x1c0d/*回车键值*/inta[8][8]={0},key,score1,score2;/*具体分数以及按键与存放棋子的变量*/charplayone[3],playtwo[3];/*两个人的得分转换成字符串输出*/voidplaytoplay(void);/*人人对战函数*/voidDrawQp(void);/*画棋盘函数*/voidSetPlayColor(intx);/*设置棋子第一次的颜色*/voidMoveColor(intx,inty);/*恢复原来棋盘状态*/intQpChange(intx,inty,intz);/*判断棋盘的变化*/voidDoScore(void);/*处理分数*/voidPrintScore(intn);/*输出成绩*/voidplayWin(void);/*输出胜利者信息*//******主函数*********/voidmain(void){intgd=DETECT,gr;initgraph(&gd,&gr,"c:\\tc");/*初始化图形系统*/DrawQp();/*画棋盘*/playtoplay();/*人人对战*/getch();closegraph();/*关闭图形系统*/}voidDrawQp()/*画棋盘*/{inti,j;score1=score2=0;/*棋手一开始得分都为0*/setbkcolor(BLUE);for(i=100;i=64-score1-score2)/*如果尝试超过空格数则停步*/{MoveColor(x,y);fillellipse(x,y,15,15);break;}elsecontinue;/*如果按键无效*/}DoScore();/*分数的改变*/break;/*棋盘变化了,则轮对方走棋*/}else/*已经有棋子就继续按键*/continue;}else/*四个方向按键的判断*/if(key==LEFT&&x>120)/*左方向键*/{MoveColor(x,y);fillellipse(x,y,15,15);SetPlayColor(t);x-=40;fillellipse(x,y,15,15);}elseif(key==RIGHT&&x80)/*右方向键*/{MoveColor(x,y);fillellipse(x,y,15,15);SetPlayColor(t);x+=40;fillellipse(x,y,15,15);}elseif(key==UP&&y>120)/*上方向键*/{MoveColor(x,y);fillellipse(x,y,15,15);SetPlayColor(t);y-=40;fillellipse(x,y,15,15);}elseif(key==DOWN&&y1)/*判断左边*/{for(k=j-1;k>=0;k--)if(a[i][k]==a[i][j]||!a[i][k])break;if(a[i][k]!=0&&k>=0){for(kk=j-1;kk>k&&k>=0;kk--){a[i][kk]=a[i][j];fillellipse(120+i*40,120+kk*40,15,15);}if(kk!=j-1)yes=1;}}if(i1)/*判断上边*/{for(k=i-1;k>=0;k--)if(a[k][j]==a[i][j]||!a[k][j])break;if(a[k][j]!=0&&k>=0){for(kk=i-1;kk>k&&k>=0;kk--){a[kk][j]=a[i][j];fillellipse(120+kk*40,120+j*40,15,15);}if(kk!=i-1)yes=1;}}if(i>1&&j=0&&kk=0&&kkk&&k>=0;ii--,jj++){a[ii][jj]=a[i][j];fillellipse(120+ii*40,120+jj*40,15,15);}if(ii!=i-1)yes=1;}}if(i1)/*左下*/{for(k=i+1,kk=j-1;k=0;k++,kk--)if(a[k][kk]==a[i][j]||!a[k][kk])break;if(a[k][kk]!=0&&k=0){for(ii=i+1,jj=j-1;ii1&&j>1)/*左上*/{for(k=i-1,kk=j-1;k>=0&&kk>=0;k--,kk--)if(a[k][kk]==a[i][j]||!a[k][kk])break;if(a[k][kk]!=0&&k>=0&&kk>=0){for(ii=i-1,jj=j-1;ii>k&&k>=0;ii--,jj--){a[ii][jj]=a[i][j];fillellipse(120+ii*40,120+jj*40,15,15);}if(ii!=i-1)yes=1;}}if(iscore1)/*开始判断最后的结果*/outtextxy(100,50,"blackwin!");elseif(score2#include#include#include#include#defineLEFT0x4b00#defineRIGHT0x4d00#defineDOWN0x5000#defineUP0x4800#defineESC0x011b#defineSPACE0x3920#defineBILI20#defineJZ4#defineJS3#defineN19intbox[N][N];intstep_x,step_y;intkey;intflag=1;voiddraw_box();voiddraw_cicle(intx,inty,intcolor);voidchange();voidjudgewho(intx,inty);voidjudgekey();intjudgeresult(intx,inty);voidattentoin();voidattention(){charch;window(1,1,80,25);textbackground(LIGHTBLUE);textcolor(YELLOW);clrscr();gotoxy(15,2);printf("游戏操作规则:");gotoxy(15,4);printf("PlayRules:");gotoxy(15,6);printf("1、按左右上下方向键移动棋子");gotoxy(15,8);printf("1.PressLeft,Right,Up,DownKeytomovePiece");gotoxy(15,10);printf("2、按空格确定落棋子");gotoxy(15,12);printf("2.PressSpacetoplacethePiece");gotoxy(15,14);printf("3、禁止在棋盘外按空格");gotoxy(15,16);printf("3.DONOTpressSpaceoutsideofthechessboard");gotoxy(15,18);printf("你是否接受上述的游戏规则(Y/N)");gotoxy(15,20);printf("DoyouaccepttheabovePlayingRules?[Y/N]:");while(1){gotoxy(60,20);ch=getche();if(ch=='Y'||ch=='y')break;elseif(ch=='N'||ch=='n'){window(1,1,80,25);textbackground(BLACK);textcolor(LIGHTGRAY);clrscr();exit(0);}gotoxy(51,12);printf("");}}voiddraw_box(){intx1,x2,y1,y2;setbkcolor(LIGHTBLUE);setcolor(YELLOW);gotoxy(7,2);printf("Left,Right,Up,DownKEYtomove,Spacetoput,ESC-quit.");for(x1=1,y1=1,y2=18;x1=1;i--)if(box[i][j]==0){draw_circle(step_x,step_y,LIGHTBLUE);break;}if(i18)break;else{for(i=step_x+1,j=step_y;i18)break;step_x=i;judgewho(step_x,step_y);break;}caseDOWN: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;}caseUP:if((step_y-1)=1;j--)if(box[i][j]==0){draw_circle(step_x,step_y,LIGHTBLUE);break;}if(j=1&&step_x=1&&step_y=1;j--){if(box[j][k]==flag)n1++;elsebreak;}/*水平向右数*/for(j=x,k=y;j=5){return(1);break;}/*垂直向上数*/n1=0;n2=0;for(j=x,k=y;k>=1;k--){if(box[j][k]==flag)n1++;elsebreak;}/*垂直向下数*/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(box[j][k]==flag)n1++;elsebreak;}/*向右下方数*/for(j=x,k=y;j=5){return(1);break;}/*向右上方数*/n1=0;n2=0;for(j=x,k=y;j=1;j++,k--){if(box[j][k]==flag)n1++;elsebreak;}/*向左下方数*/for(j=x,k=y;j>=1,k=5){return(1);break;}return(0);break;}}voidmain(){intgdriver=VGA,gmode=VGAHI;clrscr();attention();initgraph(&gdriver,&gmode,"c:\\tc");/*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&&key!=ESC);}while(key!=ESC);closegraph();}热心网友 时间:2023-06-24 16:09
#include <stdio.h>