From aab8a66bec58b49445671614f5252fe17598b74b Mon Sep 17 00:00:00 2001 From: Ki-Hin Date: Sun, 28 May 2017 22:15:45 +0900 Subject: [PATCH 1/4] Edit Game Shop --- Solutions/in010210/Game Shop/Part 2/Item.cpp | 15 ++------------- Solutions/in010210/Game Shop/Part 2/Main.cpp | 7 ++++--- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/Solutions/in010210/Game Shop/Part 2/Item.cpp b/Solutions/in010210/Game Shop/Part 2/Item.cpp index 37f3dce..f8e4509 100644 --- a/Solutions/in010210/Game Shop/Part 2/Item.cpp +++ b/Solutions/in010210/Game Shop/Part 2/Item.cpp @@ -13,7 +13,6 @@ 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) @@ -21,13 +20,8 @@ Weapon::Weapon(string name, string description, int weight, int value, int damag 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/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 From e2310aa573923f8057f6cf9877491a194df84aec Mon Sep 17 00:00:00 2001 From: Ki-Hin Date: Mon, 29 May 2017 11:37:30 +0900 Subject: [PATCH 2/4] =?UTF-8?q?Edit=20=EC=83=9D=EC=84=B1=EC=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Solutions/in010210/Game Shop/Part 2/Item.cpp | 8 ++++---- Solutions/in010210/Game Shop/Part 2/Item.h | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Solutions/in010210/Game Shop/Part 2/Item.cpp b/Solutions/in010210/Game Shop/Part 2/Item.cpp index f8e4509..75b641d 100644 --- a/Solutions/in010210/Game Shop/Part 2/Item.cpp +++ b/Solutions/in010210/Game Shop/Part 2/Item.cpp @@ -3,7 +3,7 @@ #include #include -Item::Item(string name, string description, int weight, int value) +Item::Item(string& name, string& description, int weight, int value) :name(name), description(description), weight(weight), value(value) {} void Item::Describe() @@ -15,17 +15,17 @@ void Item::Describe() cout << setw(13) << "Value" << "= " << value << endl; } -Weapon::Weapon(string name, string description, int weight, int value, int damage) +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() { Item::Describe(); cout << setw(13) << "Damage" << "= " << damage << endl; } -Armor::Armor(string name, string description, int weight, int value, int defense) +Armor::Armor(string& name, string& description, int weight, int value, int defense) : defense(defense), Item(name, description, weight, value) {} void Armor::Describe() diff --git a/Solutions/in010210/Game Shop/Part 2/Item.h b/Solutions/in010210/Game Shop/Part 2/Item.h index c1efecb..74bd1af 100644 --- a/Solutions/in010210/Game Shop/Part 2/Item.h +++ b/Solutions/in010210/Game Shop/Part 2/Item.h @@ -12,7 +12,7 @@ class Item int weight; int value; public: - Item(string name, string description, int weight, int value); + Item(string& name, string& description, int weight, int value); virtual void Describe(); }; @@ -22,8 +22,8 @@ class Weapon :public Item private: int damage; public: - Weapon(string name, string description, int weight, int value, int damage); - virtual void Describe(); + Weapon(string& name, string& description, int weight, int value, int damage); + virtual void Describe() override; }; class Armor :public Item @@ -31,6 +31,6 @@ class Armor :public Item private: int defense; public: - Armor(string name, string description, int weight, int value, int defense); - virtual void Describe(); + Armor(string& name, string& description, int weight, int value, int defense); + virtual void Describe() override; }; \ No newline at end of file From 501153778cdbaccaa763b3a88c01cdbfd87481b5 Mon Sep 17 00:00:00 2001 From: Ki-Hin Date: Tue, 30 May 2017 22:45:33 +0900 Subject: [PATCH 3/4] Fix bug --- Solutions/in010210/Game Shop/Part 2/Item.cpp | 6 +++--- Solutions/in010210/Game Shop/Part 2/Item.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Solutions/in010210/Game Shop/Part 2/Item.cpp b/Solutions/in010210/Game Shop/Part 2/Item.cpp index 75b641d..0652550 100644 --- a/Solutions/in010210/Game Shop/Part 2/Item.cpp +++ b/Solutions/in010210/Game Shop/Part 2/Item.cpp @@ -3,7 +3,7 @@ #include #include -Item::Item(string& name, string& description, int weight, int value) +Item::Item(string name, string description, int weight, int value) :name(name), description(description), weight(weight), value(value) {} void Item::Describe() @@ -15,7 +15,7 @@ void Item::Describe() cout << setw(13) << "Value" << "= " << value << endl; } -Weapon::Weapon(string& name, string& description, int weight, int value, int damage) +Weapon::Weapon(string name, string description, int weight, int value, int damage) : damage(damage), Item(name, description, weight, value) {} void Weapon::Describe() @@ -25,7 +25,7 @@ void Weapon::Describe() } -Armor::Armor(string& name, string& description, int weight, int value, int defense) +Armor::Armor(string name, string description, int weight, int value, int defense) : defense(defense), Item(name, description, weight, value) {} void Armor::Describe() diff --git a/Solutions/in010210/Game Shop/Part 2/Item.h b/Solutions/in010210/Game Shop/Part 2/Item.h index 74bd1af..a741685 100644 --- a/Solutions/in010210/Game Shop/Part 2/Item.h +++ b/Solutions/in010210/Game Shop/Part 2/Item.h @@ -12,7 +12,7 @@ class Item int weight; int value; public: - Item(string& name, string& description, int weight, int value); + Item(string name, string description, int weight, int value); virtual void Describe(); }; @@ -22,7 +22,7 @@ class Weapon :public Item private: int damage; public: - Weapon(string& name, string& description, int weight, int value, int damage); + Weapon(string name, string description, int weight, int value, int damage); virtual void Describe() override; }; @@ -31,6 +31,6 @@ class Armor :public Item private: int defense; public: - Armor(string& name, string& description, int weight, int value, int defense); + Armor(string name, string description, int weight, int value, int defense); virtual void Describe() override; }; \ No newline at end of file From 49dad4df95fc9a3a390f0d7dabbb2fe914d44b03 Mon Sep 17 00:00:00 2001 From: Ki-Hin Date: Tue, 18 Jul 2017 20:06:28 +0900 Subject: [PATCH 4/4] Complete Game Shop Part 3 --- .../in010210/Game Shop/Part 3/Game Shop.cpp | 60 ++++++++++++++++++ .../in010210/Game Shop/Part 3/Game Shop.h | 61 +++++++++++++++++++ Solutions/in010210/Game Shop/Part 3/Main.cpp | 35 +++++++++++ 3 files changed, 156 insertions(+) create mode 100644 Solutions/in010210/Game Shop/Part 3/Game Shop.cpp create mode 100644 Solutions/in010210/Game Shop/Part 3/Game Shop.h create mode 100644 Solutions/in010210/Game Shop/Part 3/Main.cpp 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