Adilol

Player.cpp

Aug 15th, 2011
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.50 KB | None | 0 0
  1.  
  2.  
  3. #include "Library.h"
  4.  
  5. PLAYER::PLAYER()
  6. {
  7.     SetName("Hero");
  8.     strength = 1;
  9.     intelligence = 1;
  10.     level = 1;
  11.     SetGold(100);
  12.     SetExperience(0);
  13.     SetMaxHealth(25);
  14.     SetHealth(25);
  15.     SetMaxMana(100);
  16.     SetMana(100);
  17.     SetPoisoned(false);
  18.     SetMonster(false);
  19.    
  20.     weapon.SetName("Rusty Dagger");
  21.     weapon.SetDamage(2);
  22.     weapon.SetPrice(0);
  23.  
  24.     armor.SetName("None");
  25.     armor.SetAP(0);
  26.     armor.SetPrice(0);
  27.  
  28.     //FIREBALL fireball;
  29.     //HEAL heal;
  30.     //POISON poison;
  31.     BLAZE blaze;
  32.     RANDOM rand;
  33.  
  34.     AddSpell(&blaze);
  35.     AddSpell(&rand);
  36. }
  37.  
  38. int PLAYER::GetIntelligence()
  39. {
  40.     return intelligence;
  41. }
  42.  
  43. int PLAYER::GetStrength()
  44. {
  45.     return strength;
  46. }
  47.  
  48. void PLAYER::SetIntelligence(int newint)
  49. {
  50.     intelligence = newint;
  51. }
  52.  
  53. void PLAYER::SetStrength(int newstr)
  54. {
  55.     strength = newstr;
  56. }
  57.  
  58. void PLAYER::SetLevel(int newlevel)
  59. {
  60.     level = newlevel;
  61. }
  62.  
  63. int PLAYER::GetLevel()
  64. {
  65.     return level;
  66. }
  67.  
  68.  
  69. WEAPON* PLAYER::GetWeapon()
  70. {
  71.     return &weapon;
  72. }
  73.  
  74. void PLAYER::SetWeapon(WEAPON newweapon)
  75. {
  76.     weapon = newweapon;
  77. }
  78.  
  79. ARMOR* PLAYER::GetArmor()
  80. {
  81.     return &armor;
  82. }
  83.  
  84. void PLAYER::SetArmor(ARMOR newarmor)
  85. {
  86.     armor = newarmor;
  87. }
  88.  
  89. void PLAYER::AddPotion(POTION* potion)
  90. {
  91.     if (potion == NULL)
  92.         return;
  93.  
  94.     //check for duplicate
  95.     for (int check = 0; check < 15; check++)
  96.     {
  97.         if (potionlist[check] != NULL)
  98.         {
  99.             if (strcmp(potionlist[check]->GetName(),potion->GetName()) == 0)
  100.             {
  101.                 //names are same
  102.                 potionlist[check]->AddQuantity(1);
  103.                 return;
  104.             }
  105.         }
  106.     }
  107.  
  108.     //no duplicates found
  109.  
  110.     for (int loop=0;loop < 15; loop++)
  111.     {
  112.         if (potionlist[loop] == NULL)
  113.         {
  114.             //create a potion here
  115.             potionlist[loop] = new POTION(potion);
  116.             return;
  117.         }
  118.     }
  119.  
  120.     cout << "There is no room in your inventory.\n";
  121.     Wait();
  122.     cout << endl;
  123. }
  124.  
  125. POTION** PLAYER::GetPotionList()
  126. {
  127.     return potionlist;
  128. }
  129.  
  130. void PLAYER::AddSpell(SPELL *newspell)
  131. {
  132.     //check for open spot
  133.  
  134.     for (int loop=0;loop < 10;loop++)
  135.     {
  136.         if (spelllist[loop] == NULL)
  137.         {
  138.             //openspot
  139.  
  140.             //which type?
  141.             switch (newspell->GetSpellType())
  142.             {
  143.             case ST_GENERIC:
  144.                 {
  145.                     spelllist[loop] = new SPELL(newspell);
  146.                     break;
  147.                 }
  148.             case ST_FIREBALL:
  149.                 {
  150.                     spelllist[loop] = new FIREBALL((FIREBALL*)newspell);
  151.                     break;
  152.                 }
  153.             case ST_HEAL:
  154.                 {
  155.                     spelllist[loop] = new HEAL((HEAL*)newspell);
  156.                     break;
  157.                 }
  158.             case ST_POISON:
  159.                 {
  160.                     spelllist[loop] = new POISON((POISON*)newspell);
  161.                     break;
  162.                 }
  163.             case ST_BLAZE:
  164.                 {
  165.                     spelllist[loop] = new BLAZE((BLAZE*)newspell);
  166.                     break;
  167.                 }
  168.             case ST_RANDOM:
  169.                 {
  170.                     spelllist[loop] = new RANDOM((RANDOM*)newspell);
  171.                     break;
  172.                 }
  173.             }
  174.            
  175.             loop = 10;
  176.         }
  177.     }
  178. }
  179.  
  180. SPELL** PLAYER::GetSpellList()
  181. {
  182.     return spelllist;
  183. }
  184.  
  185. void PLAYER::CheckForLevelUp()
  186. {
  187.     //formula
  188.     // (level * (level * 10))
  189.  
  190.     if (GetExperience() >= (level * (level * 10)))
  191.     {
  192.         //level up!
  193.         cout << "You have gained a level!\n\n";
  194.         level++;
  195.  
  196.         int choice = -1;
  197.  
  198.         while (choice < 1 || choice > 2)
  199.         {
  200.             cout << "Pick a stat to increase.\n";
  201.             cout << "1: Strength\n";
  202.             cout << "2: Intelligence\n";
  203.             cout << ">";
  204.  
  205.             cin >> choice;
  206.             cin.clear();
  207.             cin.ignore(INT_MAX,'\n');
  208.         }
  209.  
  210.         if (choice == 1)
  211.         {
  212.             cout << "You feel much stronger.\n";
  213.             strength++;
  214.  
  215.             SetMaxHealth(strength * 25);
  216.         }
  217.         if (choice == 2)
  218.         {
  219.             cout << "You feel much smarter.\n";
  220.             intelligence++;
  221.  
  222.             SetMaxMana(intelligence * 5);
  223.         }
  224.  
  225.         SetHealth(GetMaxHealth());
  226.         SetMana(GetMaxMana());
  227.  
  228.         Wait();
  229.     }
  230.  
  231. }
Advertisement
Add Comment
Please, Sign In to add comment