victorialais

rpg editado 4

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