Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Solutions/ISHNN/Game Shop/4/Armor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <iomanip>
#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;
}
16 changes: 16 additions & 0 deletions Solutions/ISHNN/Game Shop/4/Armor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once
#include <iostream>
#include "Item.h"

class Armor : public Item
{
public:
Armor(std::string, std::string, int, int, int);
~Armor();

void Describe();

private:
int defence;
};

23 changes: 23 additions & 0 deletions Solutions/ISHNN/Game Shop/4/Item.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <iomanip>
#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;
}
17 changes: 17 additions & 0 deletions Solutions/ISHNN/Game Shop/4/Item.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once
#include <iostream>

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;
};
48 changes: 48 additions & 0 deletions Solutions/ISHNN/Game Shop/4/Main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <iostream>
#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;
}
21 changes: 21 additions & 0 deletions Solutions/ISHNN/Game Shop/4/Potion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <iomanip>
#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;
}
17 changes: 17 additions & 0 deletions Solutions/ISHNN/Game Shop/4/Potion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once
#include <iostream>
#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;
};

98 changes: 98 additions & 0 deletions Solutions/ISHNN/Game Shop/4/Shop.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include <fstream>
#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;
}
}
22 changes: 22 additions & 0 deletions Solutions/ISHNN/Game Shop/4/Shop.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once
#include <iostream>
#include <Set>
#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<Item*> items;
};
17 changes: 17 additions & 0 deletions Solutions/ISHNN/Game Shop/4/Weapon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <iomanip>
#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;
}
16 changes: 16 additions & 0 deletions Solutions/ISHNN/Game Shop/4/Weapon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once
#include <iostream>
#include "Item.h"

class Weapon : public Item
{
public:
Weapon(std::string, std::string, int, int, int);
~Weapon();

void Describe();

private:
int damage;
};

5 changes: 5 additions & 0 deletions Solutions/ISHNN/Game Shop/4/equip_item.txt
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions Solutions/ISHNN/Game Shop/4/potion_item.txt
Original file line number Diff line number Diff line change
@@ -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