No Description

BPlayer.cpp 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. #include "BPlayer.h"
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <time.h>
  6. using namespace std;
  7. /*====================================
  8. Constructor
  9. ====================================*/
  10. BPlayer::BPlayer() {
  11. srand(time(NULL));
  12. Number = rand() % 51;
  13. FG = FGattempt = FGPercentage = Thrpt = Thrptattempt = ThrptPercentage =
  14. FT = FTattempt = FTPercentage = Points = Rebs = Asts = Stls = Blocks =
  15. Fouls = Turnovers = 0;
  16. }
  17. BPlayer::BPlayer(unsigned short number) {
  18. Number = number;
  19. FG = FGattempt = FGPercentage = Thrpt = Thrptattempt = ThrptPercentage =
  20. FT = FTattempt = FTPercentage = Points = Rebs = Asts = Stls = Blocks =
  21. Fouls = Turnovers = 0;
  22. }
  23. /*====================================
  24. Adders
  25. ====================================*/
  26. void BPlayer::shotTaken() {
  27. int option;
  28. cout << "FG Made (1) FG Missed (2) 3pt Made (3) 3pt Missed (4)\n"
  29. << "FT Made (5) FT Missed (6) None (7)\n";
  30. cin >> option;
  31. if(option == 1){
  32. FG++;
  33. FGattempt++;
  34. Points += 2;
  35. }
  36. else if(option == 2){
  37. FGattempt++;
  38. }
  39. else if(option == 3){
  40. Thrpt++;
  41. Thrptattempt++;
  42. Points += 3;
  43. }
  44. else if(option == 4){
  45. Thrptattempt++;
  46. }
  47. else if(option == 5){
  48. FT++;
  49. FTattempt++;
  50. Points++;
  51. }
  52. else if(option == 6){
  53. FTattempt++;
  54. }
  55. else{
  56. return;
  57. }
  58. }
  59. void BPlayer::addReb() { Rebs++; }
  60. void BPlayer::addAst() { Asts++; }
  61. void BPlayer::addStl() { Stls++; }
  62. void BPlayer::addBlock() { Blocks++; }
  63. void BPlayer::addFoul() { Fouls++; }
  64. void BPlayer::addTurnover() { Turnovers++; }
  65. /*===================================
  66. Subtractors
  67. ===================================*/
  68. /*****************************************************
  69. Remover los ifs que validan si ya estan en 0 los stats
  70. *****************************************************/
  71. void BPlayer::remPoints() {
  72. int option;
  73. cout << "Remove FG (1) Remove 3pt (2) Remove FT (3) None (4)\n";
  74. cin >> option;
  75. if(Points == 0) {
  76. cout << "The player doesn't have any points to remove\n\n";
  77. }
  78. if(option == 1){
  79. FG--;
  80. FGattempt--;
  81. Points -= 2;
  82. }
  83. else if(option == 2){
  84. Thrpt--;
  85. Thrptattempt--;
  86. Points -= 3;
  87. }
  88. else if(option == 3){
  89. FT--;
  90. FTattempt--;
  91. Points--;
  92. }
  93. else {
  94. return;
  95. }
  96. }
  97. void BPlayer::remReb() {
  98. if(Rebs == 0) {
  99. cout << "The player doesn't have any rebounds to remove\n\n";
  100. }
  101. else {
  102. Rebs--;
  103. }
  104. }
  105. void BPlayer::remAst() {
  106. if(Asts == 0) {
  107. cout << "The player doesn't have any assists to remove\n\n";
  108. }
  109. else {
  110. Asts--;
  111. }
  112. }
  113. void BPlayer::remStl() {
  114. if(Stls == 0) {
  115. cout << "The player doesn't have any steals to remove\n\n";
  116. }
  117. else {
  118. Stls--;
  119. }
  120. }
  121. void BPlayer::remBlock() {
  122. if(Blocks == 0) {
  123. cout << "The player doesn't have any blocks to remove\n\n";
  124. }
  125. else {
  126. Blocks--;
  127. }
  128. }
  129. void BPlayer::remFoul() {
  130. if(Fouls == 0) {
  131. cout << "The player doesn't have any fouls to remove\n\n";
  132. }
  133. else {
  134. Fouls--;
  135. }
  136. }
  137. void BPlayer::remTurnover() {
  138. if(Turnovers == 0) {
  139. cout << "The player doesn't have any turnovers to remove\n\n";
  140. }
  141. else {
  142. Turnovers--;
  143. }
  144. }
  145. /*==================================================
  146. Getters
  147. ==================================================*/
  148. unsigned short BPlayer::getNumber() const { return Number; }
  149. unsigned short BPlayer::getPoints() const { return Points; }
  150. float BPlayer::getFGPercentage() const {
  151. if(FG == 0 && FGattempt == 0) {
  152. return 0;
  153. }
  154. else {
  155. return FG / FGattempt * 100;
  156. }
  157. }
  158. float BPlayer::getThrptPercentage() const {
  159. if(Thrpt == 0 && Thrptattempt == 0) {
  160. return 0;
  161. }
  162. else {
  163. return Thrpt / Thrptattempt * 100;
  164. }
  165. }
  166. float BPlayer::getFTPercentage() const {
  167. if(FT == 0 && FTattempt == 0) {
  168. return 0;
  169. }
  170. else {
  171. return FT / FTattempt * 100;
  172. }
  173. }
  174. unsigned short BPlayer::getRebs() const { return Rebs; }
  175. unsigned short BPlayer::getAsts() const { return Asts; }
  176. unsigned short BPlayer::getStls() const { return Stls; }
  177. unsigned short BPlayer::getBlocks() const { return Blocks; }
  178. unsigned short BPlayer::getFouls() const { return Fouls; }
  179. unsigned short BPlayer::getTurnovers() const { return Turnovers; }
  180. void BPlayer::showStats() {
  181. cout << "Points\tFG%\tThrpt%\tFT%\tRebounds\n";
  182. for(int i = 0; i < 44; i++) {
  183. cout << "-";
  184. }
  185. cout << "\n" << Points << "\t" << getFGPercentage() << "\t"
  186. << getThrptPercentage() << "\t" << getFTPercentage() << "\t"
  187. << Rebs << "\n";
  188. for(int i = 0; i < 44; i++) {
  189. cout << "=";
  190. }
  191. cout << "\nAssists\tSteals\tBlocks\tFouls\tTurnovers\n";
  192. for(int i = 0; i < 44; i++) {
  193. cout << "-";
  194. }
  195. cout << "\n" << Asts << "\t" << Stls << "\t"
  196. << Blocks << "\t" << Fouls << "\t"
  197. << Turnovers << "\n";
  198. }