Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4. #include <ctime>
  5.  
  6. using namespace std;
  7.  
  8. class player
  9. {
  10. public:
  11.     string name;
  12.     int Accuracy;
  13.     int Bulls_Hit;
  14.     int DartsThrown;
  15.  
  16.     //functions
  17.     void PrintAll()
  18.     {
  19.         cout << name << endl;
  20.         cout << Accuracy << endl;
  21.         cout << Bulls_Hit << endl;
  22.         cout << DartsThrown << endl;
  23.     }
  24.  
  25.     int DoesitHit() //Random Number to generte if they hit
  26.     {
  27.         int Throw = rand() % 100 + 1;
  28.         cout << Throw << endl;
  29.         return Throw;
  30.     }
  31.  
  32.     bool Game() //hit check
  33.     {
  34.         if (Bulls_Hit < 10)
  35.         {
  36.             int Throw = DoesitHit();
  37.             //cout << Throw << endl;
  38.             if (Throw > Accuracy)
  39.             {
  40.                 cout << name << " Missed :(" << endl;
  41.                 DartsThrown++;
  42.                 return false;
  43.             }
  44.             else if (Throw <= Accuracy)
  45.             {
  46.                 cout << name << " Hit :)" << endl;
  47.                 Bulls_Hit++;
  48.                 DartsThrown++;
  49.                 return true;
  50.             }
  51.         }
  52.  
  53.     }
  54.     int play()
  55.     {
  56.         cout << "Joe Throws First" << endl;
  57.         for (int x = 0; x < 3; x++)
  58.         {
  59.             Game();
  60.             WinningCondition();
  61.  
  62.         }
  63.         cout << "Sid Throws Next" << endl;
  64.         for (int x = 0; x < 3; x++)
  65.         {
  66.             Game();
  67.             WinningCondition();
  68.         }
  69.  
  70.         PrintAll();
  71.         PrintAll();
  72.     }
  73.  
  74.     int GetBulls()
  75.     {
  76.         return Bulls_Hit;
  77.     }
  78.     void GetName()
  79.     {
  80.         return name;
  81.     }
  82.  
  83.     void WinningCondition()
  84.     {
  85.         if (Bulls_Hit == 10)
  86.         {
  87.             cout << name << "Hit the Bulls Eye 10 times, They Won! :D" << endl;
  88.         }
  89.         else if (Bulls_Hit != 10)
  90.         {
  91.             return;
  92.         }
  93.     }
  94. };
  95.  
  96. int main()
  97. {
  98.     srand(time(0));
  99.     player Joe;
  100.     Joe.name = "Joe";
  101.     Joe.Accuracy = 71;
  102.     Joe.Bulls_Hit = 0;
  103.     Joe.DartsThrown = 0;
  104.    
  105.     int JoeBulls = 0;
  106.     int SidBulls = 0;
  107.     string PlayerName;
  108.  
  109.     player Sid;
  110.     Sid.name = "Sid";
  111.     Sid.Accuracy = 73;
  112.     Sid.Bulls_Hit = 0;
  113.     Sid.DartsThrown = 0;
  114.  
  115.     Joe.PrintAll();
  116.     Sid.PrintAll();
  117.  
  118.     //Joe.DoesitHit();
  119.     //Joe.Game();
  120.     JoeBulls = Joe.GetBulls();
  121.     SidBulls = Sid.GetBulls();
  122.     PlayerName = Joe.Getname();
  123.     PlayerName = Sid.Getname();
  124.  
  125.  
  126.     if (JoeBulls > 10 || SidBulls > 10)
  127.     {
  128.         cout << name << "Hit the Bull 10 times, They Win!" << endl;
  129.     }
  130.  
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement