/* http://www.mrwadlo.com */ #include #include #include #include int guess; int question[9]; int answer[9]; int total[7] = { 0,0,0,0,0,0,0 }; int games[7] = { 0,0,0,0,0,0,0 }; int cols = 4; void createboard(); void drawboard(); void getguess(); char compare(); void rank(); void getrows(); void help(); void load(); void save(); void demo(); void showarrow(); void main() { int i; char ext = 'y'; char win = 'n'; clrscr(); textcolor(7); textbackground(0); load(); getrows(); while ( ext != 'q' && ext != 'Q' ) { guess = 0; clrscr(); rank('n'); createboard(); drawboard(); while ( win == 'n' && guess < 20 ) { showarrow(); getguess(); win = compare(); } gotoxy(3,24); for ( i=0 ; i0 ) { printf("\b \b"); i--; } else if ( ch > 0 && ch < 5 && i 0 ) { printf("%2d.%1.0f", total[i-3] / games[i-3], ((1.0F * total[i-3] / games[i-3]) - total[i-3]/games[i-3]) * 10); } else { printf(" N/A"); } } } void getrows() { int i; do { clrscr(); textcolor(14); for ( i=8 ; i<16 ; i++ ) { gotoxy(21,i); cprintf("%c",186); gotoxy(47,i); cprintf("%c",186); } for ( i=22 ; i<47 ; i++ ) { gotoxy(i,7); cprintf("%c",205); gotoxy(i,16); cprintf("%c",205); } gotoxy(21,7); cprintf("%c",201); gotoxy(21,16); cprintf("%c",200); gotoxy(47,7); cprintf("%c",187); gotoxy(47,16); cprintf("%c",188); gotoxy(24,11); cprintf("How many columns 3-9?"); gotoxy(27,12); cprintf("(Default is 4)"); textcolor(7); demo(); cols = getch() - '0'; if ( cols < 3 || cols > 9 ) { printf("\a"); } } while ( cols < 3 || cols > 9 ); } void help() { gotoxy(51,2); printf("Attempt to solve the code by"); gotoxy(51,3); printf("entering a sequence of"); gotoxy(51,4); printf("numbers, each ranging from 1"); gotoxy(51,5); printf("to 4. When a row is filled,"); gotoxy(51,6); printf("press enter. To the left of"); gotoxy(51,7); printf("of the board is a response of"); gotoxy(51,8); printf("how many digits you have in"); gotoxy(51,9); printf("the correct order. You have a"); gotoxy(51,10); printf("maximum of 20 guesses. Scores"); gotoxy(51,11); printf("are displayed below."); } void load() { int i; FILE *fp; fp = fopen("memory.dat","r"); if (fp != 0) { for ( i=3 ; i<10 ; i++ ) fscanf(fp, "%d ", &games[i-3]); for ( i=3 ; i<10 ; i++ ) fscanf(fp, "%d ", &total[i-3]); } fclose(fp); } void save() { int i; FILE *fp; fp = fopen("memory.dat","w"); if (fp != 0) { for ( i=3 ; i<10 ; i++ ) fprintf(fp, "%d ", games[i-3]); fprintf(fp, "\n"); for ( i=3 ; i<10 ; i++ ) fprintf(fp, "%d ", total[i-3]); } fclose(fp); } void demo() { int x=1, y=1, rnd, i; if ( cols > 9 || cols < 3 ) { cols = 4; } drawboard(); rank('n'); while ( !kbhit() ) { rnd = rand() % 4 + 1; gotoxy(x+2,y+3); textcolor(rnd+9); cprintf("%d", rnd); x++; if ( x > cols ) { x=1; y++; if ( y > 19) { gotoxy(x+2,y+4); for ( i=0 ; i 0) cprintf("%c",16); textcolor(8); if ( guess > 0 ) { gotoxy(cols+4,guess+2); cprintf("%c%d",17,guess); if (guess-1 <9 && guess-1 > 0) cprintf("%c",16); } if ( guess < 19 ) { gotoxy(cols+4,guess+4); cprintf("%c%d",17,guess+2); if (guess+1 <9) cprintf("%c",16); } if ( guess > 1 ) { gotoxy(cols+4,guess+1); cprintf(" "); if ( guess > 2 ) printf(" "); } textcolor(7); }