#include <dos.h> #include <bios.h> #include <stdlib.h> #include <conio.h> char getkey(void); void window_3d(int,int,int,int,int,int); int shuffle(int a[4][4]); void soundl(void); main() {int i,j,x,y,a[4][4]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0}; char ch; textmode(3); textbackground(CYAN); textcolor(RED); clrscr(); gotoxy(25,19); ptintf("F1:shuffle ESC:exit"); window_3d(22,6,54,16,BLUE,GREEN); do {gotoxy(3,3); for(i=0;i<=3;i++) {for(j=0;j<=3;j++) if(a[i][j]==0) {x=i;y=j;printf("");} else printf("%6d",a[i][j]); gotoxy(3,5+i*2); } ch=getkey(); switch(ch) {case 72:if(x!=3) {a[x][y]=a[x+1][y]; a[x+1][y]=0; } else soundl();break; case 80: if(x!=0) {a[x][y]=a[x-1][y]; a[x-1][y]=0; } else soundl();break; case 77:if(y!=0) {a[x][y]=a[x][y-1]; a[x][y-1]=0; } else soundl();break; case 75: if(y!=3) {a[x][y]=a[x][y+1]; a[x][y+1]=0; } else soundl(); case 59: shuffle(a);break; } }while(ch!=1); window_3d(int x1,int y1,int x2,int y2,int bk_color,int fo_color) {textbackground(BLACK); window(x1,y1,x2,y2); clscr(); textbackground(bk_color); textcolor(fo_color); window(x1-2,y1-1,x2-2,y2-1); clscr(); } void soundl(void) {sound(1064); delay(100); nosound(); } char getkey() {union{int i,char ch[2]}k; k.i=bioskey(0); return k.ch[1]; } int shuffle(a[4][4]) {int num,i,j,t; for(t=0;t<=100;t++) {for(i=0;i<=3;i++) for(j=0;j<=3;j++) if(a[i][j]==0) {switch(i) {case 0: a[i][j]=a[i+1][j];a[i+1][j]=0; break; case 1: case 2: num=rand()%2; if(num=0) {a[i][j]=a[i+1][j]; a[i+1][j]=0; } else {a[i][j]=a[i-][j]; a[i-1][j]=0; } case 3: a[i][j]=a[i-1][j];a[i-1][j]=0; break; } } for(i=0;i<=3;i++) for(j=0;j<=3;j++) if(a[i][j]==0) {switch(j) {case 0: a[i][j]=a[i][j+1];a[i][j+1]=0; break; case 1: case 2: num=rand()%2; if(num=0) {a[i][j]=a[i][j+1]; a[i][j+1]=0; } else {a[i][j]=a[i][j-1]; a[i][j-1]=0; } break; case 3: a[i][j]=a[i][j-1];a[i][j-1]=0; break; } } } }
--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups " 程序员_在路上" group. To post to this group, send email to go2program@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/go2program -~----------~----~----~----~------~----~------~--~---