From 2936486126a76069a088f8bc359009143d7c9d09 Mon Sep 17 00:00:00 2001 From: myitinos Date: Mon, 31 Dec 2018 13:57:51 +0800 Subject: [PATCH] first commit --- class/character.hpp | 57 +++++++++++++++++++++++++++++++++++++++++++++ class/monster.hpp | 36 ++++++++++++++++++++++++++++ class/player.hpp | 51 ++++++++++++++++++++++++++++++++++++++++ main.cpp | 33 ++++++++++++++++++++++++++ 4 files changed, 177 insertions(+) create mode 100644 class/character.hpp create mode 100644 class/monster.hpp create mode 100644 class/player.hpp create mode 100644 main.cpp diff --git a/class/character.hpp b/class/character.hpp new file mode 100644 index 0000000..473cac0 --- /dev/null +++ b/class/character.hpp @@ -0,0 +1,57 @@ +#ifndef _2EASY4ME_CHARACTER_H_ +#define _2EASY4ME_CHARACTER_H_ + +#include + +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 \ No newline at end of file diff --git a/class/monster.hpp b/class/monster.hpp new file mode 100644 index 0000000..9cd0474 --- /dev/null +++ b/class/monster.hpp @@ -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 \ No newline at end of file diff --git a/class/player.hpp b/class/player.hpp new file mode 100644 index 0000000..15cd150 --- /dev/null +++ b/class/player.hpp @@ -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 \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..cb9d1fb --- /dev/null +++ b/main.cpp @@ -0,0 +1,33 @@ +#include + +#include +#include + +#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; +} \ No newline at end of file