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
|
#include <iostream>
#include <vector>
#include <map>
#include "class_item.h"
#include "class_player.h"
enum class EQUIPMENT
{
rustySword,
crackedShield,
rustyAxe,
};
const std::map<EQUIPMENT, class_item> loot =
{
{ EQUIPMENT::rustySword, {"Rusty Sword", 2, 2} },
{ EQUIPMENT::crackedShield, {"Cracked Shield", 0, 5} },
{ EQUIPMENT::rustyAxe, {"Rusty Axe", 4, 0} },
};
class_player::class_player()
{
baseAttack = 2;
health = 10;
experience = 0;
weaponEquipped = "Fists";
weaponSlot = false;
}
void class_player::displayInventory()
{
if ( inventory.empty() )
{
std::cout << "You have nothing in your inventory." << std::endl;
}
else
{
std::cout << "You have " << inventory.size() << " items in your inventory." << std::endl;
for ( int x = 0; x < inventory.size(); x++ )
{
std::cout << inventory[x].getName();
if ( inventory[x].getName() == weaponEquipped )
{
std::cout << " [Equipped]" << std::endl;
}
else
{
std::cout << std::endl;
}
}
}
}
void class_player::displayHUD()
{
std::cout << "Attack " << getAttack() << " | Health " << getHealth() << std::endl;
}
int class_player::getAttack()
{
return baseAttack + weaponAttack;
}
int class_player::getHealth()
{
return health;
}
bool class_player::isWeaponSlotAvailable()
{
if ( weaponSlot )
{
return false;
}
else
{
return true;
}
}
void class_player::addItem(const class_item& item)
{
inventory.push_back(item);
}
void class_player::removeItem(const std::string item)
{
for ( int x = 0; x < inventory.size(); x++ )
{
if ( inventory[x].getName() == item )
{
inventory.erase(inventory.begin() + x);
}
}
}
void class_player::equipItem(const std::string item)
{
for ( int x = 0; x < inventory.size(); x++ )
{
if (weaponSlot)
{
weaponSlot = false;
for ( int x = 0; x < inventory.size(); x++ )
{
if ( inventory[x].getName() == weaponEquipped )
{
weaponAttack = weaponAttack - inventory[x].getDamage();
weaponEquipped = "Fists";
}
}
if (inventory[x].getName() == item)
{
weaponAttack = weaponAttack + inventory[x].getDamage();
}
}
}
}
|