-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathx.cpp
More file actions
136 lines (101 loc) · 2.95 KB
/
x.cpp
File metadata and controls
136 lines (101 loc) · 2.95 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include<iostream>
#include<cstdlib>
using namespace std;
class weapons{
private:
string name;
int dmg;
float chance;
int code;
public:
weapons(string name ,int dmg,float chance,int code){
this->name=name;
this->dmg=dmg;
this->chance=chance;
this->code=code;
}
int attack(){
int random=rand()%101;
if (random >=(1-chance)*100){
cout <<name<<" achieved a succesful hit"<<endl;
return dmg;
}
else{
cout <<name<<" missed"<<endl;
return 0;
}
}
int getcode(){
return code;
}
string getname(){
return name;
}
};
class fighter{
private:
bool alive;
int health;
string name;
int wep1;
int wep2;
int wep3;
public:
fighter(string name,int wep1,int wep2,int wep3,bool alive=true,int health=300){
this->name=name;
this->wep1=wep1;
this->wep2=wep2;
this->wep3=wep3;
this->alive=alive;
this->health=health;
}
bool checkhealth(){
if(health>0){
return alive;
}
else{
alive=false;
cout<<name<<" died"<<endl;
return alive;
}
}
void takedmg(int a){
health=health-a;
}
string taunt(){
return "i, "+name+" shall defeat you hahaha";
}
int choose_wep(){
int arr[3]={wep1,wep2,wep3};
int wep=rand() % 3;
return wep;
}
string announce_turn(){
return "its "+name+"`s turn";
}
};
int main(){
weapons list[6]={weapons("iron rifle",6,1,1),weapons("energy sword",12,0.8,2),weapons("shoulder canon",45,0.25,3)
,weapons("fusion canon",9,0.9,4),weapons("fusion sword",18,0.7,5),weapons("tank mode",60,0.15,6)};
fighter optimus("optimus",1,2,3);
fighter megatron("megatron",4,5,6,330);
int i=0;
fighter& attacker=optimus;
fighter& reciever=megatron;
while (optimus.checkhealth()==true && megatron.checkhealth()==true){
if ((i%2)==0){
fighter& attacker=optimus;
fighter& reciever=megatron;
}
else{
fighter& attacker=optimus;
fighter& reciever=megatron;
}
cout<<attacker.announce_turn()<<endl;
cout<<reciever.taunt()<<endl;
int weapon=attacker.choose_wep();
cout<<"the chosen weapon is "<<list[weapon].getname()<<endl;
int hurt=list[weapon].attack();
reciever.takedmg(hurt);
}
}