#include<dos.h> #include <bios.h>
#define UP 5 #define LEFT 1 #define DOWN 2 #define RIGHT 3
#define BUP 18432 #define BDOWN 20480 #define BLEFT 19200 #define BRIGHT 19712 #define BESC 283
void point(int x, int y, char far *p, int i); /*paint point*/ int scan (int x,int y, char far *p ); /*search the tail*/ void clear (char far *p); /*clean the marks*/ void graph(int i,char far *p); /*input score or fail alarm*/ void sand(char far *p); /*paint random point */ void box(char far *p); /*edge*/ int x0=100,y0=70; int success=0; int pt = 0; int tail = 0; int i=0;
main() { int length = 20; int control = 1; int x=100,y=70; int i; char far *p; union REGS r; r.h.al=0x13; r.h.ah=0; int86(0x10,&r,&r) ; p=(char far *)(0xa0000000l);
printf ("Score:%3d",success); sand(p); box(p); while (1) { control = bioskey(0);
switch (control) { case BUP: while(!bioskey(1)) { if (tail>0) /*length more*/ tail--; if (length>0) length--; if (length == 0 && tail==0) {clear (p);}
y--; if (y == 9) y = 150; point(x, y, p,123); }break; case BDOWN: while(!bioskey(1)) { if (tail>0) /*length more*/ tail--; if (length>0) length--; if (length == 0 && tail==0) clear (p); y++; if (y==151) y = 10; point(x, y, p,123); }break; case BLEFT: while(!bioskey(1)) { if (tail>0) /*length more*/ tail--; if (length>0) length--; if (length == 0 && tail==0) clear (p); x--; if (x == 79) x = 220; point(x, y, p,123); }break; case BRIGHT: while(!bioskey(1)) { if (tail>0) /*length more*/ tail--; if (length>0) length--; if (length == 0 && tail==0) clear (p); x++; if (x == 221) x = 80; point(x, y, p,123); }break; default: exit(0); } } }
void point (int x, int y, char far *p, int i) { if (i == 123) /*paint*/ { if((*(p+320*y+x)==123)) { graph(0,p); } else if (*(p+320*y+x)==78) { graph(1,p); tail =5; sand(p); } } *(p+320*y+x) = i; if (i == 123) delay (4000); }
int scan (int x, int y, char far * p) { if (*(p+320*y+x+1)==123) return RIGHT; else if (*(p+320*y+x-1)==123) return LEFT; else if (*(p+320*y+x+320)==123) return DOWN; else if (*(p+320*y+x-320)==123) return UP; }
void clear (char far * p) { int state; state = scan (x0,y0,p); if (state == RIGHT) { x0++; point (x0,y0,p,0); if (x0==220) { x0=80; } point (x0,y0,p,0); } if (state == LEFT) { x0--; point (x0,y0,p,0); if (x0==80) { x0=220; } point (x0,y0,p,0);
} if (state == DOWN) { y0++; point (x0,y0,p,0); if (y0==150) { y0 = 10; } point (x0,y0,p,0); } if (state == UP) { y0--; point (x0,y0,p,0); if (y0==10) { y0=150; } point (x0,y0,p,0); } }
void graph (int i,char far *p) { if (i == 0) { printf ("\n\n\n\n\n\t FAILED!!!"); box(p); sleep(1); getch(); exit(0); } else { success++; printf ("\b\b\b%3d",success); } }
void sand (char far *p) { pt ++; if (pt == 7) { pt = 1; i++; } switch (pt) { case 1: *(p+320*14+12+320*(10+i)+80+i) = 78;break; case 2: *(p+320*48+50+320*(10+i)+80+i) = 78;break; case 3: *(p+320*67+110+320*(10+i)+80+i) = 78;break; case 4: *(p+320*53+100+320*(10+i)+80+i) = 78;break; case 5: *(p+320*90+25+320*(10+i)+80+i) = 78;break; case 6: *(p+320*80+120+320*(10+i)+80+i) = 78; } }
void box(char far *p) { int i; for (i=79; i<=221; i++) { *(p+320*9+i) = 345; /*top*/ *(p+320*151+i) = 345; /*botton*/ } for (i=9; i<=151; i++) { *(p+320*i+79)=345; /*left*/ *(p+320*i+221)=345; /*right*/ } }
|