Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. #define _CRT_SECURE_NO_DEPRECATE
  2.  
  3. #include <stdio.h>
  4. #include <conio.h>
  5. #include <stdlib.h>
  6. #include <time.h>
  7. #include <windows.h>
  8.  
  9. static void random_gotoxy(void);
  10. static void help(void);
  11. static void press_key();
  12.  
  13. int main(){
  14. unsigned char ch = 0;
  15. unsigned char ch_2 = 0;
  16.  
  17. printf("[F1]\t\tHelp\n[F2]\t\tSpusti\n[F10/ESC]\tUkonci");
  18.  
  19. do{
  20. if (_kbhit()){
  21. ch = _getch();
  22. switch (ch) {
  23. case 0x00:
  24. ch_2 = _getch();
  25.  
  26. if(ch_2 == 59) // F1
  27. help();
  28. else if(ch_2 == 60) // F2
  29. press_key();
  30. else if(ch_2 == 68){ // F10
  31. system("cls");
  32. printf("Koniec...\n\n");
  33. return 0;
  34. }
  35. break;
  36.  
  37. default:
  38. break;
  39. }
  40. }
  41. }while (ch != 27);
  42.  
  43. system("cls");
  44. printf("Koniec...\n\n");
  45. return 0;
  46. }
  47.  
  48. static void random_gotoxy(void){
  49. COORD coord = {0,0};
  50.  
  51. coord.X = rand() % 50 + 1;
  52. coord.Y = rand() % 10 + 1;
  53.  
  54. SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
  55. }
  56.  
  57. static void help(void){
  58. system("cls");
  59. printf("This program measure your reaction time by pressing the given symbol.\n");
  60. printf("Possible symbols are from ASCII(48) - ASCII(122)");
  61. }
  62.  
  63. static void press_key(){
  64. time_t start_watch, stop_watch;
  65. double timer;
  66. char symbol_to_guess = 0;
  67. char symbol_typed = 0;
  68. FILE *fw;
  69.  
  70. system("cls");
  71. start_watch = clock();
  72.  
  73. //symboly od 48-122 .. cisla ..velke a male pismena + tie medzi tym
  74. symbol_to_guess = rand() % 122;
  75. if(symbol_to_guess < 48)
  76. symbol_to_guess += 48;
  77.  
  78. random_gotoxy();
  79. printf("%c", symbol_to_guess);
  80.  
  81. do{
  82. symbol_typed = _getch();
  83. }
  84. while(symbol_typed != symbol_to_guess);
  85.  
  86. system("cls");
  87.  
  88. if(symbol_typed == symbol_to_guess){
  89. stop_watch = clock();
  90.  
  91. timer = (stop_watch - start_watch) / (double)CLOCKS_PER_SEC;
  92.  
  93. printf("You reaction time is %.3fms!", timer);
  94. }
  95.  
  96. fw = fopen("data.txt", "a");
  97. fprintf(fw, "'%c' - %.3fs\n", symbol_to_guess, timer);
  98. fclose(fw);
  99.  
  100. Sleep(2000);
  101. system("cls");
  102. Sleep(500);
  103. main();
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement