diff options
| -rw-r--r-- | door/music.c | 59 | 
1 files changed, 59 insertions, 0 deletions
diff --git a/door/music.c b/door/music.c new file mode 100644 index 0000000..3b52b4e --- /dev/null +++ b/door/music.c @@ -0,0 +1,59 @@ +#include <stdio.h> +#include <string.h> +#include <time.h> +#include <stdlib.h> + +char cheat; + +void print_note(char n) { + printf("  %c  \n",n=='G'?cheat?n:'o':' '); + printf("--%c--\n",n=='F'?cheat?n:'o':'-'); + printf("  %c  \n",n=='E'?cheat?n:'o':' '); + printf("--%c--\n",n=='D'?cheat?n:'o':'-'); + printf("  %c  \n",n=='C'?cheat?n:'o':' '); + printf("--%c--\n",n=='B'?cheat?n:'o':'-'); + printf("  %c  \n",n=='A'?cheat?n:'o':' '); + printf("--%c--\n",n=='g'?cheat?n:'o':'-'); + printf("  %c  \n",n=='f'?cheat?n:'o':' '); + printf("--%c--\n",n=='e'?cheat?n:'o':'-'); + printf("  %c  \n",n=='d'?cheat?n:'o':' '); + printf("  %c  \n",n=='c'?cheat?n:'o':' '); + printf("  %c  \n",n=='b'?cheat?n:'o':' '); + printf("  %c  \n",n=='a'?cheat?n:'o':' '); +} + +char notes[]="ABCDEFGabcdefg"; + +int main(int argc,char *argv[]) { + int count; + int correct=0; + int total=20; + char note; + cheat=argc > 1; + short in; + srandom(time(0)); + total=20; + count=total; + printf("\x1b[H\x1b[J"); + time_t end; + time_t start=time(0); + for(;in != -1 && count;count--) { +  note=notes[random()%strlen(notes)]; +  print_note(note); +  in=fgetc(stdin); +  if(in == note || in == note+' ') { +   printf("\x1b[H\x1b[J"); +   printf("Yay!\n"); +   correct++; +   in=fgetc(stdin);//kill the newline +  } else { +   printf("\x1b[H\x1b[J"); +   printf("boo!\n"); +   in=fgetc(stdin);//kill the newline +  } + } + end=time(0); + printf("took you %lld seconds\n",end-start); + printf("got %d/%d right.\n",correct,total); + return 0; +}  | 
