Skip to content

Instantly share code, notes, and snippets.

@krysseltillada
Created September 10, 2015 19:31
Show Gist options
  • Save krysseltillada/ffb3d6574d32580317e1 to your computer and use it in GitHub Desktop.
Save krysseltillada/ffb3d6574d32580317e1 to your computer and use it in GitHub Desktop.
skill tree header
#pragma once
#ifndef CLASS_HEADER
#define CLASS_HEADER
#include <vector>
#include <iostream>
struct skill_info {
skill_info () = default;
skill_info (const std::string &n, const std::string &des, const int &lvl, const double &cd) :
name (n), description (des), level (lvl), cooldown (cd) { }
std::string name, description;
int level;
double cooldown;
};
class Class {
friend std::ostream &operator << (std::ostream &, const Class &);
public:
Class () = default;
Class (const std::string usr, const std::string &gdr, const int &lvl) :
username (usr), gender (gdr), level (lvl) { }
virtual void set_basic_skill (const std::string &sk, const std::string &des, const int &lvl, const double &cd) {
basic_skill.push_back (skill_info(sk, des, lvl, cd));
}
virtual ~Class () = default;
protected:
std::string username, gender;
int level;
std::vector <skill_info> basic_skill;
};
class Swordsman : public Class {
friend std::ostream &operator << (std::ostream &, const Swordsman &info);
public:
Swordsman () = default;
Swordsman (const std::string usr, const std::string &gdr, const int &lvl) :
Class (usr, gdr, lvl) { }
void set_swordsman_skill (const std::string &n, const std::string &des, const int &lvl, const double &cd) {
sw_skill.push_back (skill_info(n, des, lvl, cd));
}
protected:
std::vector <skill_info> sw_skill;
};
class Warrior final : public Swordsman {
friend std::ostream &operator << (std::ostream &os, const Warrior &);
public:
Warrior () = default;
Warrior (const std::string &usr, const std::string &gdr, const int &lvl) :
Swordsman (usr, gdr, lvl) { }
void set_warrior_skill (const std::string &s, const std::string &des, const int &lvl, const double cd) {
w_skill.push_back(skill_info(s, des, lvl, cd));
}
protected:
std::vector <skill_info> w_skill;
};
std::ostream &operator << (std::ostream &os, const Class &info) {
os << "username: " << info.username << std::endl
<< "gender: " << info.gender << std::endl
<< "level: " << info.level << std::endl;
os << "basic skill " << std::endl;
for (skill_info si : info.basic_skill) {
os << "skill name: " << si.name << std::endl
<< "description: " << si.description << std::endl
<< "level: " << si.level << std::endl
<< "cooldown: " << si.cooldown << std::endl;
}
return os;
}
std::ostream &operator << (std::ostream &os, const Swordsman &info) {
os << "username: " << info.username << std::endl
<< "gender: " << info.gender << std::endl
<< "level: " << info.level << std::endl;
os << "basic skill " << std::endl;
for (skill_info si : info.basic_skill) {
os << "skill name: " << si.name << std::endl
<< "description: " << si.description << std::endl
<< "level: " << si.level << std::endl
<< "cooldown: " << si.cooldown << std::endl;
}
os << "swordsman skill " << std::endl;
for (skill_info si : info.sw_skill) {
os << "skill name: " << si.name << std::endl
<< "description: " << si.description << std::endl
<< "level: " << si.level << std::endl
<< "cooldown: " << si.cooldown << std::endl;
}
return os;
}
std::ostream &operator << (std::ostream &os, const Warrior &info) {
os << "username: " << info.username << std::endl
<< "gender: " << info.gender << std::endl
<< "level: " << info.level << std::endl;
os << "basic skill " << std::endl;
for (skill_info si : info.basic_skill) {
os << "skill name: " << si.name << std::endl
<< "description: " << si.description << std::endl
<< "level: " << si.level << std::endl
<< "cooldown: " << si.cooldown << std::endl;
}
os << "swordsman skill " << std::endl;
for (skill_info si : info.sw_skill) {
os << "skill name: " << si.name << std::endl
<< "description: " << si.description << std::endl
<< "level: " << si.level << std::endl
<< "cooldown: " << si.cooldown << std::endl;
}
os << "warrior skill " << std::endl;
for (skill_info si : info.w_skill) {
os << "skill name: " << si.name << std::endl
<< "description: " << si.description << std::endl
<< "level: " << si.level << std::endl
<< "cooldown: " << si.cooldown << std::endl;
}
return os;
}
#endif // CLASS_HEADER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment