-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass_and_game.cpp
More file actions
79 lines (72 loc) · 1.6 KB
/
Copy pathclass_and_game.cpp
File metadata and controls
79 lines (72 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <cstdlib>
#include <ctime>
using std::cout;
using std::endl;
using std::cin;
class People {
private:
int life;
int dano;
public:
People(int a, int c) {
life = a;
life = life > 100? 100:life;
dano = c;
dano = dano > 25? 25:dano;
}
int getLife() {
return life;
}
int getDano() {
return dano;
}
void sertar(People &objetivo) {
objetivo.life -= dano;
objetivo.life = objetivo.life <= 0? 0:objetivo.life;
cout<<"El enemigo tiene "<<objetivo.life<<endl;
if(objetivo.life > 0) {
life -= objetivo.dano;
life = life < 0? 0:life;
cout<<"Tienes "<<life<<endl;
}
}
void masur(People &enemigo, int z) {
int y = life + z;
life = y > 100? 100:y;
cout<<"Te curaste "<<z<<" Y tienes "<<life<<"PS"<<endl;
enemigo.life = enemigo.life < 25? enemigo.life + 50:enemigo.life;
cout<<"El enemigo se curo 50 y tiene "<<enemigo.life<<"PS"<<endl;
}
};
int main() {
int des;
int w;
srand(time(NULL));
int g = (rand() % (100 - 50 + 1)) + 50;
int h = (rand() % (25 - 10 + 1)) + 20;
People A1(g, h);
h = (rand() % (25 - 10 + 1)) + 20;
g = (rand() % (100 - 50 + 1)) + 50;
People B2(g, h);
cout<<"Tienes "<<A1.getLife()<<"PS y "<<A1.getDano()<<"PD"<<endl;
cout<<"Tiene el enemigo "<<B2.getLife()<<"PS y "<<B2.getDano()<<"PD"<<endl;
while(A1.getLife() > 0 && B2.getLife() > 0) {
cout<<"Que acción quieres 1.- atacar: 2.-curarse"<<endl;
cin>>des;
switch(des) {
case 1:
A1.sertar(B2);
break;
case 2:
cout<<"Cuanto te quieres curar? "<<endl;
cin>>w;
A1.masur(B2, w);
break;
default:
cout<<"Accion invalida "<<endl;
break;
}
}
return 0;
}