Advertisement
Felanpro

Typeracer game (incomplete)

Mar 16th, 2019
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <thread>
  4. #include <windows.h>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. //Typeracer game
  10. double timer = 0;
  11. bool end_game = false;
  12.  
  13. void hellothere()
  14. {
  15.     while (!end_game)
  16.     {
  17.         if (timer == 30)
  18.         {
  19.             end_game = true;
  20.             system("cls");
  21.         }
  22.         Sleep(1000);
  23.         timer++;
  24.     }
  25. }
  26.  
  27. char word[5];
  28. string input_from_player;
  29.  
  30. void intitialize_word()
  31. {
  32.     srand(time(NULL));
  33.     for (int x = 0; x < 5; x++)
  34.     {
  35.         word[x] = (rand() % 25) + 97;
  36.     }
  37.     input_from_player = word;
  38. }
  39.  
  40. int main()
  41. {
  42.     intitialize_word();
  43.  
  44.     double points = 0;
  45.  
  46.     thread clock(hellothere);
  47.  
  48.     while (!end_game)
  49.     {
  50.         for (int k = 0; k < 5; k++)
  51.         {
  52.             cout << word[k];
  53.         }
  54.  
  55.         cout << endl;
  56.  
  57.         cin >> input_from_player;
  58.         if (input_from_player == word)
  59.         {
  60.             intitialize_word();
  61.             points++;
  62.         }
  63.         system("cls");
  64.  
  65.         if (points == 10)
  66.         {
  67.             end_game = true;
  68.         }
  69.     }
  70.  
  71.     clock.join(); //End time
  72.  
  73.     double words_per_minute = (points/timer) * 60;
  74.  
  75.     cout << words_per_minute << endl;
  76.  
  77.     cout << "You typed 10 words over a period of " << timer << " seconds" << endl;
  78.     cout << "This estimates to " << words_per_minute << " words per minute." << endl;
  79.  
  80.     int pause; cin >> pause; //Pause the game
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement