/* http://www.mrwadlo.com */ #include #include #include void calc_time(); void count_100ths(int hund); void display(int xi,int yi,int xf,int yf); void update(); int random(int max); char dropcheck(); int free( int x, int y ); int timeeo(); char builder(char com); void offswitch(int i); void SaveScreen(); void LoadScreen(); int quicktime(); int screen[80][25]; long one_sec; int ballx[9], bally[9]; int startx, starty; int posx, posy; int main() { int i; char com = '?'; FILE *fpTESTr; startx = 40; starty = 12; posx = startx; posy = starty+1; for ( i=0 ; i<9 ; i++ ) { ballx[i] = startx; bally[i] = starty; } clrscr(); calc_time(); fpTESTr = fopen("MOUS3.sav","rb"); if ( fpTESTr != 0 ) { gotoxy(16,13); printf("Would you like to load saved build MOUS3.SAV? Y/N"); do { com = getch(); } while ( com != 'y' && com != 'Y' && com != 'n' && com != 'N'); if ( com == 'y' || com == 'Y' ) { LoadScreen(); } clrscr(); display(0,0,80,24); } fclose(fpTESTr); gotoxy(2,25); printf("~:%c 1:%c 2:%c 3:^ 4:%c 5:%c 6:%c 7:%c 8:# 9:%c 0:DEL SPACE:DROP ENTER:SWITCH ESC:EXIT",127,175,174,29,14,11,202,17); while ( com != 27 ) { com = dropcheck(); /*check for keypress and execute */ if ( countfree() != 9 || com == 13 ) /*if there will be movement... */ { update(); /*...update first... */ display(0,0,80,24); /*...and then display change */ } else if ( com == 72 || com == 75 || com == 77 || com == 80 ) { display(posx-1,posy-1,posx+2,posy+2); } else display(posx-1,posy-1,posx+2,posy+2); gotoxy(posx+1,posy+1); if ( quicktime() % 2 == 1 || com == 72 || com == 75 || com == 77 || com == 80 ) printf("%c",219); count_100ths(20); } clrscr(); gotoxy(15,13); printf("Would you like to save this build as MOUS3.SAV? Y/N"); do { com = getch(); } while ( com != 'y' && com != 'Y' && com != 'n' && com != 'N'); if ( com == 'y' || com == 'Y' ) { SaveScreen(); } return 0; } void calc_time() { time_t time1; time1 = time(NULL); gotoxy(30,13); printf("Calculating CPU Speed..."); while( time(NULL) == time1 ) ; time1 = time(NULL); while( time(NULL) < (time1 + 2) ) { one_sec++; printf(" \b"); } clrscr(); one_sec /= 2; } int quicktime() { time_t time1; time1 = time(NULL); time1 = time1 % 10000; return time1; } void count_100ths(int hund) { long i = 0; time_t time1; gotoxy (1,25); while ( i < ( one_sec / 100 * hund ) ) { printf(" \b"); time1 = time(NULL); i++; } } int random(int max) { int rnd; time_t time1; time1 = time(NULL); rnd = ( rand() + time1 ) % max; return rnd; } void display(int xi,int yi,int xf,int yf) { int i,j,k; if ( yi < 0 ) yi = 0; else if ( yf > 24 ) yf = 24; if ( xi < 0 ) xi = 0; else if ( xf > 80 ) xf = 80; for ( j=yi ; j 29 && screen[i][j] < 41 ) { if ( screen[i][j] < 40 ) printf("%d", screen[i][j] - 30 ); else printf("X"); } else { switch( screen[i][j] ) { case 0: printf(" "); break; case 1: printf("%c",175); break; case 2: printf("%c",174); break; case 3: printf("^"); break; case 4: printf("%c",29); break; case 5: printf("%c",14); break; case 6: printf("%c",11); break; case 7: printf("%c",202); break; case 9: printf("%c",17); break; case 19: printf("%c",16); break; case 16: printf("%c",186); break; case 17: printf("%c",186); break; } } } } } void update() { int i; for ( i=0 ; i<9 ; i++ ) { if ( ballx[i] != startx || bally[i] != starty ) { if ( screen[ballx[i]+1][bally[i]+1] == 7 && screen[ballx[i]][bally[i]+1] == 1 ) { if ( timeeo() == 0 && screen[ballx[i]+1][bally[i]] == 17) { if ( screen[ballx[i]][bally[i]+1] == 1 && free(ballx[i]+1,bally[i]) ) { screen[ballx[i]+1][bally[i]] = 16; ballx[i]++; } } else if ( timeeo() != 0 && screen[ballx[i]+1][bally[i]] == 16 ) { screen[ballx[i]+1][bally[i]] = 17; } } else if ( screen[ballx[i]-1][bally[i]+1] == 7 && screen[ballx[i]][bally[i]+1] == 2 ) { if ( timeeo() == 0 && screen[ballx[i]-1][bally[i]] == 17) { if ( screen[ballx[i]][bally[i]+1] == 2 && free(ballx[i]-1,bally[i]) ) { screen[ballx[i]-1][bally[i]] = 16; ballx[i]--; } } else if ( timeeo() != 0 && screen[ballx[i]-1][bally[i]] == 16 ) { screen[ballx[i]-1][bally[i]] = 17; } } else { switch( screen[ballx[i]][bally[i]+1] ) { case 0: if ( free(ballx[i],bally[i]+1) ) bally[i]++; break; case 1: if ( free(ballx[i]+1,bally[i]) ) ballx[i]++; break; case 2: if ( free(ballx[i]-1,bally[i]) ) ballx[i]--; break; case 3: if ( free(ballx[i],bally[i]-1) ) bally[i]--; break; case 4: if ( free(ballx[i]-1,bally[i]) && free(ballx[i]+1,bally[i]) ) { if ( random(2) == 1 ) ballx[i]++; else ballx[i]--; } else if ( free(ballx[i]-1,bally[i]) && random(2) == 1) ballx[i]--; else if ( free(ballx[i]+1,bally[i]) && random(2) == 1) ballx[i]++; break; case 5: if ( free(ballx[i],bally[i]+1) ) bally[i]++; break; case 7: offswitch(i); break; case 9: ballx[i]--; break; case 19: ballx[i]++; break; default: if ( free(ballx[i],bally[i]+1) ) bally[i]++; break; } if ( screen[ballx[i]][bally[i]] == 6 ) { ballx[i] = startx; bally[i] = starty; } else if ( screen[ballx[i]][bally[i]] == 5 ) printf("\a"); else if ( screen[ballx[i]][bally[i]] > 29 && screen[ballx[i]][bally[i]] < 40 ) { if ( screen[ballx[i]][bally[i]] < 40 ) screen[ballx[i]][bally[i]]++; } } if ( bally[i] > 24 ) { screen[ballx[i]][bally[i]-2] = 6; ballx[i] = startx; bally[i] = starty; } if (ballx[i] < 0 ) { screen[ballx[i]+1][bally[i]] = 6; ballx[i] = startx; bally[i] = starty; } if (ballx[i] > 79 ) { screen[ballx[i]-1][bally[i]] = 6; ballx[i] = startx; bally[i] = starty; } if (bally[i] < 0 ) { screen[ballx[i]][bally[i]+1] = 6; ballx[i] = startx; bally[i] = starty; } if ( ballx[i] == startx && bally[i]+1 == starty ) { gotoxy(ballx[i]+1,bally[i]+1); printf("%c",11); ballx[i] = startx; bally[i] = starty; } } } } char dropcheck() { int i,j; char com; if ( kbhit() ) { com = getch(); /*ignorible*/ if ( com == ' ' && startx >=0 && startx <= 79 && starty >= 0 && starty <= 24) { for ( i=0 ; i<9 ; i++ ) { if ( ballx[i] == startx && bally[i] == starty ) { ballx[i] = startx; bally[i] = starty+1; i=11; } } } else if ( com == 13 ) { for ( i=0 ; i<24 ; i++ ) for ( j=0 ; j<80 ; j++ ) { if ( screen[j][i] == 9 ) screen[j][i] = 19; else if ( screen[j][i] == 19 ) screen[j][i] = 9; } } else com = builder(com); } while ( kbhit() ) { getch(); /* prevent buffered movement */ } return com; } int countfree() { int counter=0; int i; for ( i=0 ; i<9 ; i++ ) if ( ballx[i] == startx && bally[i] == starty ) counter++; return counter; } int free( int x, int y ) { int i; for ( i=0 ; i<9 ; i++ ) if ( ballx[i] == x && bally[i] == y ) return 0; return 1; } int timeeo() { int eo; time_t time1; time1 = time(NULL); eo = time1 % 2; return eo; } char builder(char com) { int i; gotoxy(1,1); while ( com == 0 ) { com = getch(); if ( com == 75 && posx > 0 ) posx--; else if ( com == 77 && posx < 79 ) posx++; else if ( com == 72 && posy > 0 ) posy--; else if ( com == 80 && posy < 23 ) posy++; if ( kbhit() ) { com = getch(); display(posx-5,posy-5,posx+6,posy+6); } } if ( com == 48 || com == 83 || com == 8 ) { if ( startx == posx && ( starty == posy || starty-1 == posy ) ) { printf("\a"); } else if ( screen[posx][posy] == 7 ) { screen[posx][posy] = 0; screen[posx][posy-1] = 0; } else if ( screen[posx][posy] == 17 ) { screen[posx][posy] = 0; screen[posx][posy+1] = 0; } else screen[posx][posy] = 0; } else if ( com > 48 && com < 58 ) { if ( screen[posx][posy] == 7 ) screen[posx][posy-1] = 0; if ( screen[posx][posy] == 17 ) printf("\a"); else if ( startx == posx && ( starty == posy || starty-1 == posy ) ) printf("\a"); else if ( com == '8' ) screen[posx][posy] = 30; else if ( com == '9' && screen[posx][posy] == 9 ) screen[posx][posy] = 19; else if ( com == '7' ) { screen[posx][posy] = 7; screen[posx][posy-1] = 17; } else screen[posx][posy] = com - '0'; /*all others*/ } else if ( com == '`' && posy > 0 && posy < 22 ) { startx = posx; starty = posy; for( i=0 ; i<9 ; i++ ) { ballx[i] = startx; bally[i] = starty; } screen[posx][posy] = 0; screen[posx][posy-1] = 0; display(0,0,80,24); /*reposition dropper on screen*/ } return com; } void offswitch(int i) { if ( screen[ballx[i]+1][bally[i]+1] == 2 && screen[ballx[i]-1][bally[i]+1] == 1 ) { /* Movement Jam : Do Nothing */ } if ( screen[ballx[i]+1][bally[i]+1] == 4 || screen[ballx[i]-1][bally[i]+1] == 4 ) { if ( random(2) == 1 ) { if ( free(ballx[i]+1,bally[i]) ) ballx[i]++; } else if ( free(ballx[i]-1,bally[i]) ) ballx[i]--; } else if ( screen[ballx[i]+1][bally[i]+1] == 1 || screen[ballx[i]-1][bally[i]+1] == 1 ) { if ( free(ballx[i]+1,bally[i]) ) ballx[i]++; } else if ( screen[ballx[i]+1][bally[i]+1] == 2 || screen[ballx[i]-1][bally[i]+1] == 2) { if ( free(ballx[i]-1,bally[i]) ) ballx[i]--; } else { if ( random(2) == 1 ) { if ( free(ballx[i]+1,bally[i]) ) ballx[i]++; } else if ( free(ballx[i]-1,bally[i]) ) ballx[i]--; } } void SaveScreen() { int i,j; FILE *fpSAVEw; fpSAVEw = fopen("MOUS3.sav","wb"); for ( j=0 ; j<24 ; j++ ) { for ( i=0 ; i<80 ; i++ ) { fprintf(fpSAVEw,"%c",screen[i][j]); } } fprintf(fpSAVEw,"%d %d",startx,starty); fclose(fpSAVEw); } void LoadScreen() { int i,j; FILE *fpLOADr; fpLOADr = fopen("MOUS3.sav","rb"); for ( j=0 ; j<24 ; j++ ) { for ( i=0 ; i<80 ; i++ ) { fscanf(fpLOADr,"%c",&screen[i][j]); } } fscanf(fpLOADr,"%d %d",&startx,&starty); for ( i=0 ; i<9 ; i++ ) { ballx[i] = startx; bally[i] = starty; } fclose(fpLOADr); }