-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItem.cpp
More file actions
53 lines (53 loc) · 1.53 KB
/
Item.cpp
File metadata and controls
53 lines (53 loc) · 1.53 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
#include "Item.h"
Item::Item():Object(){}
Item::Item(string name,string tag,int health,int attack,int defense):Object(name,tag){
this -> health = health;
this -> attack = attack;
this -> defense = defense;
}
bool Item::triggerEvent(Object* deal){
Player* pickup = static_cast<Player*> (deal);
if(this -> getTag() == "potion"|| this -> getTag() == "key" || this-> getTag() == "attackpotion"){
cout<<"You put it into your backpack"<<endl;
pickup->addItemtoBackpack(*this);
return true;
}
else if(this -> getTag() == "weapon" || this -> getTag() == "armor" || this -> getTag() == "shield"){
int flag = 1;
vector<Item> players = pickup->getInventory();
for(auto i : players){
if(i.getTag() == this -> getTag()){
flag = 0;
break;
}
}
if(flag == 0){
cout<<"You put it into your backpack"<<endl;
pickup->addItemtoBackpack(*this);
return true;
}
else{
cout<<"You put on "<<this -> getTag()<<" : "<<this -> getName()<<endl;
pickup->addItemtoInventory(*this);
return true;
}
}
}
int Item::getHealth(){
return health;
}
int Item::getAttack(){
return this -> attack;
}
int Item::getDefense(){
return this -> defense;
}
void Item::setHealth(int health){
this -> health = health;
}
void Item::setAttack(int attack){
this -> attack = attack;
}
void Item::setDefense(int defense){
this -> defense = defense;
}