-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype-test.c
90 lines (60 loc) · 1.55 KB
/
type-test.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
89
90
#include <ncurses.h>
#include <stdlib.h>
#include <string.h>
#include "tstfunc.h"
#include "color.h"
int main(int argc, char const *argv[])
{
init();
int i = 0, idx, now, counter = 0;;
char temp[100];
struct t typing;
mvprintw(2, 0, "> ");
keypad(stdscr, TRUE);
while(counter < 2){
read_word();
now = 0;
idx = 0;
move(0, 0);
for(int i = 0; i < 8; i++)
printw("%s ", word[i]);
while(idx < 8){
color_word(0, now, word[idx], BG_WHITE);
move(2, 2);
while(' ' != (temp[i] = getch())){
if(temp[i] == 7 && i > 0)
backspace(--i);
else if(temp[i] > 0x20 && temp[i] < 0x7f)
addch(temp[i++]);
};
temp[i] = '\0';
i = 0;
move(2, 2);
clrtoeol();
if(!strcmp(temp, word[idx])){
color_word(0, now, word[idx], BG_GREEN);
typing.correct++;
}
else{
color_word(0, now, word[idx], BG_RED);
typing.wrong++;
}
now += strlen(word[idx]) + 1;
free(word[idx]);
word[idx] = 0;
idx++;
move(2, 0);
}
counter++;
// cleanup();
move(0, 0);
clrtoeol();
}
clear();
// show a result;
result(typing.correct, typing.wrong);
getch();
refresh();
endwin();
return 0;
}