Browse Source

first commit

master
myitinos 5 years ago
parent
commit
2936486126
4 changed files with 177 additions and 0 deletions
  1. +57
    -0
      class/character.hpp
  2. +36
    -0
      class/monster.hpp
  3. +51
    -0
      class/player.hpp
  4. +33
    -0
      main.cpp

+ 57
- 0
class/character.hpp View File

@ -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

+ 36
- 0
class/monster.hpp View File

@ -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

+ 51
- 0
class/player.hpp View File

@ -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

+ 33
- 0
main.cpp View File

@ -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;
}

Loading…
Cancel
Save