Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Game Shop, Part 1.cpp #41

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
13 changes: 13 additions & 0 deletions Solutions/Stareat0707/Game Shop/Game Shop, Part 1/Item.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "Item.h"

Item::Item(std::string name, std::string description, int weight, int value) : name(name), description(description), weight(weight), value(value)
{
}

void Item::Describe()
{
std::cout << "Name = " << name << std::endl;
std::cout << "Description = " << description << std::endl;
std::cout << "Weight = " << weight << " lbs" << std::endl;
std::cout << "Value = " << value << " coins" << std::endl;
}
16 changes: 16 additions & 0 deletions Solutions/Stareat0707/Game Shop/Game Shop, Part 1/Item.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once
#include <iostream>
#include <string>

class Item
{
public:
Item(std::string, std::string, int, int);
void Describe();

protected:
std::string name;
std::string description;
int weight;
int value;
};
14 changes: 14 additions & 0 deletions Solutions/Stareat0707/Game Shop/Game Shop, Part 1/Main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "Item.h"

int main()
{
Item* item = new Item("Excalibur", "The legendary sword of King Arthur", 12, 1024, 24);
item->Describe();
delete item;

std::cout << std::endl;

item = new Item("Steel Armor", "Protective covering made by steel", 15, 805, 18);
item->Describe();
delete item;
}
11 changes: 11 additions & 0 deletions Solutions/Stareat0707/Game Shop/Game Shop, Part 2/Armor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "Armor.h"

Armor::Armor(std::string name, std::string description, int weight, int value, int defense) : Item(name, description, weight, value), defense(defense)
{
}

void Armor::Describe()
{
Item::Describe();
std::cout << "Defense = " << defense << std::endl;
}
13 changes: 13 additions & 0 deletions Solutions/Stareat0707/Game Shop/Game Shop, Part 2/Armor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once
#include "Item.h"

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

private:
int defense;
};
13 changes: 13 additions & 0 deletions Solutions/Stareat0707/Game Shop/Game Shop, Part 2/Item.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "Item.h"

Item::Item(std::string name, std::string description, int weight, int value) : name(name), description(description), weight(weight), value(value)
{
}

void Item::Describe()
{
std::cout << "Name = " << name << std::endl;
std::cout << "Description = " << description << std::endl;
std::cout << "Weight = " << weight << " lbs" << std::endl;
std::cout << "Value = " << value << " coins" << std::endl;
}
16 changes: 16 additions & 0 deletions Solutions/Stareat0707/Game Shop/Game Shop, Part 2/Item.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once
#include <iostream>
#include <string>

class Item
{
public:
Item(std::string, std::string, int, int);
virtual void Describe();

protected:
std::string name;
std::string description;
int weight;
int value;
};
15 changes: 15 additions & 0 deletions Solutions/Stareat0707/Game Shop/Game Shop, Part 2/Main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "Armor.h"
#include "Weapon.h"

int main()
{
Item* item = new Weapon("Excalibur", "The legendary sword of King Arthur", 12, 1024, 24);
item->Describe();
delete item;

std::cout << std::endl;

item = new Armor("Steel Armor", "Protective covering made by steel", 15, 805, 18);
item->Describe();
delete item;
}
11 changes: 11 additions & 0 deletions Solutions/Stareat0707/Game Shop/Game Shop, Part 2/Weapon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "Weapon.h"

Weapon::Weapon(std::string name, std::string description, int weight, int value, int damage) : Item(name, description, weight, value), damage(damage)
{
}

void Weapon::Describe()
{
Item::Describe();
std::cout << "Damage = " << damage << std::endl;
}
13 changes: 13 additions & 0 deletions Solutions/Stareat0707/Game Shop/Game Shop, Part 2/Weapon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once
#include "Item.h"

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

private:
int damage;
};