|
@ -3,6 +3,8 @@ |
|
|
|
|
|
|
|
|
#include "character.hpp"
|
|
|
#include "character.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
#include "string.h"
|
|
|
|
|
|
|
|
|
class Player : public Character |
|
|
class Player : public Character |
|
|
{ |
|
|
{ |
|
|
protected: |
|
|
protected: |
|
@ -46,6 +48,36 @@ class Player : public Character |
|
|
|
|
|
|
|
|
xp -= level * level; |
|
|
xp -= level * level; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int generateCode(char *dst) |
|
|
|
|
|
{ |
|
|
|
|
|
return sprintf(dst, |
|
|
|
|
|
"PlayerName:%15s;PlayerHp:%d;PlayerAtt:%d;PlayerDef:%d;PlayerLvl:%d;PlayerExp:%d;", |
|
|
|
|
|
this->name, this->hp, this->att, this->def, this->level, this->xp); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Player *loadCode(char *dst) |
|
|
|
|
|
{ |
|
|
|
|
|
char name[16]; |
|
|
|
|
|
int hp; |
|
|
|
|
|
int att; |
|
|
|
|
|
int def; |
|
|
|
|
|
int lvl; |
|
|
|
|
|
int exp; |
|
|
|
|
|
|
|
|
|
|
|
int result = sscanf(dst, |
|
|
|
|
|
"PlayerName:%15s;PlayerAtt:%d;PlayerDef:%d;PlayerLvl:%d;PlayerExp:%d;", |
|
|
|
|
|
name, &hp, &att, &def, &lvl, &exp); |
|
|
|
|
|
|
|
|
|
|
|
if (result == 5) |
|
|
|
|
|
{ |
|
|
|
|
|
return new Player(name, hp, att, def, lvl, exp); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
return nullptr; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
#endif
|
|
|
#endif
|