Advertisement
Guest User

Untitled

a guest
Aug 10th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Players
  5. {
  6. public:
  7.     int id;
  8.     string  name;
  9.     int life = 100;
  10.     int damage = 20;
  11. };
  12.  
  13. int main()
  14. {
  15.     int id;
  16.     int shoot = 0;
  17.     int reply = -1;
  18.     string player1;
  19.  
  20.     cout << "Choose an username: ";
  21.     cin >> player1;
  22.     Players p1;
  23.     p1.name = player1;
  24.     Players p2;
  25.     p2.name = "Naabs";
  26.     cout << "Welcome: " << p1.name << endl << "Your heath: "<< p1.life << endl << endl;
  27.     cout << "Starting a new game..." << endl << endl;
  28.     cout << "You are versus : " << p2.name << endl << "His heath: " << p2.life << endl << endl;
  29.     while(p1.life >= 0 && p2.life >= 0)
  30.     {
  31.         cout << "Do you want to shoot at: " << p2.name << " ? (1 or 0): ";
  32.         cin >> reply;
  33.         if (reply == 1 || reply == 0)
  34.         {
  35.             p2.life = p2.life - p1.damage;
  36.             cout << p2.name << " has been shoot and took: " << p1.damage << " damages" << endl;
  37.             cout << p2.life << " life left" << endl;
  38.         }
  39.         else
  40.         {
  41.             cout << "Invalide reply... Quitting";
  42.             return 0;
  43.         }
  44.     }
  45.     cout << p2.name << " is dead, good job" << endl;
  46.     cout << p1.name << " has won";
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement