Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Main File
- #include <iostream>
- #include <thread>
- #include <windows.h>
- #include "SharedHeader.h"
- using namespace std;
- int main()
- {
- int n = 1;
- thread t1(mygame::GenerateNumbers);
- thread t5(mygame::PlayBG);
- while (mygame::lives>0) {
- cin >> n;
- if (n == mygame::result) {
- thread t2(mygame::AddPoints);
- t2.join();
- thread t3(mygame::AddLife);
- t3.join();
- //Added winmm.live in the additional dependencies
- thread t6(mygame::PlayRight);
- }
- else {
- thread t7(mygame::PlayWrong);
- }
- /*Sleep(200);*/
- }
- t1.join();
- return 0;
- }
- //Functions and Data types from header file
- #include <iostream>
- #include <windows.h>
- #include <random>
- using namespace std;
- namespace mygame
- {
- int points = 0;
- int lives = 5;
- int n1;
- int n2;
- int rand_operator;
- int result;
- void GenerateNumbers()
- {
- for (int i = 0; i < 20; i++) {
- if (lives == 0) {
- cout << "\nYou've ran out of lives!\nScore:"<< points;
- break;
- }
- /* initialize random seed: */
- srand(time(NULL));
- n1 = rand() % 100;
- n2 = rand() % 10;
- rand_operator = rand() % 3;
- cout << "\nLives:" <<lives << "\tPoints:" << points <<"\n";
- switch (rand_operator)
- {
- case 0://Addition
- cout << "\n" << n1 << "+" << n2 << "\n=";
- result = n1 + n2;
- break;
- case 1://Multiplication
- cout << "\n" << n1 << "*" << n2 << "\n=";
- result = n1 * n2;
- break;
- case 2://Subtraction
- cout << "\n" << n1 << "-" << n2 << "\n=";
- result = n1 - n2;
- break;
- }
- Sleep(5000);
- lives -= 1;
- }
- }
- void AddPoints()
- {
- points += 1;
- }
- void AddLife() {
- lives += 1;
- }
- void PlayBG() {
- PlaySound(TEXT("220060__portwain__quiz-game-music-loop-bpm-90"), NULL, SND_SYNC);
- }
- void PlayWrong() {
- PlaySound(TEXT("131657__bertrof__game-sound-wrong.wav"), NULL, SND_ASYNC);
- }
- void PlayRight() {
- PlaySound(TEXT("131660__bertrof__game-sound-correct.wav"), NULL, SND_ASYNC);
- }
- }
- //Header File
- #pragma once
- namespace mygame
- {
- void GenerateNumbers();
- void AddPoints();
- void AddLife();
- void PlayBG();
- void PlayRight();
- void PlayWrong();
- extern int n1;
- extern int n2;
- extern int points;
- extern int srand;
- extern int lives;
- extern int result;
- extern int rand_operator;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement