/* http://www.mrwadlo.com */ #include #include #include #define X 0 #define Y 1 #define MAXMONS 3267 int turn = 0; int curmons = 0; int lose = 0; float handycap = 1.0 ; int setup; int deaths; int treatcount; int play[2]; int mons[2][MAXMONS+1]; float pwr[MAXMONS+1]; /* int rndloc[MAXMONS]; */ int treat[2][MAXMONS]; int last[2][MAXMONS]; int turns[MAXMONS]; void drawscreen(); void left(); void right(); void up(); void down(); void drawchars(); void initialize(); int occupied(int x, int y); void randomlocs(); int onezero(); void swing(); void shiftarray(int x); void status(); void ext(); void treatcheck(int x, int y); void viewer(); void pause(); main() { char com = 2; int px, py, ax, ay, rnd, i; textcolor(15); clrscr(); while (curmons < 1 || curmons > MAXMONS) { gotoxy(30,20); printf("Enter Difficulty 1-3267: "); scanf("%d", &curmons); } clrscr(); setup = 1; drawscreen(); initialize(); drawchars(); setup = 0; while (com != 27 && lose == 0 && curmons > 0) { if (turn == 0) { last[0][0] = play[0]; last[1][0] = play[1]; deaths = 0; for ( i=1 ; i<=curmons ; i++ ) { last[0][i] = mons[0][i]; last[1][i] = mons[1][i]; } status(); gotoxy(80,50); com = getch(); if (com == NULL) { com = getch(); if ( com == 75 && play[0] > 3 ) left(); else if ( com == 77 && play[0] < 78 ) right(); else if ( com == 72 && play[1] > 3 ) up(); else if ( com == 80 && play[1] <45 ) down(); } else if ( com == '5' ) { viewer(); turn--; } } else if (turn > curmons) turn = -1; else { for ( i=turns[turn] ; i>0 ; i-- ) { px = play[0] - mons[0][turn]; py = play[1] - mons[1][turn]; if (px < 0) ax = px*-1; else ax = px; if (py < 0) ay = py*-1; else ay = py; /* gotoxy(49,48); printf("%3d", turn); gotoxy(49,49); printf("X: %3d = %3d - %3d |%3d|", px, play[0], mons[0][turn], ax); gotoxy(49,50); printf("Y: %3d = %3d - %3d |%3d|", py, play[1], mons[1][turn], ay); getch(); getch(); */ rnd = onezero(); if (/*ax >= ay*/ (ay == 0 || rnd == 1) && ax != 0) { if (px > 0 ) { if (occupied(mons[0][turn]+1,mons[1][turn]) == 0) { mons[0][turn]++; gotoxy(50,50); printf("CASE A"); /* getch(); */ gotoxy(50,50); printf(" "); } /* else { swing(turn, gotoxy(50,50); printf("CASE B"); getch(); gotoxy(50,50); printf(" "); } */ } else if (px < 0) { if (occupied(mons[0][turn]-1,mons[1][turn]) == 0) { mons[0][turn]--; gotoxy(50,50); printf("CASE C"); /* getch(); */ gotoxy(50,50); printf(" "); } /* else { gotoxy(50,50); printf("CASE D"); getch(); gotoxy(50,50); printf(" "); } */ } } else { if (py > 0) { if (occupied(mons[0][turn],mons[1][turn]+1) == 0) { mons[1][turn]++; gotoxy(50,50); printf("CASE E"); /* getch(); */ gotoxy(50,50); printf(" "); } /* else { gotoxy(50,50); printf("CASE F"); getch(); gotoxy(50,50); printf(" "); } */ } else if (py < 0) { if (occupied(mons[0][turn],mons[1][turn]-1) == 0) { mons[1][turn]--; gotoxy(50,50); printf("CASE G"); /* getch(); */ gotoxy(50,50); printf(" "); } /* else { gotoxy(50,50); printf("CASE H"); getch(); gotoxy(50,50); printf(" "); } */ } } } /* gotoxy(10,40); printf("mx=%d my=%d px=%d py=%d ax=%d ay=%d", play[0], play[1], px, py, ax, ay); getch(); */ } if (turn == curmons) drawchars(); turn++; } ext(); return 0; } void drawscreen() { int i, j; for ( i=3 ; i<79 ; i++ ) { gotoxy(i,2); printf("%c", 205); gotoxy(i,46); printf("%c", 205); } for ( i=3 ; i<46 ; i++ ) { gotoxy(2,i); printf("%c", 186); gotoxy(79,i); printf("%c", 186); } gotoxy(2,2); printf("%c", 201); gotoxy(2,46); printf("%c", 200); gotoxy(79,2); printf("%c", 187); gotoxy(79,46); printf("%c", 188); } void left() { if(occupied(play[0]-1,play[1]) == 0) { play[0]--; treatcheck(play[0],play[1]); drawchars(); pwr[0] += handycap; } } void right() { if(occupied(play[0]+1,play[1]) == 0) { play[0]++; treatcheck(play[0],play[1]); drawchars(); pwr[0] += handycap; } } void up() { if(occupied(play[0],play[1]-1) == 0) { play[1]--; treatcheck(play[0],play[1]); drawchars(); pwr[0] += handycap; } } void down() { if(occupied(play[0],play[1]+1) == 0) { play[1]++; treatcheck(play[0],play[1]); drawchars(); pwr[0] += handycap; } } void drawchars() { int i, j; for ( i=0 ; i<=curmons+deaths ; i++ ) { if (setup == 0) { gotoxy(last[0][i],last[1][i]); printf(" "); } } textcolor(14); for ( i=0 ; i<(curmons+25)/5 ; i++ ) { if (treat[0][i] != 0 && treat[1][i] != 0) { gotoxy(treat[0][i],treat[1][i]); cprintf("%c", 235); gotoxy(10,46); printf("%d",i); } } textcolor(12); for ( i=1 ; i<=curmons ; i++ ) { if (pwr[i] > -1) { gotoxy(mons[0][i],mons[1][i]); if (pwr[i] > 9) cprintf("X"); else if (pwr[i] < 1) cprintf("0"); else cprintf("%1.0f", pwr[i]); } } textcolor(10); gotoxy(play[0],play[1]); cprintf("%c", 2); } void initialize() { int i; play[0] = 20; play[1] = 20; randomlocs(); pwr[0] = 10; for ( i=1 ; i<=curmons ; i++ ) { pwr[i] = 5+(i%5); } for ( i=1 ; i 0 ) cprintf("Goodbye"); else if (curmons < 1) cprintf("Winner!"); else cprintf("Game Over"); gotoxy(35,21); cprintf("Press ESC to View Hall of Fame"); while (com != 27) com = getch(); fp = fopen("roggle.fam","r"); if (fp != 0) { for ( i=0 ; i<40 ; i++ ) { fscanf(fp, "%s", play[i].Name); fscanf(fp, "\t%d\n", &play[i].Score); } } else printf("Failed Load"); fclose(fp); clrscr(); /* gotoxy(25,8); printf("Float = %.0f", pwr[0]); */ while (pwr[0] >= ftod + 1) { ftod++; gotoxy(60,47); printf("Calc ftod: %d ", ftod); } /* gotoxy(25,9); printf("Deccc = %d", ftod); */ i=0; while (i<40 && play[i].Score > ftod) i++; if (i<40) { /* printf("i = %d j = %d",i,j); */ j=40; while (j>i) { play[j].Score = play[j-1].Score; for ( k=0 ; k<11 ; k++ ) play[j].Name[k] = play[j-1].Name[k]; j--; } play[i].Score = ftod; gotoxy(50,10); printf("Enter Your Name: "); scanf("%10s", play[i].Name); clrscr(); current = i; } gotoxy(40,2); printf("Hall of Fame"); for ( i=0 ; i<40 ; i++ ) { gotoxy(5,i+4); for ( j=0 ; (j<10) && play[i].Name[j] != NULL ; j++ ) printf("%c", play[i].Name[j]); gotoxy(17,i+4); printf("%d", play[i].Score); pause(); } if (current != -1) { gotoxy(4,current+4); printf("%c",16); } fp = fopen("roggle.fam","w"); if (fp != 0) { for ( i=0 ; i<40 ; i++ ) { fprintf(fp, "%s", play[i].Name); fprintf(fp, "\t%d\n", play[i].Score); } } else printf("Failed Load"); fclose(fp); com = 2; while (com != 27) com = getch(); exit(); } void treatcheck(int x, int y) { int i; for ( i=0 ; i3) { x--; gotoxy(x+1,y); printf(" "); } else if (com == '8' && y>3) { y--; gotoxy(x,y+1); printf(" "); } else if (com == '6' && x<78) { x++; gotoxy(x-1,y); printf(" "); } else if (com == '2' && y<45) { y++; gotoxy(x,y-1); printf(" "); } drawchars(); for ( i=0 ; i