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
|
#include <iostream>
#include <string>
#include <map>
using namespace std;
class Item
{
public:
Item
(
const string& name,
const int stackSize,
const float weight,
const int storageSlotsUsed,
const string& description
) : mName(name),
mStackSize(stackSize),
mWeight(weight),
mStorageSlotsUsed(storageSlotsUsed),
mDescription(description)
{}
string GetName() const { return mName; }
int GetStackSize() const { return mStackSize; }
float GetWeight() const { return mWeight; }
string GetDescription() const { return mDescription; }
private:
string mName{ "Item Name" };
const int mStackSize{ 0 };
const float mWeight{ 0 };
const int mStorageSlotsUsed{ 0 };
string mDescription{ "Item Description" };
};
class Weapon : public Item
{
public:
Weapon
(
const string& name,
const int stackSize,
const float weight,
const int storageSlotsUsed,
float attackDamage,
const string& description
) :
Item{ name, stackSize, weight, storageSlotsUsed, description },
mAttackDamage(attackDamage)
{}
float GetDamage() const { return mAttackDamage; }
private:
float mAttackDamage{ 0 };
const int mStaminaUse{ 0 };
};
void Output(Item& item)
{
cout << item.GetName() << '\n';
cout << item.GetDescription() << '\n';
cout << "Weight: " << item.GetWeight() << " lbs" << '\n';
cout << "Max Stack Size: " << item.GetStackSize() << "\n\n";
}
class Player
{
public:
Player(const string& name, int stamina) : mName(name), mStamina(stamina)
{}
private:
string mName{ "Player" };
int mStamina{ 100 };
};
void Output(Weapon& weapon)
{
cout << weapon.GetName() << '\n';
cout << weapon.GetDescription() << '\n';
cout << "Damage: " << weapon.GetDamage() << '\n';
cout << "Weight: " << weapon.GetWeight() << " lbs" << '\n';
cout << "Max Stack Size: " << weapon.GetStackSize() << "\n\n";
}
class Container
{
public:
Container(const string& name, int storageSlots) : mName(name), mStorageSlots(storageSlots)
{}
void Add(Item& item, int amount)
{
mContainer.insert({ item, amount });
}
void Remove()
{
}
int GetSlotsUsedCount() const
{
return mStorageSlots;
}
string GetName() const { return mName; }
private:
string mName{ "Container Name" };
int mStorageSlots{ 0 };
map<Item, int> mContainer;
};
int main()
{
Player Hero("Hero", 100);
Container PlayerInventory("Player Inventory", 100);
Item GlowLeaf("Glow Leaf", 99, 0.1, 1, "A glowing leaf that blooms at night.");
Item WeaponRepairKit("Weapon Repair Kit", 99, 0.4, 2, "Repairs any weapon.");
Item GlowRock("Glow Rock", 99, 0.8, 1, "A strange rock that emits a continuous glow.");
Weapon Katana("Katana", 1, 3.1, 12, 65, "A blade once wielded by Samurai of ancient Japan.");
Output(GlowLeaf);
Output(WeaponRepairKit);
Output(GlowRock);
Output(Katana);
return 0;
}
|