BHXSpecter

Me Testing Out Some Code

Apr 27th, 2013
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. struct Player{
  8.     string name;
  9.     int health;
  10.     int atk;
  11.     int def;
  12.     int mag;
  13. };
  14.  
  15. struct Weapons{
  16.     string name;
  17.     int atk;
  18.     int price;
  19. };
  20.  
  21. struct Armors{
  22.     string name;
  23.     int def;
  24.     int price;
  25. };
  26.  
  27. struct Enemies{
  28.     string name;
  29.     int atk;
  30.     int health;
  31.     int def;
  32. };
  33.  
  34.  
  35. int main()
  36. {
  37.     vector<Weapons> swords;
  38.     vector<Weapons> axes;
  39.     vector<Weapons> staffs;
  40.    
  41.     vector<Armors> heavy;
  42.     vector<Armors> light;
  43.     vector<Armors> mage;
  44.    
  45.     vector<Enemies> mobs;
  46.     vector<Enemies> bosses;
  47.  
  48.     Player player;
  49.        
  50.     swords.push_back(Weapons());
  51.     swords.push_back(Weapons());
  52.     mobs.push_back(Enemies());
  53.        
  54.     swords[0].name = "Bastard Sword";
  55.     swords[0].atk = 26;
  56.     swords[0].price = 35;
  57.    
  58.     swords[1].name = "Broad Sword";
  59.     swords[1].atk = 32;
  60.     swords[1].price = 50;
  61.    
  62.     player.name = "Devlin";
  63.     player.health = 100;
  64.     player.def = 20;
  65.     player.atk = 30;
  66.     player.mag = 130;
  67.    
  68.     mobs[0].name = "Wood Troll";
  69.     mobs[0].atk = 24;
  70.     mobs[0].health = 100;
  71.     mobs[0].def = 5;
  72.    
  73.     for (int i = 0; i < 2; i++)
  74.     {
  75.         cout << swords[i].name << ' ' << swords[i].atk << ' ' << swords[i].price << endl;
  76.     }
  77.     int turn = 1;
  78.     int round = 1;
  79.     while(mobs[0].health != 0 && player.health != 0)
  80.     {
  81.         cout << "At the start of round " << round << " Player's HP is: " << player.health << ", and "
  82.              << mobs[0].name << " HP is: " << mobs[0].health << "\n";
  83.              
  84.         if(turn == 1 && player.health != 0) // player's attack
  85.         {
  86.             mobs[0].health = mobs[0].health - player.atk;
  87.             if(mobs[0].health < 0)
  88.                 mobs[0].health = 0;
  89.             turn = 0;
  90.         }
  91.         if(turn == 0 && mobs[0].health != 0)
  92.         {
  93.             player.health = player.health - mobs[0].atk;
  94.             if(player.health < 0)
  95.                 player.health = 0;
  96.             turn = 1;
  97.         }
  98.         if(mobs[0].health == 0)
  99.             cout << "You have beat " << mobs[0].name << ".\n";
  100.         if(player.health == 0)
  101.             cout << "You died by the hand of the " << mobs[0].name << "\nHave a nice day!";
  102.         round++;
  103.     }
  104.     return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment