-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
88 lines (82 loc) · 2.22 KB
/
main.c
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <stdio.h>
#include <ncurses.h>
#include <ctype.h>
#include "ngui.h"
#include <string.h>
#include <time.h>
#include <math.h>
#define NOMBRE_MOTS 20
#define DUREE_TEST 60
int main(){
initscr();
start_color();
init_pair(1, COLOR_WHITE, COLOR_GREEN);
init_pair(2, COLOR_WHITE, COLOR_RED);
init_pair(3, COLOR_WHITE, COLOR_BLACK);
keypad(stdscr, TRUE);
noecho();
cbreak();
timeout(1000);
int countdown=1;
int gameState=1, ch=0;
float wpm=0;
char buffer[100]={0}, *s=buffer;
char *listeMots[NOMBRE_MOTS]={NULL};
genereTexte(listeMots, NOMBRE_MOTS);
int indice=0 , score=1;
int tableau[NOMBRE_MOTS]={3};
time_t init=time(NULL);
while(gameState!=0 && countdown>0){
erase();
countdown=DUREE_TEST-difftime(time(NULL), init);
if(countdown!=DUREE_TEST){
wpm=(float)score/(DUREE_TEST-countdown);
}
else
wpm=5;
mvprintw(0, 0, "countdown: %d score:%d WPM:%f",countdown, score, wpm);
move(1, 0);
if(indice>=NOMBRE_MOTS){
genereTexte(listeMots, NOMBRE_MOTS);
indice=0;
for(int h=0;h<NOMBRE_MOTS;h++){
tableau[h]=3;
}
}
for (int i=0;i<NOMBRE_MOTS;i++){
attron(COLOR_PAIR(tableau[i]));
printw("%s ", listeMots[i]);
attroff(COLOR_PAIR(tableau[i]));
}
mvprintw(4,0, "answer:%s", buffer);
refresh();
if((ch=getch())!=ERR){
if(ch==' '){
if(strcmp(buffer,listeMots[indice])==0){
score++;
tableau[indice]=1;
}
else{
tableau[indice]=2;
}
indice++;
*s = 0;
sscanf(buffer, "%d", &gameState);
s = buffer;
*s = 0;
}
else if(ch==KEY_BACKSPACE){
if(s>buffer)
*--s=0;
}
else if(ch=='\n'){
}
else if(s-buffer<(long)sizeof buffer-1){
*s++=ch;
*s=0;
}
}
}
endwin();
return 0;
}