diff --git a/Solutions/ISHNN/Game Shop/4/Armor.cpp b/Solutions/ISHNN/Game Shop/4/Armor.cpp new file mode 100644 index 0000000..720c7e5 --- /dev/null +++ b/Solutions/ISHNN/Game Shop/4/Armor.cpp @@ -0,0 +1,17 @@ +#include +#include "Armor.h" + +Armor::Armor(std::string name, std::string descripition, int wight, int value, int defence) :Item(name, descripition, wight, value) +{ + Armor::defence = defence; +} + + +Armor::~Armor() +{ +} + +void Armor::Describe() { + Item::Describe(); + std::cout << std::left << std::setw(13) << "Defence" << " = " << defence << std::endl; +} diff --git a/Solutions/ISHNN/Game Shop/4/Armor.h b/Solutions/ISHNN/Game Shop/4/Armor.h new file mode 100644 index 0000000..213ebe1 --- /dev/null +++ b/Solutions/ISHNN/Game Shop/4/Armor.h @@ -0,0 +1,16 @@ +#pragma once +#include +#include "Item.h" + +class Armor : public Item +{ +public: + Armor(std::string, std::string, int, int, int); + ~Armor(); + + void Describe(); + +private: + int defence; +}; + diff --git a/Solutions/ISHNN/Game Shop/4/Item.cpp b/Solutions/ISHNN/Game Shop/4/Item.cpp new file mode 100644 index 0000000..ef47182 --- /dev/null +++ b/Solutions/ISHNN/Game Shop/4/Item.cpp @@ -0,0 +1,23 @@ +#include +#include "Item.h" + +Item::Item(std::string name, std::string descripition, int wight, int value) +{ + Item::name = name; + Item::descripition = descripition; + Item::wight = wight; + Item::value = value; +} + + +Item::~Item() +{ + +} + +void Item::Describe() { + std::cout << std::left << std::setw(13) << "Name" << " = " << name.data() << std::endl; + std::cout << std::left << std::setw(13) << "Description" << " = " << descripition.data() << std::endl; + std::cout << std::left << std::setw(13) << "Weight" << " = " << wight << " lbs" << std::endl; + std::cout << std::left << std::setw(13) << "Value" << " = " << value << " gold coins" << std::endl; +} \ No newline at end of file diff --git a/Solutions/ISHNN/Game Shop/4/Item.h b/Solutions/ISHNN/Game Shop/4/Item.h new file mode 100644 index 0000000..61c3188 --- /dev/null +++ b/Solutions/ISHNN/Game Shop/4/Item.h @@ -0,0 +1,17 @@ +#pragma once +#include + +class Item +{ +public: + Item(std::string, std::string, int, int); + ~Item(); + + virtual void Describe(); + +private: + std::string name; + std::string descripition; + int wight; + int value; +}; \ No newline at end of file diff --git a/Solutions/ISHNN/Game Shop/4/Main.cpp b/Solutions/ISHNN/Game Shop/4/Main.cpp new file mode 100644 index 0000000..643b401 --- /dev/null +++ b/Solutions/ISHNN/Game Shop/4/Main.cpp @@ -0,0 +1,48 @@ +#include +#include "Item.h" +#include "Weapon.h" +#include "Armor.h" +#include "Potion.h" +#include "Shop.h" + +int Selection_Main(); //¸Þ´º ¼±ÅÃâÀ» Ãâ·ÂÇÏ´Â ÇÔ¼ö + +int main() { + Shop WAshop("Weapon/Armor Shop", "equip_item.txt"); + Shop Pshop("Potion Shop", "potion_item.txt"); + while (true) { + bool exit = false; + + switch (Selection_Main()) + { + case 1: { + WAshop.LoadShop(); break; + } + case 2: { + Pshop.LoadShop(); break; + } + case 3: { + exit = true; break; + } + default: + std::cout << "Invaild number! Try again" << std::endl; + } + + if (exit) break; + } +} + +int Selection_Main() { + int select; + std::cout << "- Shop Select -" << std::endl; + std::cout << " 1. Weapon/Armor Shop" << std::endl; + std::cout << " 2. Potion Shop" << std::endl; + std::cout << " 3. Exit" << std::endl; + std::cout << std::endl; + + std::cout << "Select : "; + std::cin >> select; + std::cout << std::endl; + + return select; +} \ No newline at end of file diff --git a/Solutions/ISHNN/Game Shop/4/Potion.cpp b/Solutions/ISHNN/Game Shop/4/Potion.cpp new file mode 100644 index 0000000..7d66fa0 --- /dev/null +++ b/Solutions/ISHNN/Game Shop/4/Potion.cpp @@ -0,0 +1,21 @@ +#include +#include "Potion.h" + +Potion::Potion(std::string name, std::string descripition, int wight, int value, std::string type, int capacity) :Item(name, descripition, wight, value) +{ + + Potion::type = type; + Potion::capacity = capacity; +} + + +Potion::~Potion() +{ +} + +void Potion::Describe() { + Item::Describe(); + + std::cout << std::left << std::setw(13) << "Type" << " = " << type.data() << std::endl; + std::cout << std::left << std::setw(13) << "Capacity" << " = " << capacity << std::endl; +} diff --git a/Solutions/ISHNN/Game Shop/4/Potion.h b/Solutions/ISHNN/Game Shop/4/Potion.h new file mode 100644 index 0000000..706079c --- /dev/null +++ b/Solutions/ISHNN/Game Shop/4/Potion.h @@ -0,0 +1,17 @@ +#pragma once +#include +#include "Item.h" + +class Potion : public Item +{ +public: + Potion(std::string, std::string, int, int, std::string, int); + ~Potion(); + + void Describe(); + +private: + std::string type; + int capacity; +}; + diff --git a/Solutions/ISHNN/Game Shop/4/Shop.cpp b/Solutions/ISHNN/Game Shop/4/Shop.cpp new file mode 100644 index 0000000..57f26b9 --- /dev/null +++ b/Solutions/ISHNN/Game Shop/4/Shop.cpp @@ -0,0 +1,98 @@ +#include +#include "Shop.h" + +#include "Weapon.h" +#include "Armor.h" +#include "Potion.h" + +Shop::Shop(std::string name, std::string filename){ + Shop::name = name; + Shop::filename = filename; + + Shop::ReadDataFromFile(); +} + +Shop::~Shop() +{ +} + +void Shop::ReadDataFromFile() { + char input_buf[100]; + + std::ifstream inFile(Shop::filename); + + int item_count = 0; + + while (!inFile.eof()) { + inFile.getline(input_buf, 100); + + std::string tokens[7]; + int tokenNum = 0; + bool isString = false; + + for (char r : input_buf) { + + if (r == ',') { + tokenNum++; continue; + }//ºÐ±â(,)ÀÏ °æ¿ì ´ÙÀ½ ÅäÅ«À¸·Î À̵¿ + else if (r == '\"') { + isString = !isString; continue; + }//¹®Àå("")ÀÇ ½ÃÀÛ¿¡¼­ true, ³¡¿¡¼­ false + + else if (r != ' ' || isString) { + tokens[tokenNum] += r; + }//°ø¹éÀ» »« °ªÀÎ °æ¿ì ¶Ç´Â ¹®ÀåÀÏ °æ¿ì ´ëÀÔ + } + + if (!tokens[0].compare("Weapon")) { + Shop::items.insert(new Weapon(tokens[1], tokens[2], atoi(tokens[3].c_str()), atoi(tokens[4].c_str()), atoi(tokens[5].c_str()))); + } + else if (!tokens[0].compare("Armor")) { + Shop::items.insert(new Armor(tokens[1], tokens[2], atoi(tokens[3].c_str()), atoi(tokens[4].c_str()), atoi(tokens[5].c_str()))); + } + else if (!tokens[0].compare("Potion")) { + Shop::items.insert(new Potion (tokens[1], tokens[2], atoi(tokens[3].c_str()), atoi(tokens[4].c_str()),tokens[5], atoi(tokens[6].c_str()) )); + } + } + + inFile.close(); +} + +void Shop::LoadShop() { + while (true) { + std::cout << "Welcome to " << Shop::name.data() << "!" << std::endl; + std::cout << "-----------------------------" << std::endl; + switch (Selection_Shop()) + { + case 1: { + PrintShop(); break; + } + case 2: { + return; + } + default: + std::cout << "Invaild number! Try again" << std::endl; + } + } +} + +int Shop::Selection_Shop() { + int select; + std::cout << "- Shop Select -" << std::endl; + std::cout << "1. Show Item List" << std::endl; + std::cout << "2. Exit" << std::endl; + std::cout << std::endl; + + std::cout << "Select : "; + std::cin >> select; + std::cout << std::endl; + + return select; +} + +void Shop::PrintShop() { + for (Item* item : Shop::items) { + item->Describe(); + std::cout << std::endl; + } +} diff --git a/Solutions/ISHNN/Game Shop/4/Shop.h b/Solutions/ISHNN/Game Shop/4/Shop.h new file mode 100644 index 0000000..c70326f --- /dev/null +++ b/Solutions/ISHNN/Game Shop/4/Shop.h @@ -0,0 +1,22 @@ +#pragma once +#include +#include +#include "Item.h" + +class Shop +{ +public: + Shop(std::string, std::string); + ~Shop(); + + void ReadDataFromFile(); + void LoadShop(); + + void PrintShop(); + int Selection_Shop(); + +private: + std::string name; + std::string filename; + std::set items; +}; \ No newline at end of file diff --git a/Solutions/ISHNN/Game Shop/4/Weapon.cpp b/Solutions/ISHNN/Game Shop/4/Weapon.cpp new file mode 100644 index 0000000..646969d --- /dev/null +++ b/Solutions/ISHNN/Game Shop/4/Weapon.cpp @@ -0,0 +1,17 @@ +#include +#include "Weapon.h" + +Weapon::Weapon(std::string name, std::string descripition, int wight, int value, int damage):Item(name,descripition,wight,value) +{ + Weapon::damage = damage; +} + + +Weapon::~Weapon() +{ +} + +void Weapon::Describe() { + Item::Describe(); + std::cout << std::left << std::setw(13) << "Damage" << " = " << damage << std::endl; +} \ No newline at end of file diff --git a/Solutions/ISHNN/Game Shop/4/Weapon.h b/Solutions/ISHNN/Game Shop/4/Weapon.h new file mode 100644 index 0000000..7dbc873 --- /dev/null +++ b/Solutions/ISHNN/Game Shop/4/Weapon.h @@ -0,0 +1,16 @@ +#pragma once +#include +#include "Item.h" + +class Weapon : public Item +{ +public: + Weapon(std::string, std::string, int, int, int); + ~Weapon(); + + void Describe(); + +private: + int damage; +}; + diff --git a/Solutions/ISHNN/Game Shop/4/equip_item.txt b/Solutions/ISHNN/Game Shop/4/equip_item.txt new file mode 100644 index 0000000..168a930 --- /dev/null +++ b/Solutions/ISHNN/Game Shop/4/equip_item.txt @@ -0,0 +1,5 @@ +"Weapon", "Sword", "Medium DMG", 3, 10, 10 +"Armor", "Cap", "Light Armor", 1, 5, 5 +"Armor", "Gloves", "Light Armor", 1, 5, 5 +"Weapon", "Axe", "High DMG", 5, 15, 15 +"Armor", "Boots", "Light Armor", 1, 5, 5 \ No newline at end of file diff --git a/Solutions/ISHNN/Game Shop/4/potion_item.txt b/Solutions/ISHNN/Game Shop/4/potion_item.txt new file mode 100644 index 0000000..30a9c21 --- /dev/null +++ b/Solutions/ISHNN/Game Shop/4/potion_item.txt @@ -0,0 +1,5 @@ +"Potion", "Small Health Potion", "Recovery 100 HP", 2, 5, "Health", 100 +"Potion", "Small Mana Potion", "Recovery 50 MP", 1, 30, "Mana", 50 +"Potion", "Medium Health Potion", "Recovery 200 HP", 4, 120, "Health", 200 +"Potion", "Medium Mana Potion", "Recovery 100 MP", 2, 75, "Mana", 100 +"Potion", "Large Health Potion", "Recovery 300 HP", 6, 200, "Health", 300 \ No newline at end of file