victorialais

RPG base

Nov 10th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.42 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Personagem {
  6. protected:
  7.     string nome;
  8.     int vida;
  9.     int atk;
  10.     int def;
  11.     int level;
  12. public:
  13.     Personagem(string n, int v, int a, int d) {
  14.         nome = n;
  15.         vida = v;
  16.         atk = a;
  17.         def = d;
  18.         level = 1;
  19.     }
  20.     string getNome() {
  21.         return nome;
  22.     }
  23.     int getVida() {
  24.         return vida;
  25.     }
  26.     int getAtk() {
  27.         return atk;
  28.     }
  29.     int getDef() {
  30.         return def;
  31.     }
  32.     int getLevel() {
  33.         return level;
  34.     }
  35.     void setNome(string novoNome) {
  36.         nome = novoNome;
  37.     }
  38.  
  39.     bool estaVivo() {
  40.         return (vida > 0);
  41.     }
  42.  
  43.     void descricao() {
  44.         cout << "*************" << endl;
  45.         cout << "Nome: " << nome << endl;
  46.         cout << "Level: " << level << endl;
  47.         cout << "Vida: " << vida << endl;
  48.         cout << "Atk: " << atk << endl;
  49.         cout << "Def: " << def << endl;
  50.         cout << "*************" << endl;
  51.     }
  52.  
  53.     virtual void atacar(Personagem* alvo) = 0;
  54.     virtual void receberAtaque(int dano) = 0;
  55. };
  56.  
  57. class Heroi : public Personagem {
  58. protected:
  59.     //Equipamentos
  60. public:
  61.     Heroi(string n, int v, int a, int d)
  62.     : Personagem(n, v, a, d) {
  63.  
  64.     }
  65.  
  66.     void atacar(Personagem* alvo) {
  67.         int dano = atk;
  68.         alvo->receberAtaque(dano);
  69.     }
  70.     void receberAtaque(int dano) {
  71.         int danoFinal = dano - def;
  72.         vida = vida - danoFinal;
  73.     }
  74.  
  75. };
  76.  
  77. class Inimigo : public Personagem {
  78. protected:
  79.     //Experiencia fornecida ao ser derrotado
  80.     //Itens derrubados ao ser derrotado
  81. public:
  82.     Inimigo(string n, int v, int a, int d)
  83.     : Personagem(n, v, a, d) {
  84.     }
  85.  
  86.     void atacar(Personagem* alvo) {
  87.         int danoFinal = atk * 2;
  88.         alvo->receberAtaque(danoFinal);
  89.     }
  90.     void receberAtaque(int dano) {
  91.         int danoFinal = dano * 0.8;
  92.         vida = vida - danoFinal;
  93.     }
  94. };
  95.  
  96. int main()
  97. {
  98.     Heroi* sam = new Heroi("Samuel", 100, 25, 5);
  99.     Inimigo* mar = new Inimigo("Marcus", 100, 11, 3);
  100.  
  101.     while (sam->estaVivo() && mar->estaVivo()) {
  102.         sam->atacar(mar);
  103.         mar->atacar(sam);
  104.  
  105.         sam->descricao();
  106.         mar->descricao();
  107.     }
  108.  
  109.     if (sam->estaVivo()) {
  110.         cout << "Samuel eh o grande Vendor" << endl;
  111.     }
  112.     if (mar->estaVivo()) {
  113.         cout << "Eu ja sabia!!! sdufhsudfhsd" << endl;
  114.     }
  115.  
  116.     return 0;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment