Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_DEPRECATE
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <windows.h>
- static void random_gotoxy(void);
- static void help(void);
- static void press_key();
- int main(){
- unsigned char ch = 0;
- unsigned char ch_2 = 0;
- printf("[F1]\t\tHelp\n[F2]\t\tSpusti\n[F10/ESC]\tUkonci");
- do{
- if (_kbhit()){
- ch = _getch();
- switch (ch) {
- case 0x00:
- ch_2 = _getch();
- if(ch_2 == 59) // F1
- help();
- else if(ch_2 == 60) // F2
- press_key();
- else if(ch_2 == 68){ // F10
- system("cls");
- printf("Koniec...\n\n");
- return 0;
- }
- break;
- default:
- break;
- }
- }
- }while (ch != 27);
- system("cls");
- printf("Koniec...\n\n");
- return 0;
- }
- static void random_gotoxy(void){
- COORD coord = {0,0};
- coord.X = rand() % 50 + 1;
- coord.Y = rand() % 10 + 1;
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
- }
- static void help(void){
- system("cls");
- printf("This program measure your reaction time by pressing the given symbol.\n");
- printf("Possible symbols are from ASCII(48) - ASCII(122)");
- }
- static void press_key(){
- time_t start_watch, stop_watch;
- double timer;
- char symbol_to_guess = 0;
- char symbol_typed = 0;
- FILE *fw;
- system("cls");
- start_watch = clock();
- //symboly od 48-122 .. cisla ..velke a male pismena + tie medzi tym
- symbol_to_guess = rand() % 122;
- if(symbol_to_guess < 48)
- symbol_to_guess += 48;
- random_gotoxy();
- printf("%c", symbol_to_guess);
- do{
- symbol_typed = _getch();
- }
- while(symbol_typed != symbol_to_guess);
- system("cls");
- if(symbol_typed == symbol_to_guess){
- stop_watch = clock();
- timer = (stop_watch - start_watch) / (double)CLOCKS_PER_SEC;
- printf("You reaction time is %.3fms!", timer);
- }
- fw = fopen("data.txt", "a");
- fprintf(fw, "'%c' - %.3fs\n", symbol_to_guess, timer);
- fclose(fw);
- Sleep(2000);
- system("cls");
- Sleep(500);
- main();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement