Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class Cowboy {
  7. public:
  8.     string name, move;
  9.     int bullets, life, points;
  10.    
  11.     Cowboy(string name) {
  12.         this -> name = name;
  13.         this -> bullets = 0;
  14.         this -> life = 1;
  15.         this -> points = 0;
  16.         this -> move = "";
  17.         }
  18.        
  19.     void setCurrentMove(string move) {
  20.         if ((move == "BLOCK" && this -> move == "BLOCK") || (move == "LOAD" && this-> bullets >= 1) || (move == "BANG" && this -> bullets == 0)) {
  21.             this -> life = 0;
  22.         }
  23.  
  24.         if (move == "LOAD") {
  25.             this -> bullets += 1;
  26.         }
  27.  
  28.         this -> move = move;
  29.     }
  30.  
  31.     int fight(Cowboy& cowboy2) {
  32.         if (this -> life == 0 && cowboy2.life == 1) {
  33.             cowboy2.points += 1;
  34.             return 2;
  35.         }
  36.         else if (this -> life == 1 && cowboy2.life == 0) {
  37.             this -> points += 1;
  38.             return 1;
  39.         }
  40.         else if (this -> life == 0 && cowboy2.life == 0) {
  41.             return 0;
  42.         }
  43.  
  44.         if (this -> move == "BANG" && cowboy2.move == "LOAD") {
  45.             this -> bullets += 1;
  46.             return 1;
  47.         }
  48.         else if (cowboy2.move == "BANG" && this -> move == "LOAD") {
  49.             cowboy2.points += 1;
  50.             return 2;
  51.         }
  52.  
  53.         return 0;
  54.     }
  55.  
  56.     void reset() {
  57.         this -> life = 1;
  58.         this -> bullets = 0;
  59.         this-> move = "";
  60.     }
  61.    
  62. };
  63.  
  64.  
  65.  
  66. void round(Cowboy& cowboy1, Cowboy& cowboy2) {
  67.     string ruch1, ruch2;
  68.     int value;
  69.    
  70.     cout << "podaj ruch, Cowboyu1: ";
  71.     cin >> ruch1;
  72.     cout << "podaj ruch, Cowboyu2: ";
  73.     cin >> ruch2;
  74.    
  75.  
  76.     cowboy1.setCurrentMove(ruch1);
  77.     cowboy2.setCurrentMove(ruch2);
  78.     value = cowboy1.fight(cowboy2);
  79.     if (value == 1) {
  80.         cout << "Cowboy1 wygrał";
  81.         cowboy1.reset();
  82.         cowboy2.reset();
  83.     }
  84.     if (value == 2) {
  85.         cout << "Cowboy2 wygrał";
  86.         cowboy1.reset();
  87.         cowboy2.reset();
  88.     }
  89.     if (value == 0){
  90.         cout << "Remis";
  91.     }
  92.     cout << "punkty Cowboy1: " << cowboy1.points << " punkty Cowboy2: " << cowboy2.points;
  93. }
  94.  
  95.  
  96. int main() {
  97.     int maxPoints; 
  98.    
  99.     Cowboy *cowboy1 = new Cowboy("ania");
  100.     Cowboy *cowboy2 = new Cowboy("kasia");
  101.     cout << &cowboy2.name;
  102.    
  103.     cout << "Podaj po zdobyciu ilu punktów gracz wygrywa: ";
  104.     cin >> maxPoints;
  105.  
  106.     while ((cowboy1.points < maxPoints)  && (cowboy2.points < maxPoints)) {
  107.         round(cowboy1, cowboy2);
  108.     }
  109.     if (cowboy1.points == maxPoints) {
  110.         cout << "Cowboy1 wygrał grę!";
  111.     }
  112.     if (cowboy2.points == maxPoints){
  113.         cout << "Cowboy2 wygrał grę";
  114.     }
  115.    
  116.     return 0;
  117. }
  118.  
  119. // czy potrzebna jest * ?? (66 linijka)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement