MoBaT

player.cpp

Jun 25th, 2011
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.02 KB | None | 0 0
  1. #include "Player.h"
  2. #include <iostream>
  3. #include <time.h>
  4. #include <stdlib.h>
  5. using namespace std;
  6.  
  7. Player::Player()
  8. {
  9.     _name = "DEFAULT";
  10.     _health = 100;
  11.     _strengh = 1;
  12.     _agility = 1;
  13.     _mf = "male";
  14.     _race = 0;
  15.     _xCoord = 3;
  16.     _yCoord = 5;
  17.     _win = 0;
  18.     _tryX = 3;
  19.     _tryY = 5;
  20. }
  21.  
  22. Player::Player(string name, int health, int strengh, int agility, string mf, int race, int xCoord, int yCoord, int win, int tryX, int tryY)
  23. {
  24.     _name = name;
  25.     _health = health;
  26.     _strengh = strengh;
  27.     _agility = agility;
  28.     _mf = mf;
  29.     _race = race;
  30.     _xCoord = xCoord;
  31.     _yCoord = yCoord;
  32.     _win = win;
  33.     _tryX = tryX;
  34.     _tryY = tryY;
  35. }
  36.  
  37. void Player::set_name(string PlayerName)
  38. {
  39.     _name = PlayerName;
  40. }
  41.  
  42. void Player::set_sex(string playerSex)
  43. {
  44.     if (playerSex == "m")
  45.     {
  46.         _mf = "male";
  47.     }
  48.     else if (playerSex == "f")
  49.     {
  50.         _mf = "female";
  51.     }
  52.     else
  53.     {
  54.     _mf = "male";
  55.     }
  56. }
  57.  
  58. void Player::set_race(int playerRace)
  59. {
  60.     _race = playerRace;
  61. }
  62.  
  63. void Player::set_tryX(int tryX)
  64. {
  65.     _tryX = tryX;
  66. }
  67.  
  68. void Player::set_tryY(int tryY)
  69. {
  70.     _tryY = tryY;
  71. }
  72.  
  73. void Player::set_xCoord(int coord)
  74. {
  75.     _xCoord = coord;
  76. }
  77.  
  78. void Player::set_yCoord(int coord)
  79. {
  80.     _yCoord = coord;
  81. }
  82.  
  83.  
  84. void Player::returnRace()
  85. {
  86.     if (_race == 1)
  87.     {
  88.     cout << "Human";
  89.     }
  90.     else if (_race == 2)
  91.     {
  92.     cout << "Mage";
  93.     }
  94. }
  95.  
  96. string Player::returnName()
  97. {
  98.     return _name;
  99. }
  100.  
  101. int Player::returnHealth()
  102. {
  103.     return _health;
  104. }
  105.  
  106. string Player::returnSex()
  107. {
  108.     return _mf;
  109. }
  110.  
  111. void Player::returnStat(int stat)
  112. {
  113.     if (stat == 1)
  114.     {
  115.         cout << _strengh;
  116.     }
  117.     else if (stat == 2)
  118.     {
  119.         cout << _agility;
  120.     }
  121. }
  122.  
  123. int Player::returnCoord(int coord)
  124. {
  125.     if (coord == 1)
  126.     {
  127.         return (_xCoord);
  128.     }
  129.     else if (coord == 2)
  130.     {
  131.         return (_yCoord);
  132.     }
  133. }
  134.  
  135. int Player::returnTry(int coord)
  136. {
  137.     if (coord == 1)
  138.     {
  139.         return _tryX;
  140.     }
  141.     else if (coord == 2)
  142.     {
  143.         return _tryY;
  144.     }
  145. }
  146.  
  147. int Player::returnWin()
  148. {
  149.     return _win;
  150. }
  151.  
  152.  
  153. void Player::addStat(int stat, int amount)
  154. {
  155.     if (stat == 1)
  156.     {
  157.         _strengh = _strengh + amount;
  158.     }
  159.     if (stat == 2)
  160.     {
  161.         _agility = _agility + amount;
  162.     }
  163. }
  164.  
  165. void Player::subtractStat(int stat, int amount)
  166. {
  167.     if (stat == 1)
  168.     {
  169.         _strengh = _strengh - amount;
  170.     }
  171.     if (stat == 2)
  172.     {
  173.         _agility = _agility - amount;
  174.     }
  175. }
  176.  
  177.  
  178.  
  179. void Player::createStats()
  180. {
  181.     if (_race == 1)
  182.     {
  183.         srand((unsigned)time(0));
  184.         _strengh = rand() % 5 + 1;
  185.         _agility = rand() % 15 + 1;
  186.     }
  187.     if (_race == 2)
  188.     {
  189.         srand((unsigned)time(0));
  190.         _strengh = rand() % 15 + 1;
  191.         _agility = rand() % 8 + 1;
  192.     }
  193. }
  194.  
  195. void Player::IsDead()
  196. {
  197.     if (_health <= 0)
  198.     {
  199.         cout << "Player " << _name << " has died!" << endl;
  200.     }
  201. }
  202.  
  203. Player::~Player()
  204. {
  205.  
  206. }
Advertisement
Add Comment
Please, Sign In to add comment