Created
November 17, 2012 18:53
-
-
Save zachlatta/4098820 to your computer and use it in GitHub Desktop.
Character Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "../Header/Character.h" | |
#include <iostream> | |
#include <fstream> | |
/******************** | |
* PRIVATE METHODS * | |
********************/ | |
void Character::setExperience(int experience) | |
{ | |
this->experience = experience; | |
} | |
/******************* | |
* PUBLIC METHODS * | |
*******************/ | |
std::string getName() | |
{ | |
return name; | |
} | |
std::string getRace() | |
{ | |
return race; | |
} | |
int Character::getExperience() | |
{ | |
return experience; | |
} | |
int Character::getLevel() | |
{ | |
// TODO: Add logic to calculate level from experience | |
return 0; | |
} | |
void Character::addExperience(int experience) | |
{ | |
this->experience = experience; | |
} | |
void Character::save() | |
{ | |
std::ofstream saveFile; | |
saveFile.open("save.dat"); | |
// Writes data from class into file | |
saveFile << experience << std::endl; | |
saveFile.close(); | |
} | |
void Character::load() | |
{ | |
std::ifstream saveFile; | |
std::string buffer; | |
saveFile.open("save.dat", std::ios::in); | |
// Reads data from file into class | |
getline(saveFile, buffer); | |
experience = atoi(buffer.c_str()); | |
saveFile.close(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#ifndef CHARACTER_H | |
#define CHARACTER_H | |
class Character | |
{ | |
private: | |
std::string name; | |
std::string race; | |
int experience; | |
void setExperience(int); | |
public: | |
std::string getName(); | |
std::string getRace(); | |
int getExperience(); | |
int getLevel(); | |
void addExperience(int); | |
void save(); | |
void load(); | |
}; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment