Skip to content

Commit

Permalink
Add sell function, add remove_item, add itemType to all items
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanw02 committed Nov 25, 2021
1 parent f795cac commit 3b77099
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 66 deletions.
6 changes: 6 additions & 0 deletions Armor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Armor : public Item
{
protected:
int defense;
string itemType;
public:
Armor(){}
int get_sell_price(){return sell_price;}
Expand All @@ -29,6 +30,7 @@ class ByteArmor : public Armor
name = "ByteArmor";
description = "Armor made of a byte of code. Probably too thin to be proper armor but its better than nothing!";
defense = 5;
itemType = "Armor";
}

};
Expand All @@ -42,6 +44,7 @@ class KiloArmor : public Armor
name = "KiloArmor";
description = "Armor made of a kilobyte of code. This weighs a kilo! You'll definitely gain strength carrying this!";
defense = 10;
itemType = "Armor";
}

};
Expand All @@ -55,6 +58,7 @@ class MegaArmor : public Armor
name = "MegaArmor";
description = "Armor made of a megabyte of code. Being able to shoot and change weapons like MegaMan not included";
defense = 15;
itemType = "Armor";
}

};
Expand All @@ -68,6 +72,7 @@ class GigaArmor : public Armor
name = "GigaArmor";
description = "Armor made of a gigabyte of code. Might give giga defense physically, but it'll be a giga dent on your money";
defense = 20;
itemType = "Armor";
}

};
Expand All @@ -81,6 +86,7 @@ class TeraArmor : public Armor
name = "TeraArmor";
description = "Legendary armor made of a terabyte of code. The best of the best armor around the interface, but as it is the best, only a few exist due to the immense work for its creation.";
defense = 25;
itemType = "Armor";
}

};
Expand Down
11 changes: 11 additions & 0 deletions Item.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,22 @@ class Item
{
protected:
int sell_price;
string itemType;
string name;
string description;
public:

string get_name() {
return this->name;
}

string get_item_type() {
return this->itemType;
}

virtual void check_stats() = 0;
virtual int get_sell_price() = 0;

};

#endif
2 changes: 2 additions & 0 deletions Potion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Potion : public Item
protected:
int alter;
string type;
string itemType;
public:
Potion(){}
int get_sell_price(){return sell_price;}
Expand All @@ -31,6 +32,7 @@ class HealthPotion : public Potion
description = "A nice drink filled to the brim with dihydrogen monoxide or as you people call it, water. It'll replenish you well.";
type = "Health";
alter = 15;
itemType = "Potion";
}

};
Expand Down
4 changes: 4 additions & 0 deletions Weapon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class KiloWeapon : public Weapon
name = "KiloWeapon";
description = "Weapon made of a kilobyte of code. This'll definitely make enemies shed a kilo!";
attack = 10;
itemType = "Weapon";
}

};
Expand All @@ -55,6 +56,7 @@ class MegaWeapon : public Weapon
name = "MegaWeapon";
description = "Weapon made of a megabyte of code. It has a mega personality to go along with its mega size";
attack = 15;
itemType = "Weapon";
}

};
Expand All @@ -68,6 +70,7 @@ class GigaWeapon : public Weapon
name = "GigaWeapon";
description = "Weapon made of a gigabyte of code. This giga-hurts, well for the victim on the sharp side anyways.";
attack = 20;
itemType = "Weapon";
}

};
Expand All @@ -81,6 +84,7 @@ class TeraWeapon : public Weapon
name = "TeraWeapon";
description = "Legendary weapon infused with a terabyte of code. The pinnacle of weapons that code can make. Trust me we tried to make a better weapon, but we don't have the storage for it...";
attack = 25;
itemType = "Weapon";
}

};
Expand Down
197 changes: 134 additions & 63 deletions player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,125 +10,196 @@
#include "Potion.hpp"
#include "skillset.hpp"
#include <vector>
#include <typeinfo>
#include <algorithm>

using namespace std;

class Player : public Character
{
protected:
//0: Weapon, 1: Armor, 2: Potion
//Equipped item will be in index 0 for each vector
vector<vector<Item*>> inventory = vector<vector<Item*>>(3, vector<Item*>());
protected:
// 0: Weapon, 1: Armor, 2: Potion
// Equipped item will be in index 0 for each vector
vector<vector<Item *>> inventory = vector<vector<Item *>>(3, vector<Item *>());
int money = 0;
Weapon* currentWeapon = nullptr;
Armor* currentArmor = nullptr;
SkillSet* mainSkill = nullptr;
SkillSet* comboSkill = nullptr;

public:
Weapon *currentWeapon = nullptr;
Armor *currentArmor = nullptr;
SkillSet *mainSkill = nullptr;
SkillSet *comboSkill = nullptr;

public:
Player(){};
~Player(){};

void attack(Character* opponent)
void attack(Character *opponent)
{
int damageDealt = this->get_power() - opponent->get_defense();
if (damageDealt < 0)
{
damageDealt = 0;
}
//opponent->set_health(damageDealt);
int damageDealt = this->get_power() - opponent->get_defense();
if (damageDealt < 0)
{
damageDealt = 0;
}
// opponent->set_health(damageDealt);
}

void check_stats() {
cout << "-------------------------------------------------------" << endl;
cout << "Player stats: " << endl;
cout << "Health: " << this->get_health() << endl;
cout << "Power: " << this->get_power() << endl;
cout << "Defense: " << this->get_defense() << endl;
cout << "Speed: " << this->get_defense() << endl;
cout << "-------------------------------------------------------" << endl;
cout << "Item stats: " << endl;
if(this->currentWeapon != nullptr) this->currentWeapon->check_stats();
if(this->currentArmor != nullptr) this->currentArmor->check_stats();
for(unsigned i = 0; i < this->inventory.at(2).size(); i++) {
this->inventory.at(2).at(i)->check_stats();
}
cout << "-------------------------------------------------------" << endl;
void check_stats()
{
cout << "-------------------------------------------------------" << endl;
cout << "Player stats: " << endl;
cout << "Health: " << this->get_health() << endl;
cout << "Power: " << this->get_power() << endl;
cout << "Defense: " << this->get_defense() << endl;
cout << "Speed: " << this->get_defense() << endl;
cout << "-------------------------------------------------------" << endl;
cout << "Item stats: " << endl;
if (this->currentWeapon != nullptr)
this->currentWeapon->check_stats();
cout << endl;
if (this->currentArmor != nullptr)
this->currentArmor->check_stats();
cout << endl;
for (unsigned i = 0; i < this->inventory.at(2).size(); i++)
{
this->inventory.at(2).at(i)->check_stats();
cout << endl;
}
cout << "-------------------------------------------------------" << endl;
}

void add_item(Item* item, int price) {
if(this->money < price) {
cout << "You don't have enough money to purchase this item." << endl << endl;
void add_item(Item *item, int price)
{
if (this->money < price)
{
cout << "You don't have enough money to purchase this item." << endl
<< endl;
return;
}

this->money -= price;

string itemType = typeid(item).name();
string itemType = item->get_item_type();

if(itemType == "Weapon") {
if (itemType == "Weapon")
{
this->inventory.at(0).push_back(item);
}else if(itemType == "Armor") {
}
else if (itemType == "Armor")
{
this->inventory.at(1).push_back(item);
}else{
}
else
{
this->inventory.at(2).push_back(item);
}

cout << item->get_name() << " purchased successfully" << endl;
cout << "Your new balance is " << this->money << endl << endl;
cout << "Your new balance is " << this->money << endl
<< endl;
}

void remove_item(Item *item, int price)
{
string itemType = item->get_item_type();

if (itemType == "Weapon")
{
vector<Item*>::iterator it = find(this->inventory.at(0).begin(), this->inventory.at(0).end(), item);
if(it != this->inventory.at(0).end()) {
this->inventory.at(0).erase(it);
this->money += price;
}
}
else if (itemType == "Armor")
{
vector<Item*>::iterator it = find(this->inventory.at(1).begin(), this->inventory.at(0).end(), item);
if(it != this->inventory.at(1).end()) {
this->inventory.at(1).erase(it);
this->money += price;
}
}
else
{
vector<Item*>::iterator it = find(this->inventory.at(2).begin(), this->inventory.at(0).end(), item);
if(it != this->inventory.at(2).end()) {
this->inventory.at(2).erase(it);
this->money += price;
}
}

cout << item->get_name() << " sold successfully" << endl;
delete item;
cout << "Your new balance is " << this->money << endl
<< endl;
}


void display_inventory() {
for(unsigned i = 0; i < this->inventory.size(); i++) {
for(unsigned j = 0; j < this->inventory.at(i).size(); j++) {
cout << this->inventory.at(i).at(j)->get_name() << endl;
}
}
}

int get_money() {
vector<Item*> get_inventory() {
vector<Item*> temp;
for(unsigned i = 0; i < this->inventory.size(); i++) {
for(unsigned j = 0; j < this->inventory.at(i).size(); j++) {
temp.push_back(this->inventory.at(i).at(j));
}
}

return temp;

}

int get_money()
{
return this->money;
}
};

class Defender : public Player
{
public:
public:
Defender()
{
health = 25;
power = 5;
defense = 7;
speed = 3;
mainSkill = new ShieldBash();
comboSkill = new ComboSkill(new ShieldBash(), new Rebuild());
health = 25;
power = 5;
defense = 7;
speed = 3;
mainSkill = new ShieldBash();
comboSkill = new ComboSkill(new ShieldBash(), new Rebuild());
}

~Defender();
};

class Cleaner : public Player
{
public:
public:
Cleaner()
{
health = 25;
power = 8;
defense = 3;
speed = 7;
mainSkill = new CleanSweep();
comboSkill = new ComboSkill(new CleanSweep(), new ShieldBash());
health = 25;
power = 8;
defense = 3;
speed = 7;
mainSkill = new CleanSweep();
comboSkill = new ComboSkill(new CleanSweep(), new ShieldBash());
}

~Cleaner();
};

class Firewall : public Player
{
public:
public:
Firewall()
{
health = 35;
power = 5;
defense = 5;
speed = 5;
mainSkill = new Rebuild();
comboSkill = new ComboSkill(new Rebuild(), new CleanSweep());
health = 35;
power = 5;
defense = 5;
speed = 5;
mainSkill = new Rebuild();
comboSkill = new ComboSkill(new Rebuild(), new CleanSweep());
}

~Firewall();
Expand Down
Loading

0 comments on commit 3b77099

Please sign in to comment.