diff --git a/升级版(着色构成连珠的5个子).cpp b/升级版(着色构成连珠的5个子).cpp new file mode 100644 index 0000000..eda363a --- /dev/null +++ b/升级版(着色构成连珠的5个子).cpp @@ -0,0 +1,554 @@ +//СϷ + +#include +#include +#include +#include //ʹgetch() + +int startchoice,winner,player,Q[200][200]= {0}; //Q¼ +char button; //ָ + +struct Point { //Ľṹ + int x,y; +} point,game_xy; + +struct Piece { //ӵ¼ + struct Point coord; + struct Piece *fore; +}; + +struct Piece *head,*p,*ptr,*ptr1; +struct Point win_point[5]; + +void goto_xy(int x, int y) { //ƶ + COORD c; + c.X=2*x; + c.Y=y; + SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c); +} + +void Init() { //ʼ¼ӵʼ + for(int i=0; i<200; i++) + for(int j=0; j<200; j++) + Q[i][j]=0; + + startchoice=0; + player=1; + p=(struct Piece *)malloc(sizeof(struct Piece)); + head=p; +} + +void Welcome() { //ӭ + system("color B0"); //#include B dzɫ 0 ɫ + goto_xy(10,3); + printf("-"); + goto_xy(17,1); + printf("˵"); + goto_xy(13,3); + printf(" ***˶ս***"); + goto_xy(13,4); + printf(" ***˳***"); + point.x=12; + point.y=3; + goto_xy(0,0); +} + +void ShowWho() { //ʾֵһ + goto_xy(17,24); + if(player==0) + printf("ֵ׷"); + else + printf("ֵҷ"); + goto_xy(point.x,point.y); +} + +void Draw() { //滭Ϸ + game_xy.x=10; + game_xy.y=3; + system("cls"); + system("color 3F"); //3 ɫ F ɫ + goto_xy(15,1); + printf("ӭplay our 壡"); + /*goto_xy(29,22); + printf("¿ʼ r");*/ + goto_xy(1,24); + printf(" b"); + goto_xy(1,25); + printf("˳ ESC"); + + const int i=8; //const ݲԱı ޸ݱȽϷ + const int j=19; + const int k=3; + goto_xy(game_xy.x-i,game_xy.y+k); //׷巽 + printf("׷ "); + goto_xy(game_xy.x-i,game_xy.y+k+2); + printf("ƶ W"); + goto_xy(game_xy.x-i,game_xy.y+k+4); + printf(" S"); + goto_xy(game_xy.x-i,game_xy.y+k+6); + printf(" A"); + goto_xy(game_xy.x-i,game_xy.y+k+8); + printf(" D "); + goto_xy(game_xy.x-i,game_xy.y+k+10); + printf(": "); + + goto_xy(game_xy.x+j,game_xy.y+k); //ҷ巽 + printf("ҷ "); + goto_xy(game_xy.x+j,game_xy.y+k+2); + printf("ƶ "); + goto_xy(game_xy.x+j,game_xy.y+k+4); + printf(" "); + goto_xy(game_xy.x+j,game_xy.y+k+6); + printf(" "); + goto_xy(game_xy.x+j,game_xy.y+k+8); + printf(" "); + goto_xy(game_xy.x+j,game_xy.y+k+10); + printf(": Enter"); + + for(int k1=0; k1<200; k1++) //ʼӼ¼ڵڶʱȷ + for(int k2=0; k2<200; k2++) + Q[k1][k2]=0; + + for(int i=0; i<20; i++) { // + + if(i==0) { //һ + goto_xy(10,i+3); + printf("ЩЩЩЩЩЩЩЩЩЩЩЩЩЩЩЩЩЩ"); + + } + if(i!=0&&i!=19) { //м16 + goto_xy(10,i+3); + printf(""); + } + if(i==19) { //һ + goto_xy(10,i+3); + printf("ةةةةةةةةةةةةةةةةةة"); + } + } + point.x=19; + point.y=12; + goto_xy(19,12); +} + +void Clean() { //-˶Ĺ켣 + goto_xy(10,3); + printf(" "); + goto_xy(24,3); + printf(" "); + goto_xy(10,4); + printf(" "); + goto_xy(24,4); + printf(" "); +} + +void menu_choose(char press) { //ѡϷ˳ + if(press==72) { //ASCLL + if(point.y==3) + point.y=4; + else + point.y=3; + Clean(); + goto_xy(10,point.y); + printf("-"); + } + if(press==80) { //ASCLL + if(point.y==4) + point.y=3; + else + point.y=4; + Clean(); + goto_xy(10,point.y); + printf("-"); + } + if(press==13) { // 13سASCLL + startchoice=point.y-2; //startchoice Ϊ12 + } +} + +void go_back(int x1,int y1) { //庯 + goto_xy(x1,y1); + if(x1==10) { + if(y1==3) { + printf(""); + } else if(y1==20) { + printf(""); + } else { + printf(""); + } + } else if(x1==27) { + if(y1==3) { + printf(""); + } else if(y1==20) { + printf(""); + } else { + printf(""); + } + } else { + if(y1==3) { + printf(""); + } else if(y1==20) { + printf(""); + } else { + printf(""); + } + } + Q[point.x][point.y]=0; //нӶӦΪ0 + goto_xy(x1,y1); +} + +void Record() { //¼ӵ + + p->coord.x=point.x; + p->coord.y=point.y; + ptr=p; + p=(struct Piece *)malloc(sizeof(struct Piece)); + p->fore=ptr; + + ShowWho(); + Q[point.x][point.y]=player+1; + if(player) { + player=0; + return; + } + player=1; + goto_xy(point.x,point.y); +} + +void PutDown() { //ʾӺ + if(Q[point.x][point.y]==0) { //жϸλǷ + if(player) { + printf(""); + printf("\a"); //'\a'ʾ + Record(); + } else { + printf(""); + printf("\a"); + Record(); + } + goto_xy(point.x,point.y); + } +} + +void Play(char ch) { //̵IJ ƶ ͻ + if(player==1) { //׷ + if(ch== 'W' || ch=='w') //W + { if(point.y<=3) + point.y=22; + else + point.y--; + goto_xy(point.x,point.y); + + } + if(ch=='A' || ch=='a') { //A + if(point.x<=10) + point.x=20; + else + point.x--; + goto_xy(point.x,point.y); + + } + if(ch=='D' || ch=='d') { //D + if(point.x>=20) + point.x=10; + else + point.x++; + goto_xy(point.x,point.y); + + } + if(ch=='S' || ch=='s') { //S + if(point.y>=22) + point.y=3; + else + point.y++; + goto_xy(point.x,point.y); + + } + if(ch==32) { //ոASCLL + PutDown(); + } + } else { + if(ch==72) { //ASCLL + if(point.y<=3) + point.y=22; + else + point.y--; + goto_xy(point.x,point.y); + + } + if(ch==75) { //ASCLL + if(point.x<=10) + point.x=20; + else + point.x--; + goto_xy(point.x,point.y); + + } + if(ch==77) { //ASCLL + if(point.x>=20) + point.x=10; + else + point.x++; + goto_xy(point.x,point.y); + + } + if(ch==80) { //ASCLL + if(point.y>=22) + point.y=3; + else + point.y++; + goto_xy(point.x,point.y); + + } + if(ch==13) { //سASCLL + PutDown(); + } + } + + + if(button=='b'||button=='B') { //IJ + ptr1=p; + if(p!=head) { + p=p->fore; + free(ptr1); + point.x=p->coord.x; + point.y=p->coord.y; + go_back(point.x,point.y); + } + } +} + +void judgeWinRecodePointXY(int count, int rr, int cc){ + win_point[count].x=rr; //¼ + win_point[count].y=cc; //¼ +} + +void judgeWinSetPointCOlor() { + HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);//ʵ + CONSOLE_SCREEN_BUFFER_INFO csbiInfo; //ȡǰɫ + GetConsoleScreenBufferInfo(handle, &csbiInfo); //ȡǰɫ + WORD wOldColorAttrs = csbiInfo.wAttributes; //ȡǰɫ + + SetConsoleTextAttribute(handle,FOREGROUND_INTENSITY |FOREGROUND_RED|BACKGROUND_INTENSITY|BACKGROUND_GREEN); //ɫ + for(int i=0; i<5; i++) { + //һ + goto_xy(win_point[i].x, win_point[i].y); + if(!player) { //˭Ӯ˭һӣôplayerͷ + printf(""); + } else { + printf(""); + } + } + SetConsoleTextAttribute(handle, wOldColorAttrs); //ָԭɫ +} + +int Judge() { + int count=0; + int pp=player==0?2:1; //Ŀ + for(int c=0; c<200; c++) { + for(int r=0; r<200; r++) { + if(Q[r][c]!=pp) + continue; + + // + int rr=r; + int cc=c; + judgeWinRecodePointXY(count, rr, cc); //¼ + while(--cc>=3 &&Q[rr][cc]==pp) { + count++; + judgeWinRecodePointXY(count, rr, cc); //¼ + } + cc=c; + judgeWinRecodePointXY(count, rr, cc); //¼ + while(++cc<23 &&Q[rr][cc]==pp) { + count++; + judgeWinRecodePointXY(count, rr, cc); //¼ + } + cc=c; + if(count>=4) { + judgeWinSetPointCOlor(); + return pp; + } + + // + count=0; + judgeWinRecodePointXY(count, rr, cc); //¼ + while(--rr>=10 &&Q[rr][cc]==pp) { + count++; + judgeWinRecodePointXY(count, rr, cc); //¼ + } + rr=r; + judgeWinRecodePointXY(count, rr, cc); //¼ + while(++rr<30 &&Q[rr][cc]==pp) { + count++; + judgeWinRecodePointXY(count, rr, cc); //¼ + } + rr=r; + if(count>=4) { + judgeWinSetPointCOlor(); + return pp; + } + + //鷴б + count=0; + judgeWinRecodePointXY(count, rr, cc); //¼ + cc--; + rr--; + while((cc>=3||rr>=10) &&Q[rr][cc]==pp) { + count++; + judgeWinRecodePointXY(count, rr, cc); //¼ + cc--; + rr--; + + } + rr=r; + cc=c; + judgeWinRecodePointXY(count, rr, cc); //¼ + cc++; + rr++; + while((cc<23||rr<30) &&Q[rr][cc]==pp) { + count++; + judgeWinRecodePointXY(count, rr, cc); //¼ + cc++; + rr++; + } + rr=r; + cc=c; + if(count>=4) { + judgeWinSetPointCOlor(); + return pp; + } + + //б + count=0; + judgeWinRecodePointXY(count, rr, cc); //¼ + cc++; + rr--; + while((cc<23||rr>=10) &&Q[rr][cc]==pp) { + judgeWinRecodePointXY(count, rr, cc); //¼ + count++; + cc++; + rr--; + } + rr=r; + cc=c; + judgeWinRecodePointXY(count, rr, cc); //¼ + cc--; + rr++; + while((cc>=3||rr<30) &&Q[rr][cc]==pp) { + judgeWinRecodePointXY(count, rr, cc); //¼ + count++; + cc--; + rr++; + } + rr=r; + cc=c; + if(count>=4) { + judgeWinSetPointCOlor(); + return pp; + } + + count=0; + } + } + return 0; +} + +int main(void) { + int j=0,k=0; + system("color 4E"); //#include 4 ɫ E 嵭ɫ + printf("\n ӭplay壡"); + goto_xy(15,3); + printf("ߣ"); + goto_xy(17,5); + printf(" "); + Sleep(3000); + system("cls"); + while(1) { + Init(); //ʼ + int winner=0; + Welcome(); //ӭ + + while(1) { //ȡ˵ѡ + char choice=getch(); + menu_choose(choice); + if(startchoice!=0) + break; + } + + if(startchoice==1) { //ѡ˶ս + + Draw(); + goto_xy(17,24); + printf("ֵ׷"); + goto_xy(point.x,point.y); + + while(1) { + button=getch(); + Play(button); //ȡ̵IJ ƶ ͻ + + if(button==27) { //ESCASCLL + if(MessageBox(NULL,TEXT("ȷ˳"),TEXT(""),MB_ICONQUESTION|MB_OKCANCEL)==IDOK) { + system("cls"); + printf("\n ллʹã\n"); + return 0; + } + } + + if(button==13 || button==32) //س߿ոASCLL ºʼжӮ + winner=Judge(); + + if(winner!=0) { + goto_xy(15,26); + if(winner==2) { + printf("ϲ׷Ӯ\n"); + j=j+1; + } + if(winner==1) { + printf("ϲҷӮ\n"); + k=k+1; + } + goto_xy(29,24); + printf(" %d : %d ",j,k); + } + + if(winner!=1&&winner!=2) { + continue; + } + + goto_xy(13,24); + printf(" Ϸ?(Y/N): "); + while(1) { + button=getch(); + if(button=='n'||button=='N'||button=='y'||button=='Y') + break; + } + + if(button=='n'||button=='N') { + if(MessageBox(NULL,TEXT(" ȷ˳"),TEXT(""),MB_ICONQUESTION|MB_OKCANCEL)==IDOK) { + system("cls"); + printf("\n ллʹã\n"); + return 0; + } + } + + if(button=='y'||button=='Y') { + winner=0; + system("cls"); + break; + } + + } + } + + if(startchoice==2) { + if(MessageBox(NULL,TEXT(" ȷ˳"),TEXT(""),MB_ICONQUESTION|MB_OKCANCEL)==IDOK) { + printf("\n\n ллʹã\n"); + return 0; + } + } + } + return 0; +} + + + diff --git a/升级版(着色构成连珠的5个子).exe b/升级版(着色构成连珠的5个子).exe new file mode 100644 index 0000000..6b0554f Binary files /dev/null and b/升级版(着色构成连珠的5个子).exe differ