summaryrefslogtreecommitdiff
path: root/src/games/music.c
blob: 3b52b4ee9d82d746d17d488a3fa0895abf36d793 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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;
}