Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class Cowboy {
- public:
- string name, move;
- int bullets, life, points;
- Cowboy(string name) {
- this -> name = name;
- this -> bullets = 0;
- this -> life = 1;
- this -> points = 0;
- this -> move = "";
- }
- void setCurrentMove(string move) {
- if ((move == "BLOCK" && this -> move == "BLOCK") || (move == "LOAD" && this-> bullets >= 1) || (move == "BANG" && this -> bullets == 0)) {
- this -> life = 0;
- }
- if (move == "LOAD") {
- this -> bullets += 1;
- }
- this -> move = move;
- }
- int fight(Cowboy& cowboy2) {
- if (this -> life == 0 && cowboy2.life == 1) {
- cowboy2.points += 1;
- return 2;
- }
- else if (this -> life == 1 && cowboy2.life == 0) {
- this -> points += 1;
- return 1;
- }
- else if (this -> life == 0 && cowboy2.life == 0) {
- return 0;
- }
- if (this -> move == "BANG" && cowboy2.move == "LOAD") {
- this -> bullets += 1;
- return 1;
- }
- else if (cowboy2.move == "BANG" && this -> move == "LOAD") {
- cowboy2.points += 1;
- return 2;
- }
- return 0;
- }
- void reset() {
- this -> life = 1;
- this -> bullets = 0;
- this-> move = "";
- }
- };
- void round(Cowboy& cowboy1, Cowboy& cowboy2) {
- string ruch1, ruch2;
- int value;
- cout << "podaj ruch, Cowboyu1: ";
- cin >> ruch1;
- cout << "podaj ruch, Cowboyu2: ";
- cin >> ruch2;
- cowboy1.setCurrentMove(ruch1);
- cowboy2.setCurrentMove(ruch2);
- value = cowboy1.fight(cowboy2);
- if (value == 1) {
- cout << "Cowboy1 wygrał";
- cowboy1.reset();
- cowboy2.reset();
- }
- if (value == 2) {
- cout << "Cowboy2 wygrał";
- cowboy1.reset();
- cowboy2.reset();
- }
- if (value == 0){
- cout << "Remis";
- }
- cout << "punkty Cowboy1: " << cowboy1.points << " punkty Cowboy2: " << cowboy2.points;
- }
- int main() {
- int maxPoints;
- Cowboy *cowboy1 = new Cowboy("ania");
- Cowboy *cowboy2 = new Cowboy("kasia");
- cout << &cowboy2.name;
- cout << "Podaj po zdobyciu ilu punktów gracz wygrywa: ";
- cin >> maxPoints;
- while ((cowboy1.points < maxPoints) && (cowboy2.points < maxPoints)) {
- round(cowboy1, cowboy2);
- }
- if (cowboy1.points == maxPoints) {
- cout << "Cowboy1 wygrał grę!";
- }
- if (cowboy2.points == maxPoints){
- cout << "Cowboy2 wygrał grę";
- }
- return 0;
- }
- // czy potrzebna jest * ?? (66 linijka)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement