1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#ifndef ITEM_H
#define ITEM_H
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
using namespace std;
class BaseItem {
private:
string name;
public:
enum ItemType {
IT_NONE = 0,
IT_INVENTORY = 1,
IT_WEAPON = 2,
IT_ARMOR = 3
};
BaseItem(const string &n) : name(n) { }
const string &getName() const { return name; }
virtual bool isItemType(ItemType t) const = 0;
};
class InventoryItem : public BaseItem {
protected:
int strRequired;
const int weight;
public:
InventoryItem(const string &n, int w) : BaseItem(n), weight(w) { }
virtual bool isItemType(ItemType t) const { return ((t == ItemType::IT_INVENTORY) != 0); }
int getWeight() const { return weight; }
};
class Weapon : public BaseItem {
protected:
int damage;
int strRequired;
public:
Weapon(const string &n, int d, int str) :
BaseItem(n), damage(d), strRequired(str) { }
Weapon(const string &n, int d) :
BaseItem(n), damage(d), strRequired(0) { }
virtual bool isItemType(ItemType t) const { return ((t == ItemType::IT_WEAPON) != 0); }
int getDamage() const { return damage; }
int getStr() const { return strRequired; }
};
class Armor : public BaseItem
{
protected:
int defense;
int strRequired;
public:
Armor(const string &n, int d, int str) :
BaseItem(n), defense(d), strRequired(str) { }
Armor(const string &n, int d) :
BaseItem(n), defense(d), strRequired(0) { }
virtual bool isItemType(ItemType t) const { return ((t == ItemType::IT_ARMOR) != 0); }
int getDefense() const { return defense; }
int getStr() const { return strRequired; }
};
#endif
|