Staniell

Untitled

Feb 24th, 2021
748
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Main File
  2. #include <iostream>      
  3. #include <thread>        
  4. #include <windows.h>
  5. #include "SharedHeader.h"
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     int n = 1;
  12.     thread t1(mygame::GenerateNumbers);
  13.     thread t5(mygame::PlayBG);
  14.     while (mygame::lives>0) {
  15.         cin >> n;
  16.         if (n == mygame::result) {
  17.             thread t2(mygame::AddPoints);
  18.             t2.join();
  19.             thread t3(mygame::AddLife);
  20.             t3.join();
  21.             //Added winmm.live in the additional dependencies
  22.             thread t6(mygame::PlayRight);
  23.         }
  24.         else {
  25.             thread t7(mygame::PlayWrong);
  26.         }
  27.         /*Sleep(200);*/
  28.  
  29.     }
  30.     t1.join();
  31.     return 0;
  32. }
  33.  
  34.  
  35. //Functions and Data types from header file
  36. #include <iostream>
  37. #include <windows.h>
  38. #include <random>
  39.  
  40. using namespace std;
  41. namespace mygame
  42. {
  43.     int points = 0;
  44.     int lives = 5;
  45.     int n1;
  46.     int n2;
  47.     int rand_operator;
  48.     int result;
  49.  
  50.     void GenerateNumbers()
  51.     {
  52.         for (int i = 0; i < 20; i++) {
  53.             if (lives == 0) {
  54.                 cout << "\nYou've ran out of lives!\nScore:"<< points;
  55.                 break;
  56.             }
  57.             /* initialize random seed: */
  58.             srand(time(NULL));
  59.             n1 = rand() % 100;
  60.             n2 = rand() % 10;
  61.             rand_operator = rand() % 3;
  62.  
  63.             cout << "\nLives:" <<lives << "\tPoints:" << points <<"\n";
  64.  
  65.             switch (rand_operator)
  66.             {
  67.             case 0://Addition
  68.                 cout << "\n" << n1 << "+" << n2 << "\n=";
  69.                 result = n1 + n2;
  70.                 break;
  71.             case 1://Multiplication
  72.                 cout << "\n" << n1 << "*" << n2 << "\n=";
  73.                 result = n1 * n2;
  74.                 break;
  75.             case 2://Subtraction
  76.                 cout << "\n" << n1 << "-" << n2 << "\n=";
  77.                 result = n1 - n2;
  78.                 break;
  79.             }
  80.  
  81.             Sleep(5000);
  82.             lives -= 1;
  83.         }
  84.     }
  85.  
  86.     void AddPoints()
  87.     {
  88.         points += 1;
  89.     }
  90.  
  91.     void AddLife() {
  92.         lives += 1;
  93.     }
  94.    
  95.     void PlayBG() {
  96.         PlaySound(TEXT("220060__portwain__quiz-game-music-loop-bpm-90"), NULL, SND_SYNC);
  97.     }
  98.  
  99.     void PlayWrong() {
  100.         PlaySound(TEXT("131657__bertrof__game-sound-wrong.wav"), NULL, SND_ASYNC);
  101.     }
  102.  
  103.     void PlayRight() {
  104.         PlaySound(TEXT("131660__bertrof__game-sound-correct.wav"), NULL, SND_ASYNC);
  105.     }
  106. }
  107.  
  108.  
  109. //Header File
  110. #pragma once
  111. namespace mygame
  112. {
  113.     void GenerateNumbers();
  114.     void AddPoints();
  115.     void AddLife();
  116.     void PlayBG();
  117.     void PlayRight();
  118.     void PlayWrong();
  119.     extern int n1;
  120.     extern int n2;
  121.     extern int points;
  122.     extern int srand;
  123.     extern int lives;
  124.     extern int result;
  125.     extern int rand_operator;
  126. }
  127.  
  128.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×