/* http://www.mrwadlo.com */ #include #include #include #include void calc_time(); void count_tenths(int tenth); void scroll(); void newline(); void move(); void showpos(); char check(); void updatescore(); void levelup(); int speed = 0; /* 0=slowest 9=fastest */ int density = 0; /* 0=clearest 9=max */ int distance = 0; long one_sec = 0; char scroller[78][24]; int location[2] = { 40, 24 }; int main() { int tenth; char status = 'g'; char ext = '?'; clrscr(); gotoxy(20,13); printf("Loading Claustrophobia..."); calc_time(); while ( status == 'g' ) { count_tenths(10-speed); distance++; scroll(); move(); showpos(); status = check(); updatescore(); levelup(); } gotoxy(5,25); printf("Press ESC to Exit"); while (ext != 27) { ext = getch(); } return 0; } void calc_time() { time_t time1; time1 = time(NULL); while( time(NULL) == time1 ) ; time1 = time(NULL); while( time(NULL) < (time1 + 2) ) { one_sec++; printf(" \b"); } one_sec /= 2; } void count_tenths(int tenth) { long i = 0; time_t time1; gotoxy (1,25); while ( i < ( one_sec / 10 * tenth ) ) { printf(" \b"); time1 = time(NULL); i++; } } void scroll() { int i, j; for( j=23; j>0 ; j-- ) for( i=0 ; i<78 ; i++ ) scroller[i][j] = scroller[i][j-1]; for ( i=0 ; i<78 ; i++ ) { scroller[i][0] = rand() % (10-density); if ( scroller[i][0] == 1 ) scroller[i][0] = 219; else scroller[i][0] = ' '; } gotoxy(2,1); for ( j=0 ; j<24 ; j++ ) { for ( i=0 ; i<78 ; i++ ) printf("%c", scroller[i][j]); printf("\n "); } showpos(); } void move() { char sym; if ( kbhit() ) { sym = getch(); if ( sym == 0 ) { sym = getch(); if (sym == 75 ) /* left */ location[0]--; if (sym == 77 ) /* right */ location[0]++; if (sym == 72) /* up */ location[1]--; if (sym == 80) /* down */ location[1]++; } } } void showpos() { gotoxy( location[0] +1 ,location[1] ); printf("%c",232); } char check() { if ( scroller[ location[0] -1 ][ location[1] -1 ] == -37 ) { printf("BOOM!"); return 'c'; } else { gotoxy(33,25); printf("-%d-", scroller[ location[0] -1 ][ location[1] -1 ]); return 'g'; } } void updatescore() { gotoxy(20,25); printf("Score: %d ", distance - location[1] ); gotoxy(40,25); printf("Speed: %d ", speed); gotoxy(60,25); printf("Density: %d ", density); } void levelup() { if ( (distance % 10 == 0) && (distance - location[1] > 0) ) { gotoxy(5,25); printf("levelup!"); gotoxy(15,25); if ( density < 8 ) { density++; } else { speed++; density=0; } } }