Advertisement
ren811

TurnBasedPseudoGame

Oct 16th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <string>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. class Skill{
  9. public:
  10.     string nome;
  11.     int dmg;
  12.     int cost;
  13.     Skill(string n, int d, int c)
  14.     {
  15.         this->nome = n;
  16.         this->dmg = d;
  17.         this->cost = c;
  18.     }
  19.     Skill()
  20.     {
  21.         this->nome = "Indefinido";
  22.         this->dmg = 0;
  23.         this->cost = 0;
  24.     }
  25. };
  26.  
  27. class Jogador{
  28. public:
  29.     string nome;
  30.     int hp;
  31.     int hpT;
  32.     int mp;
  33.     int mpT;
  34.     Skill skills[5];
  35.     Jogador(string n, int h, int m)
  36.     {
  37.         this->nome = n;
  38.         this->hp = h;
  39.         this->hpT = h;
  40.         this->mp = m;
  41.         this->mpT = m;
  42.     }
  43.     Jogador()
  44.     {
  45.         this->nome = "Indefinido";
  46.         this->hp = 0;
  47.         this->mp = 0;
  48.         this->hpT = 0;
  49.         this->mpT = 0;
  50.     }
  51.     void listaSkills()
  52.     {
  53.         cout << endl;
  54.         for (int i=0; i<5; i++)
  55.         {
  56.             cout << i+1 <<" - " << this->skills[i].nome << endl;
  57.         }
  58.     }
  59.     int hpAfterAttackFrom(Jogador j, int i)
  60.     {
  61.         if (this->hp - j.skills[i].dmg <= 0)
  62.         {
  63.             return 0;
  64.         }
  65.         else return this->hp - j.skills[i].dmg;
  66.     }
  67. };
  68.  
  69. class Combate{
  70. public:
  71.     int turno;
  72.     int input;
  73.     int maxAttacks;
  74.     Jogador j1;
  75.     Jogador j2;
  76.     Combate(Jogador j1, Jogador j2)
  77.     {
  78.         this->j1 = j1;
  79.         this->j2 = j2;
  80.         this->turno = 0;
  81.         this->maxAttacks = 6;
  82.     }
  83.     bool CheckPlayers()
  84.     {
  85.         if (j1.hp <= 0 || j2.hp <= 0)
  86.         {
  87.             return false;
  88.         }
  89.         else return true;
  90.     }
  91.     void Luta()
  92.     {
  93.         if (this->turno%2 == 0)
  94.         {
  95.             this->turno += 1;
  96.             cout << "Como " << j1.nome << " reagira?";
  97.             j1.listaSkills();
  98.             input = 0;
  99.             while(input==0)
  100.             {
  101.                 cin >> input;
  102.                 if (input > 0 && input < maxAttacks)
  103.                 {
  104.                     j2.hp = j2.hpAfterAttackFrom(j1, input-1);
  105.                     j1.mp -= j1.skills[input-1].cost;
  106.                 }
  107.                 else input = 0;
  108.             }
  109.         }
  110.         else
  111.         {
  112.             this->turno += 1;
  113.             cout << "Como " << j2.nome << " reagira?";
  114.             j2.listaSkills();
  115.             input = 0;
  116.             while(input==0)
  117.             {
  118.                 cin >> input;
  119.                 if (input > 0 && input < maxAttacks)
  120.                 {
  121.                     j1.hp = j1.hpAfterAttackFrom(j2, input-1);
  122.                     j2.mp -= j2.skills[input-1].cost;
  123.                 }
  124.                 else input = 0;
  125.             }
  126.         }
  127.     }
  128.     void mostraStatus()
  129.     {
  130.         cout << j1.nome << " = HP: " << j1.hp << "/" << j1.hpT << " / MP: " << j1.mp << "/" << j1.mpT << endl;
  131.         cout << j2.nome << " = HP: " << j2.hp << "/" << j2.hpT << " / MP: " << j2.mp << "/" << j2.mpT << endl;
  132.     }
  133. };
  134.  
  135. int main()
  136. {
  137.     Jogador jo1("Jogador1", 80, 50);
  138.     Jogador jo2("Jogador2", 150, 0);
  139.     jo1.skills[0] = Skill("Jato de Agua", 10, 5);
  140.     jo1.skills[1] = Skill("Surf", 12, 8);
  141.     jo1.skills[2] = Skill();
  142.     jo1.skills[3] = Skill();
  143.     jo1.skills[4] = Skill("Ataque Basico", 2, 0);
  144.     jo2.skills[0] = Skill("Lanca Chamas", 10, 6);
  145.     jo2.skills[1] = Skill("Terremoto", 15, 10);
  146.     jo2.skills[2] = Skill();
  147.     jo2.skills[3] = Skill();
  148.     jo2.skills[4] = Skill("Ataque Basico", 2, 0);
  149.  
  150.     Combate Game(jo1,jo2);
  151.     bool onGame = true;
  152.     while (onGame)
  153.     {
  154.         system("cls");
  155.         Game.mostraStatus();
  156.         Game.Luta();
  157.         onGame = Game.CheckPlayers();
  158.     }
  159.     cout << "O jogo acabou!";
  160.     getchar();
  161.     return 0;
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement