Advertisement
Guest User

Constructor Lab code

a guest
Feb 10th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include "Weapon.h"
  2.  
  3. Weapon::Weapon(WeaponType type)
  4. {
  5. m_type = type;
  6. if (m_type == PISTOL)
  7. {
  8. m_clipSize = 6;
  9. }
  10. else if (m_type == SHOTGUN)
  11. {
  12. m_clipSize = 2;
  13. }
  14. else if (m_type == RIFLE)
  15. {
  16. m_clipSize = 13;
  17. }
  18. m_ammoCount = 0;
  19.  
  20. }
  21. Weapon::Weapon(WeaponType type, int clipSize)
  22. {
  23. m_type = type;
  24. m_clipSize = clipSize;
  25. m_ammoCount = 0;
  26. }
  27. Weapon::Weapon(WeaponType type, int clipSize, int ammoCount)
  28. {
  29. m_type = type;
  30. m_clipSize = clipSize;
  31. m_ammoCount = ammoCount;
  32. }
  33. bool Weapon::Fire()
  34. {
  35. if(m_ammoCount > 0)
  36. {
  37. cout << "BANG" << endl;
  38. m_ammoCount--;
  39. }
  40. else
  41. {
  42. cout << "CLICK" << endl;
  43. }
  44. return true;
  45. }
  46. void Weapon::Reload(int ammoCount)
  47. {
  48. if (ammoCount >= (m_clipSize - m_ammoCount))
  49. {
  50. ammoCount = (m_clipSize - m_ammoCount);
  51. m_ammoCount += ammoCount;
  52. cout << "RELOADING" << endl;
  53. }
  54. else
  55. {
  56. m_ammoCount += ammoCount;
  57. cout << "RELOADING" << endl;
  58. }
  59. }
  60. int Weapon::CheckAmmo()
  61. {
  62. cout << "AMMO " << m_ammoCount << endl;
  63. return m_ammoCount;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement