| @ -0,0 +1,57 @@ | |||||
| #ifndef _2EASY4ME_CHARACTER_H_ | |||||
| #define _2EASY4ME_CHARACTER_H_ | |||||
| #include <cstring> | |||||
| class Character | |||||
| { | |||||
| protected: | |||||
| char name[16]; | |||||
| int hp; | |||||
| int att; | |||||
| int def; | |||||
| public: | |||||
| Character(char *name) | |||||
| { | |||||
| strncpy(this->name, name, sizeof(this->name)); | |||||
| this->hp = 100; | |||||
| this->att = 10; | |||||
| this->def = 5; | |||||
| } | |||||
| Character(char *name, int hp, int att, int def) | |||||
| { | |||||
| strncpy(this->name, name, sizeof(this->name)); | |||||
| this->hp = hp; | |||||
| this->att = att; | |||||
| this->def = def; | |||||
| } | |||||
| bool checkDied() | |||||
| { | |||||
| return hp <= 0; | |||||
| } | |||||
| int defend(int dmg) | |||||
| { | |||||
| dmg -= def; | |||||
| if (dmg > 0) | |||||
| { | |||||
| hp -= dmg; | |||||
| return dmg; | |||||
| } | |||||
| else | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| } | |||||
| int attack() | |||||
| { | |||||
| return att; | |||||
| } | |||||
| }; | |||||
| #endif | |||||
| @ -0,0 +1,36 @@ | |||||
| #ifndef _2EASY4ME_MONSTER_H_ | |||||
| #define _2EASY4ME_MONSTER_H_ | |||||
| #include "character.hpp" | |||||
| class Monster : public Character | |||||
| { | |||||
| protected: | |||||
| int bounty; | |||||
| public: | |||||
| Monster(char *name) | |||||
| : Character(name) | |||||
| { | |||||
| this->bounty = 0; | |||||
| } | |||||
| Monster(char *name, int hp, int att, int def) | |||||
| : Character(name, hp, att, def) | |||||
| { | |||||
| this->bounty = 0; | |||||
| } | |||||
| Monster(char *name, int hp, int att, int def, int bounty) | |||||
| : Character(name, hp, att, def) | |||||
| { | |||||
| this->bounty = bounty; | |||||
| } | |||||
| int drop() | |||||
| { | |||||
| return bounty; | |||||
| } | |||||
| }; | |||||
| #endif | |||||
| @ -0,0 +1,51 @@ | |||||
| #ifndef _2EASY4ME_PLAYER_H_ | |||||
| #define _2EASY4ME_PLAYER_H_ | |||||
| #include "character.hpp" | |||||
| class Player : public Character | |||||
| { | |||||
| protected: | |||||
| int xp; | |||||
| int level; | |||||
| public: | |||||
| Player(char *name) | |||||
| : Character(name) | |||||
| { | |||||
| this->xp = 0; | |||||
| this->level = 1; | |||||
| } | |||||
| Player(char *name, int hp, int att, int def, int level, int xp) | |||||
| : Character(name, hp, att, def) | |||||
| { | |||||
| this->xp = xp; | |||||
| this->level = level; | |||||
| } | |||||
| bool checkLevelup() | |||||
| { | |||||
| return xp > (level * level); | |||||
| } | |||||
| bool levelUp(int stat) | |||||
| { | |||||
| switch (stat) | |||||
| { | |||||
| case 1: | |||||
| hp += 10; | |||||
| break; | |||||
| case 2: | |||||
| att += 2; | |||||
| break; | |||||
| case 3: | |||||
| def += 1; | |||||
| break; | |||||
| } | |||||
| xp -= level * level; | |||||
| } | |||||
| }; | |||||
| #endif | |||||
| @ -0,0 +1,33 @@ | |||||
| #include <iostream> | |||||
| #include <cstring> | |||||
| #include <math.h> | |||||
| #include "cpp-base64/base64.h" | |||||
| #include "cpp-base64/base64.cpp" | |||||
| #include "class/monster.hpp" | |||||
| #include "class/player.hpp" | |||||
| Player* createNewPlayer() | |||||
| { | |||||
| char name[16]; | |||||
| printf("Input character name (MAX 15): "); | |||||
| scanf("%15s", name); | |||||
| return new Player(name); | |||||
| } | |||||
| int main(int argc, char const *argv[]) | |||||
| { | |||||
| char name[16]; | |||||
| printf("Input name: "); | |||||
| scanf("%15s", name); | |||||
| Player *player = new Player(name); | |||||
| printf("Created new player with name %s at %p\n", name, (void *)player); | |||||
| return 0; | |||||
| } | |||||