victorialais

rpg editado 7

Nov 20th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include<cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. class Personagem {
  8. protected:
  9.     string nome;
  10.     int vida;
  11.     int atk;
  12.     int def;
  13.     int level;
  14.     string Classe;
  15.  
  16. public:
  17.     Personagem(string n, int v, int a, int d) {
  18.         nome = n;
  19.         vida = v;
  20.         atk = a;
  21.         def = d;
  22.         level = 1;
  23.  
  24.     }
  25.     string getNome() {
  26.         return nome;
  27.     }
  28.     int getVida() {
  29.         return vida;
  30.     }
  31.     int getAtk() {
  32.         return atk;
  33.     }
  34.     int getDef() {
  35.         return def;
  36.     }
  37.     int getLevel() {
  38.         return level;
  39.     }
  40.     void setNome(string novoNome) {
  41.         nome = novoNome;
  42.     }
  43.     void setVida(int novoVida) {
  44.         vida = novoVida;
  45.     }
  46.     void setAtk(int novoAtk) {
  47.         atk = novoAtk;
  48.     }
  49.     void setDef(int novoDef) {
  50.         def = novoDef;
  51.     }
  52.     void setLevel(int novoLevel) {
  53.         level = novoLevel;
  54.     }
  55.  
  56.     bool estaVivo() {
  57.         return (vida > 0);
  58.     }
  59.  
  60.     void descricao() {
  61.         cout << "******" << endl;
  62.         cout << "Nome: " << nome << endl;
  63.         cout << "Level: " << level << endl;
  64.         cout << "Vida: " << vida << endl;
  65.         cout << "Atk: " << atk << endl;
  66.         cout << "Def: " << def << endl;
  67.         cout << "******" << endl;
  68.     }
  69.  
  70.     virtual void atacar(Personagem* alvo) = 0;
  71.     virtual void receberAtaque(int dano) = 0;
  72. };
  73.  
  74. class Heroi : public Personagem {
  75. protected:
  76.     //Equipamentos
  77. public:
  78.     Heroi(string n, int v, int a, int d) : Personagem(n, v, a, d) {
  79.  
  80.     }
  81.  
  82.     void atacar(Personagem* alvo) {
  83.         int dano = atk;
  84.         alvo->receberAtaque(dano);
  85.     }
  86.     void receberAtaque(int dano) {
  87.         int danoFinal = dano - def;
  88.         vida = vida - danoFinal;
  89.     }
  90.  
  91. };
  92.  
  93. class Inimigo : public Personagem {
  94. protected:
  95.     //Experiencia fornecida ao ser derrotado
  96.     //Itens derrubados ao ser derrotado
  97. public:
  98.     Inimigo(string n, int v, int a, int d) : Personagem(n, v, a, d) {
  99.  
  100.     }
  101.  
  102.     void atacar(Personagem* alvo) {
  103.         alvo->receberAtaque(getAtk());
  104.     }
  105.  
  106.     void receberAtaque(int dano) {
  107.         setVida(getVida() - dano);
  108.     }
  109. };
  110.  
  111.  
  112. //CLASSE DOS PERSONAGENS
  113.  
  114. class Cavaleiro : public Heroi {
  115. public:
  116.     Cavaleiro(string n, int v, int a, int d) : Heroi(n, v, a, d) {
  117.         Classe = "cavaleiro";
  118.  
  119.     }
  120.     void atacar(Heroi* alvo) {
  121.         int dano = atk;
  122.         alvo->receberAtaque(dano);
  123.     }
  124.     virtual void receberAtaque(int dano) {
  125.         int danoFinal = dano * 0.8;
  126.         setVida(getVida() - danoFinal);
  127.     }
  128. };
  129.  
  130.  
  131. class Arqueiro : public Heroi {
  132. public:
  133.     int cont;
  134.     Arqueiro(string n, int v, int a, int d) : Heroi(n, v, a, d) {
  135.         cont = 0;
  136.     }
  137.  
  138.     int getCont(){
  139.         return cont;
  140.     }
  141.     void setCont (int novoCont){
  142.         cont = novoCont;
  143.     }
  144.  
  145.     void atacar(Heroi* alvo) {
  146.         setCont(getCont() + 1);
  147.         int dano = atk;
  148.         if (getCont() % 2 == 0){
  149.             dano += atk * 0,5;
  150.         }
  151.         alvo->receberAtaque(dano);
  152.     }
  153. };
  154.  
  155.  
  156. class Barbaro : public Heroi {
  157. public:
  158.     int porcentagem;
  159.     Barbaro(string n, int v, int a, int d) : Heroi(n, v, a, d) {
  160.         int p;
  161.         porcentagem = p;
  162.     }
  163.  
  164.     int getPorcentagem(){
  165.         return porcentagem;
  166.     }
  167.     void setPorcentagem(int novoPorcentagem){
  168.         porcentagem = novoPorcentagem;
  169.     }
  170.  
  171.     void atacar(Heroi* alvo) {
  172.         srand(time(NULL)*1000);
  173.         int p = (rand() % 5) + 8;
  174.         int dano = atk*p/10;
  175.         alvo->receberAtaque(dano);
  176.     }
  177. };
  178.  
  179. class Assassino : public Heroi {
  180. public:
  181.     int atkCritico;
  182.     Assassino(string n, int v, int a, int d, int atkC) : Heroi(n, v, a, d) {
  183.         atkCritico = atkC;
  184.     }
  185.  
  186.     int getAtkCritico(){
  187.         return atkCritico;
  188.     }
  189.  
  190.     void setAtkCritico(int atkC){
  191.         atkCritico = atkC;
  192.     }
  193.  
  194.     virtual void atacar(Heroi* alvo) {
  195.         srand(time(0)*1000);
  196.  
  197.         int danoFinal = (rand() % 100 + 1) <= getAtkCritico() ? getAtk()*2 : getAtk();
  198.         alvo->receberAtaque(danoFinal);
  199.     }
  200. };
  201.  
  202. class Boss : public Inimigo{
  203. public:
  204.     Boss(string n, int v, int a, int d): Inimigo(n, v, a, d) {
  205.  
  206.     }
  207.  
  208.     void atacar(Personagem* alvo) {
  209.     int dano;
  210.     if (vida <= 30) {
  211.  
  212.         dano = atk*2.2;
  213.  
  214.     } else {
  215.  
  216.         dano = atk*2;
  217.  
  218.     }
  219.         alvo->receberAtaque(dano);
  220.     }
  221.     void receberAtaque(int dano) {
  222.         int danoFinal = dano*0.2 - def;
  223.         vida = vida - danoFinal;
  224.     }
  225. };
  226.  
  227. void Escolha(){
  228.     string nome;
  229.     int atk;
  230.     int def;
  231.     string classe;
  232.     int escolha;
  233.  
  234.     cout << "Escolha o nome do seu personagem" << endl;
  235.     cin >> nome;
  236.     cout << " Inicialmente voce tem 20 pontos de atributo. Distribua-os entre a defesa e o ataque do seu personagem." << endl;
  237.     cout << "Ataque: ";
  238.     cin >> atk;
  239.     cout << "Defesa: ";
  240.     cin >> def;
  241.  
  242.     while (def + atk != 20){
  243.         cout << "ERROR. Redistribua-os entre a defesa e o ataque do seu personagem." << endl;
  244.         cout << "Ataque: ";
  245.         cin >> atk;
  246.         cout << "Defesa: ";
  247.         cin >> def;
  248.     }
  249.  
  250.     cout << "Vamos escolher a classe do seu heroi" << endl;
  251.     cout << "1. Cavaleiro " << endl;
  252.     cout << "2. Assassino " << endl;
  253.     cout << "3. Arqueiro " << endl;
  254.     cout << "4. Barbaro " << endl;
  255.     cout << endl;
  256.     cin >> escolha;
  257.  
  258.     Heroi* heroi;
  259.         if(escolha == 1){
  260.             heroi = new Cavaleiro(nome, 100, atk, def);
  261.             cout << "Voce agora eh um cavaleiro!";
  262.         }
  263.         if(escolha == 2){
  264.             heroi = new Assassino(nome, 100, atk, def, 10);
  265.             cout << "Voce agora eh um assassino!";
  266.         }
  267.         if(escolha == 3){
  268.             heroi = new Arqueiro(nome, 100, atk, def);
  269.             cout << "Voce agora eh um arqueiro!";
  270.         }
  271.         if(escolha == 4){
  272.             heroi = new Barbaro(nome, 100, atk, def);
  273.             cout << "Voce agora eh um barbaro!";
  274.         }
  275. cout << endl;
  276. cout << "Aqui estao seus atributos iniciais:" << endl << endl;
  277. heroi->descricao();
  278.  
  279. }
  280.  
  281. int main(){
  282.  
  283.     Inimigo* vilao = new Inimigo("Buchada", 120, 14, 4);
  284.     Escolha(); // Dados do seu personagem
  285.     cout << "Neste turno, voce vai batalhar com: " << endl;
  286.     vilao->descricao();
  287.  
  288.     return 0;
  289. }
Advertisement
Add Comment
Please, Sign In to add comment