/* http://www.mrwadlo.com */ #include #include #include #include #define PI 3.14159265358979 #define MAXVEL 1000 float degrees; float radians; float velocity; int range=30; int objdist; int trajchange; char win = 'm'; int turn; int wins=0; int losses=0; int level = 1; char game = 's'; int compturn = 0; int compmin = -10; int compmax = 70; float bestlab[2][2] = { 0, 0, 0, 0 }; int bestpos[2] = { -999, 999 }; void showground(); void showobjs(); void entertraj(); void fire(int x, int sym); void impact(); void calculate(); void minipause(long mini); void clearinput(); void createdist(); void drawlabels(); void upat(int x, int sym); void downat(); void hidecur(); void kaboom(); void showscore(); void getgametype(); void degreeinput(); void velocityinput(); void comptraj(); void about(); void showmsg(char string[]); int main() { char ext = 'y'; int i; clrscr(); showmsg("PRESS ANY KEY TO PLAY!"); do { kaboom(); } while ( !kbhit() ); getch(); showmsg(" "); getgametype(); clearinput(); createdist(); showground(); drawlabels(); while ( ext != 'n' && ext != 'N' ) { turn++; showscore(); i=0; while (game == 'g' && i -8 ) { downat(); if (compturn == 1) { gotoxy(range+10,25); printf("%c",220); } else { gotoxy(range+10,25); printf(" "); } gotoxy(range+9,24); printf("%c %c", 177, 177); minipause(5000); gotoxy(range+9,24); printf(" "); } else if (range == objdist) { downat(); gotoxy(range+10,25); printf(" "); gotoxy(range+9,24); printf("%c %c", 177, 177); gotoxy(range+9,24); printf(" "); if ( range == 1 ) { gotoxy(10,24); printf("%c", 186); } win = 'y'; if (game == 'g') { wins++; level++; } if (compturn == 1) { gotoxy(range+10,25); printf("%c",220); } clearinput(); kaboom(); } if ( range < objdist && range >= bestpos[0] && compturn == 0 ) { bestlab[0][0] = degrees; bestlab[0][1] = velocity; bestpos[0] = range; } else if ( range > objdist && range <= bestpos[1] && compturn == 0 ) { bestlab[1][0] = degrees; bestlab[1][1] = velocity; bestpos[1] = range; } else if ( compturn == 1 && range < 0 ) { compmin = range+1; } else if ( compturn == 1 && range > 0 ) { compmax = range; } } void calculate() { float rng = sin(radians) * cos(radians) * velocity * velocity / 4.9; range = (int)rng; range = range + trajchange; } void minipause(long mini) { long i, j; hidecur(); for ( i=-1 * mini ; i -8 ) { gotoxy(bestpos[0]+10,23); printf("%c", 25); gotoxy(bestpos[0]+8,21); printf("%.2f%c", bestlab[0][0], 248 ); gotoxy(bestpos[0]+8,22); printf("%.2f", bestlab[0][1] ); } else if ( bestpos[0] > -999 ) { gotoxy(2,23); printf("%c", 174); gotoxy(2,21); printf("%.2f%c", bestlab[0][0], 248 ); gotoxy(2,22); printf("%.2f", bestlab[0][1] ); } if ( bestpos[1] < 68 ) { gotoxy(bestpos[1]+10,23); printf("%c", 25); gotoxy(bestpos[1]+8,19); printf("%.2f%c", bestlab[1][0], 248 ); gotoxy(bestpos[1]+8,20); printf("%.2f", bestlab[1][1] ); } else if ( bestpos[1] < 999 ) { gotoxy(79,23); printf("%c", 175); gotoxy(74,19); printf("%.2f%c", bestlab[1][0], 248 ); gotoxy(74,20); printf("%.2f", bestlab[1][1] ); } showobjs(); } void upat(int x, int sym) { int i; gotoxy(x+9,24); printf("%c%c%c", 177, sym, 177); for ( i=22 ; i>0 ; i-- ) { gotoxy(x+10,i); printf("%c",30); gotoxy(x+10,i+1); printf("%c",177); minipause(1000); } gotoxy(x+10,1); printf("%c",177); gotoxy(x+9,24); printf(" %c ", sym); if (objdist == 1) showobjs(); for ( i=23 ; i>0 ; i-- ) { gotoxy(x+10,i); printf(" "); minipause(1000); } gotoxy(x+10,1); printf(" "); } void downat() { int i; for ( i=1 ; i<25 ; i++ ) { gotoxy(range+10,i); printf("%c",31); gotoxy(range+10,i-1); printf(" "); minipause(1000); } } void hidecur() { gotoxy(79,25); } void kaboom() { int spacer, i; char pause; int Q = 219; if ( range > 7 && range < 55 ) spacer = range - 6; else if ( range > 20 ) spacer = 48; else spacer = 2; gotoxy(spacer,19); printf(" %c %c %c%c %c%c%c %c%c %c%c %c %c ", Q,Q,Q,Q,Q,Q,Q,Q,Q,Q,Q,Q,Q); gotoxy(spacer,20); printf(" %c %c %c %c %c %c %c %c %c %c %c%c %c%c ", Q,Q,Q,Q,Q,Q,Q,Q,Q,Q,Q,Q,Q,Q); gotoxy(spacer,21); printf(" %c%c %c %c %c %c %c %c %c %c %c %c %c ", Q,Q,Q,Q,Q,Q,Q,Q,Q,Q,Q,Q,Q); gotoxy(spacer,22); printf(" %c %c %c%c%c%c %c %c %c %c %c %c %c %c ", Q,Q,Q,Q,Q,Q,Q,Q,Q,Q,Q,Q,Q,Q); gotoxy(spacer,23); printf(" %c %c %c %c %c%c%c %c%c %c%c %c %c ", Q,Q,Q,Q,Q,Q,Q,Q,Q,Q,Q,Q,Q); if (game != 's') showscore(); for ( i=0 ; i<80 ; i++ ) { pause = 'n'; if ( range+i+6<80 && i>=4 ) { gotoxy(range+i+6,25); printf("%c",219); pause = 'y'; } if ( range+i+7<80 && i>=3 ) { gotoxy(range+i+7,25); printf("%c",178); } if ( range+i+8<80 && i>=2 ) { gotoxy(range+i+8,25); printf("%c",177); } if ( range+i+9<80 && i>=1 ) { gotoxy(range+i+9,25); printf("%c",176); } if ( range+i+10<80 ) { gotoxy(range+i+10,25); printf(" "); pause = 'y'; } if ( range-i+14>1 && i>=4 ) { gotoxy(range-i+14,25); printf("%c",219); pause = 'y'; } if ( range-i+13>1 && i>=3 ) { gotoxy(range-i+13,25); printf("%c",178); } if ( range-i+12>1 && i>=2 ) { gotoxy(range-i+12,25); printf("%c",177); } if ( range-i+11>1 && i>=1 ) { gotoxy(range-i+11,25); printf("%c",176); } if ( range-i+10>1 ) { gotoxy(range-i+10,25); printf(" "); pause = 'y'; } if ( pause == 'y' ) minipause(2500); if ( kbhit() ) { showground(); break; } } } void showscore() { gotoxy(70,2); printf("Turn: %d", turn); gotoxy(70,3); printf("Wins: %d", wins); gotoxy(70,4); printf("Loss: %d", losses); gotoxy(70,5); if (game == 'g') printf("Level: %d", level); else printf("Level: 0"); } void getgametype() { char ans; game = 'i'; gotoxy(3,2); printf("[P]ractice"); gotoxy(3,3); if (level == 1) printf("[G]ame"); else printf("[C]ontinue"); gotoxy(3,4); printf("[A]bout"); gotoxy(3,5); printf("[Q]uit"); do { ans = getch(); if ( ans == 0 ) { ans = getch(); ans = 'i'; } if (ans == 'p' || ans == 'P') { game = 'p'; } else if (ans == 'g' || ans == 'G' || ans == 'c' || ans == 'C') { game = 'g'; } else if (ans == 'a' || ans == 'A') about(); else if (ans == 'q' || ans == 'Q') { clrscr(); showmsg(" Goodbye! "); exit(); } else if ( ans != 'i' ) { game = '?'; printf("\a"); } } while ( game != 'p' && game != 'g' ); } void degreeinput() { char input[11]; char tempnum; float number; int i, j; int point = 0; float multiplyer=.1F; do { i=0; number = 0; gotoxy(15,2); printf(" "); gotoxy(2,2); printf("Enter Degrees: "); do { tempnum = getch(); if ( tempnum > 47 && tempnum < 58 ) { input[i] = tempnum - '0'; printf("%d%c\b", input[i], 248); i++; } else if ( tempnum == '.') { point = 0; for ( j=0 ; j<10 && input[j] != '\n' ; j++ ) if ( input[j] == '.') point = 1; if (point == 0) { input[i] = '.'; printf(".%c\b",248); i++; } } else if ( tempnum == '\b' && i>0 ) { input[i-1] = '\r'; printf("\b%c \b\b", 248); i--; } } while (tempnum != '\r' && i<10); input[i] = '\r'; i=0; while( i<10 && input[i] != '\r' && input[i] != '.' ) { number = number * 10 + input[i]; i++; } if ( input[i] == '.' ) { i++; while( i<20 && input[i] != '\r' ) { number = (input[i] * multiplyer) + number; multiplyer /= 10; i++; } } } while (number < 0 || number > 180 ); degrees = number; } void velocityinput() { char input[11]; char tempnum; float number; int i, j; int point = 0; float multiplyer=.1F; do { i=0; number = 0; gotoxy(15,3); printf(" "); gotoxy(2,3); printf("Enter Velocity: "); do { tempnum = getch(); if ( tempnum > 47 && tempnum < 58 ) { input[i] = tempnum - '0'; printf("%d", input[i]); i++; } else if ( tempnum == '.') { point = 0; for ( j=0 ; j0 ) { input[i-1] = '\r'; printf("\b \b", 248); i--; } } while (tempnum != '\r' && i<10); input[i] = '\r'; i=0; while( i<10 && input[i] != '\r' && input[i] != '.' ) { number = number * 10 + input[i]; i++; } if ( input[i] == '.' ) { i++; while( i<11 && input[i] != '\r' ) { number = (input[i] * multiplyer) + number; multiplyer /= 10; i++; } } } while ( number < 0 || number >= MAXVEL ); velocity = number; } void showmsg(char string[]) { gotoxy(30,10); printf("%s",string); } void about() { char info[160] = {" About Kaboom " "This program was created and compiled by" "*****. Made in 2003. For background " "information, see http://www.*******.com/"}; int i=0, j, k; clearinput(); showmsg(" PRESS ANY KEY... "); gotoxy(20,2); while ( !kbhit() && i<160 ) { printf("%c", info[i]); if (info[i] != ' ') for ( j=-10000 ; j<10000 ; j++ ) for ( k=-10000 ; k<10000 ; k++ ) ; if ( i%40 == 39) gotoxy(20,2+(i/39)); i++; } hidecur(); getch(); clearinput(); showmsg(" "); showscore(); getgametype(); }