diff --git a/Solutions/in010210/Game Shop/Part 2/Item.cpp b/Solutions/in010210/Game Shop/Part 2/Item.cpp index 37f3dce..0652550 100644 --- a/Solutions/in010210/Game Shop/Part 2/Item.cpp +++ b/Solutions/in010210/Game Shop/Part 2/Item.cpp @@ -13,21 +13,15 @@ void Item::Describe() cout << setw(13) << "Description" << "= " << description << endl; cout << setw(13) << "Weight" << "= " << weight << endl; cout << setw(13) << "Value" << "= " << value << endl; - cout << "\n"; } Weapon::Weapon(string name, string description, int weight, int value, int damage) : damage(damage), Item(name, description, weight, value) {} -void Weapon::Describe() +void Weapon::Describe() { - cout.setf(ios::left); - cout << setw(13) << "Name" << "= " << name << endl; - cout << setw(13) << "Description" << "= " << description << endl; - cout << setw(13) << "Weight" << "= " << weight << endl; - cout << setw(13) << "Value" << "= " << value << endl; + Item::Describe(); cout << setw(13) << "Damage" << "= " << damage << endl; - cout << "\n"; } @@ -36,11 +30,6 @@ Armor::Armor(string name, string description, int weight, int value, int defense void Armor::Describe() { - cout.setf(ios::left); - cout << setw(13) << "Name" << "= " << name << endl; - cout << setw(13) << "Description" << "= " << description << endl; - cout << setw(13) << "Weight" << "= " << weight << endl; - cout << setw(13) << "Value" << "= " << value << endl; + Item::Describe(); cout << setw(13) << "Defense" << "= " << defense << endl; - cout << "\n"; } \ No newline at end of file diff --git a/Solutions/in010210/Game Shop/Part 2/Item.h b/Solutions/in010210/Game Shop/Part 2/Item.h index c1efecb..a741685 100644 --- a/Solutions/in010210/Game Shop/Part 2/Item.h +++ b/Solutions/in010210/Game Shop/Part 2/Item.h @@ -23,7 +23,7 @@ class Weapon :public Item int damage; public: Weapon(string name, string description, int weight, int value, int damage); - virtual void Describe(); + virtual void Describe() override; }; class Armor :public Item @@ -32,5 +32,5 @@ class Armor :public Item int defense; public: Armor(string name, string description, int weight, int value, int defense); - virtual void Describe(); + virtual void Describe() override; }; \ No newline at end of file diff --git a/Solutions/in010210/Game Shop/Part 2/Main.cpp b/Solutions/in010210/Game Shop/Part 2/Main.cpp index 631aaff..3996cfa 100644 --- a/Solutions/in010210/Game Shop/Part 2/Main.cpp +++ b/Solutions/in010210/Game Shop/Part 2/Main.cpp @@ -4,11 +4,12 @@ int main() { Item* item = new Weapon("Excalibur", "The legendary sword of King Arthur", 12, 1024, 24); item->Describe(); - - + item = new Armor("Steel Armor", "Protective covering made by steel", 15, 805, 18); item->Describe(); - + item = new Item("HP Potion", "Restores HP", 1, 3); item->Describe(); + + delete item; } \ No newline at end of file diff --git a/Solutions/in010210/Game Shop/Part 3/Game Shop.cpp b/Solutions/in010210/Game Shop/Part 3/Game Shop.cpp new file mode 100644 index 0000000..e54e977 --- /dev/null +++ b/Solutions/in010210/Game Shop/Part 3/Game Shop.cpp @@ -0,0 +1,60 @@ +#include "Game Shop.h" + +#include +#include + +Item::Item(string name, string description, int weight, int value) + :name(name), description(description), weight(weight), value(value) {} + +void Item::Describe() const +{ + cout.setf(ios::left); + cout << setw(13) << "Name" << "= " << name << endl; + cout << setw(13) << "Description" << "= " << description << endl; + cout << setw(13) << "Weight" << "= " << weight << endl; + cout << setw(13) << "Value" << "= " << value << endl; +} + +Weapon::Weapon(string name, string description, int weight, int value, int damage) + : damage(damage), Item(name, description, weight, value) {} + +void Weapon::Describe() const +{ + Item::Describe(); + cout << setw(13) << "Damage" << "= " << damage << endl; +} + + +Armor::Armor(string name, string description, int weight, int value, int defense) + : defense(defense), Item(name, description, weight, value) {} + +void Armor::Describe() const +{ + Item::Describe(); + cout << setw(13) << "Defense" << "= " << defense << endl; +} + +Potion::Potion(string name, string description, int weight, int value, string type, int capacity) + :Item(name, description, weight, value), type(type), capacity(capacity) {} + +void Potion::Describe() const +{ + Item::Describe(); + cout << setw(13) << "type" << "= " << type << endl; + cout << setw(13) << "capacity" << "= " << capacity << endl; +} + +Shop::Shop(string name, vector items) + :name(name), items(items) {} + +void Shop::ShowItemList() +{ + cout << "\n" << name; + cout << "\n- Item List -\n"; + + + for_each(begin(items), end(items), [](const Item* itemptr) { + itemptr->Describe(); + cout << "\n"; + }); +} \ No newline at end of file diff --git a/Solutions/in010210/Game Shop/Part 3/Game Shop.h b/Solutions/in010210/Game Shop/Part 3/Game Shop.h new file mode 100644 index 0000000..6d54bf4 --- /dev/null +++ b/Solutions/in010210/Game Shop/Part 3/Game Shop.h @@ -0,0 +1,61 @@ +#pragma once + +#include +#include +#include + +using namespace std; + +class Item; + +class Shop +{ +private: + string name; + vector items; + +public: + explicit Shop(string name, vector items); + void ShowItemList(); +}; + +class Item +{ +protected: + string name; + string description; + int weight; + int value; +public: + Item(string name, string description, int weight, int value); + virtual void Describe() const; +}; + + +class Weapon :public Item +{ +private: + int damage; +public: + Weapon(string name, string description, int weight, int value, int damage); + virtual void Describe() const override; +}; + +class Armor :public Item +{ +private: + int defense; +public: + Armor(string name, string description, int weight, int value, int defense); + virtual void Describe() const override; +}; + +class Potion :public Item +{ +private: + string type; + int capacity; +public: + Potion(string name, string description, int weight, int value, string type, int capacity); + virtual void Describe() const override; +}; \ No newline at end of file diff --git a/Solutions/in010210/Game Shop/Part 3/Main.cpp b/Solutions/in010210/Game Shop/Part 3/Main.cpp new file mode 100644 index 0000000..de4702e --- /dev/null +++ b/Solutions/in010210/Game Shop/Part 3/Main.cpp @@ -0,0 +1,35 @@ +#pragma once +#include "Game Shop.h" +#include + +int main() +{ + vector WeaponArmorShopList = { + new Weapon("Sword", "Medium DMG", 3, 10, 10), + new Armor("Cap", "Light Armor", 1, 5, 5), + new Armor("Gloves", "Light Armor", 1, 5, 5), + new Weapon("Axe", "HIgh DMG", 5, 15, 15), + new Armor("Boots", "Light Armor", 1, 5, 5) + }; + Shop* WeaponArmorShop = new Shop("\nWelcome to Weapon/Armor Shop!", WeaponArmorShopList); + + vector PotionShopList{ + new Potion("Small Mana Potion", "Recovery 50 MP", 1, 30, "Mana", 50), + new Potion("Medium Health Potion", "Recovery 200 HP", 4, 120, "Health", 200), + new Potion("Medium Mana Potion", "Recovery 100 MP", 2, 75, "Mana", 100), + new Potion("Large Health Potion", "Recovery 300 HP", 6, 200, "Health", 300) + }; + Shop* PotionShop = new Shop("\nWelcome to Potion Shop!", PotionShopList); + + int n=0; + while (n != 3) { + std::cout << "- Shop Select -\n 1. Weapon/Armor Shop\n 2. Potion Shop\n 3. Exit\n\n Select : "; + std::cin >> n; + if(n==1)WeaponArmorShop->ShowItemList(); + else if (n == 2)PotionShop->ShowItemList(); + else if (n != 3)std::cout << "\nInvalid number! Try again\n\n"; + } + + delete WeaponArmorShop; + delete PotionShop; +} \ No newline at end of file