Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <thread>
- #include <windows.h>
- #include <string>
- #include <conio.h> //Gain access to getch()
- using namespace std;
- //Typeracer game
- double timer = 0;
- bool end_game = false;
- int errors;
- int error_words;
- int temporary_errors = 0;
- void hellothere()
- {
- while (!end_game)
- {
- if (timer == 30)
- {
- end_game = true;
- system("cls");
- }
- Sleep(1000);
- timer++;
- }
- }
- char word[5];
- char input_from_player[5];
- void intitialize_word()
- {
- srand(time(NULL));
- for (int x = 0; x < 5; x++)
- {
- word[x] = (rand() % 25) + 97;
- }
- }
- int main()
- {
- double points = 0;
- thread clock(hellothere);
- while (!end_game)
- {
- intitialize_word();
- cout << word << endl;
- for (int k = 0; k < 5; k++)
- {
- if (k > 0)
- cout << word[k - 1];
- while (input_from_player[k] != word[k])
- {
- input_from_player[k] = _getch();
- if (input_from_player[k] != word[k])
- {
- errors++;
- temporary_errors = 1;
- }
- }
- }
- if (temporary_errors == 1)
- {
- error_words++;
- temporary_errors = 0;
- }
- points++;
- if (points == 10)
- {
- end_game = true;
- }
- system("cls");
- }
- clock.join(); //End time
- double words_per_minute = (points/timer) * 60;
- cout << "You typed 10 words over a period of " << timer << " seconds" << endl;
- cout << "This estimates to " << words_per_minute << " words per minute." << endl;
- cout << "Number of erros: " << errors << endl;
- cout << "Number of words messed up on: " << error_words;
- int pause; cin >> pause; //Pause the game
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement