No Description

BPlayerClient.cpp 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #include "BPlayer.h"
  2. #include <iostream>
  3. #include <vector>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <time.h>
  7. using namespace std;
  8. void options(vector<BPlayer> &team, int &game) {
  9. int option;
  10. unsigned short player;
  11. bool ask = true;
  12. int index;
  13. do{
  14. cout << "Players: ";
  15. for(int i = 0; i < team.size(); i++) {
  16. cout << team[i].getNumber() << " ";
  17. }
  18. cout << "\nChoose the player: ";
  19. cin >> player;
  20. for(int i = 0; i < team.size(); i++) {
  21. if(player == team[i].getNumber()) {
  22. index = i;
  23. ask = false;
  24. }
  25. }
  26. } while(ask);
  27. //***********************************
  28. cout << "====================Menu====================\n";
  29. cout << "(1) Add shot/points\n";
  30. cout << "(2) Add rebound\n";
  31. cout << "(3) Add assist\n";
  32. cout << "(4) Add steal\n";
  33. cout << "(5) Add block\n";
  34. cout << "(6) Add foul\n";
  35. cout << "(7) Add turnover\n\n";
  36. cout << "(8) Remove shot/points\n";
  37. cout << "(9) Remove rebound\n";
  38. cout << "(10) Remove assist\n";
  39. cout << "(11) Remove steal\n";
  40. cout << "(12) Remove block\n";
  41. cout << "(13) Remove foul\n";
  42. cout << "(14) Remove turnover\n\n";
  43. cout << "(15) Show stats\n";
  44. cout << "(16) End game\n";
  45. cout << "============================================\n\n";
  46. cout << "What is your option? ";
  47. cin >> option;
  48. cout << "\n";
  49. if(option == 1) { team[index].shotTaken();}
  50. else if(option == 2) { team[index].addReb(); }
  51. else if(option == 3) { team[index].addAst(); }
  52. else if(option == 4) { team[index].addStl(); }
  53. else if(option == 5) { team[index].addBlock(); }
  54. else if(option == 6) { team[index].addFoul(); }
  55. else if(option == 7) { team[index].addTurnover(); }
  56. else if(option == 8) { team[index].remPoints(); }
  57. else if(option == 9) { team[index].remReb(); }
  58. else if(option == 10) { team[index].remAst(); }
  59. else if(option == 11) { team[index].remStl(); }
  60. else if(option == 12) { team[index].remBlock(); }
  61. else if(option == 13) { team[index].remFoul(); }
  62. else if(option == 14) { team[index].remTurnover(); }
  63. else if(option == 15) { team[index].showStats(); }
  64. else if(option == 16) { game = 0; }
  65. }
  66. //------------------------------------------------------
  67. unsigned short totalPoints(vector <BPlayer> &team){
  68. unsigned short total = 0;
  69. for(int i = 0; i < team.size(); i++){
  70. total = team[i].getPoints();
  71. }
  72. return total;
  73. }
  74. //------------------------------------------------------
  75. void displayGameStats(vector<BPlayer> &team1, vector<BPlayer> &team2) {
  76. for(int i = 0; i < 42; i++) {
  77. cout << "*";
  78. }
  79. cout << "TEAM 1";
  80. for(int i = 0; i < 42; i++) {
  81. cout << "*";
  82. }
  83. cout << "\nPlayer\tPoints\tFG%\tThrpt%\tFT%\tRebs\tAsts\tStls\tBlocks\tFouls\tTurnovers\n";
  84. for(int i = 0; i < 90; i++) {
  85. cout << "-";
  86. }
  87. for(int i = 0; i < team1.size(); i++) {
  88. cout << "\n" << team1[i].getNumber() << "\t" << team1[i].getPoints() << "\t" << team1[i].getFGPercentage() << "\t" << team1[i].getThrptPercentage()
  89. << "\t" << team1[i].getFTPercentage() << "\t" << team1[i].getRebs() << "\t" << team1[i].getAsts() << "\t" << team1[i].getStls() << "\t"
  90. << team1[i].getBlocks() << "\t" << team1[i].getFouls() << "\t" << team1[i].getTurnovers() << "\n\n";
  91. }
  92. for(int i = 0; i < 42; i++) {
  93. cout << "*";
  94. }
  95. cout << "TEAM 2";
  96. for(int i = 0; i < 42; i++) {
  97. cout << "*";
  98. }
  99. cout << "\nPlayer\tPoints\tFG%\tThrpt%\tFT%\tRebs\tAsts\tStls\tBlocks\tFouls\tTurnovers\n";
  100. for(int i = 0; i < 90; i++) {
  101. cout << "-";
  102. }
  103. for(int i = 0; i < team2.size(); i++) {
  104. cout << "\n" << team2[i].getNumber() << "\t" << team2[i].getPoints() << "\t" << team2[i].getFGPercentage() << "\t" << team2[i].getThrptPercentage()
  105. << "\t" << team2[i].getFTPercentage() << "\t" << team2[i].getRebs() << "\t" << team2[i].getAsts() << "\t" << team2[i].getStls() << "\t"
  106. << team2[i].getBlocks() << "\t" << team2[i].getFouls() << "\t" << team2[i].getTurnovers() << "\n\n";
  107. }
  108. }
  109. int main() {
  110. srand(time(NULL));
  111. vector<BPlayer> team1, team2;
  112. unsigned short totalTeam1, totalTeam2;
  113. int players;
  114. cout << "How many players are in each team? ";
  115. cin >> players;
  116. // Player numbers: Team 1
  117. /********************************************
  118. Remove code here so that numbers can repeat
  119. *********************************************/
  120. int count = 0;
  121. for(int i = 0; i < players; i++) {
  122. unsigned short number = rand() % 51;
  123. for(int j = 0; j < count; j++) {
  124. if(number == team1[i].getNumber()) {
  125. number = rand() % 51;
  126. }
  127. }
  128. team1.push_back(BPlayer(number));
  129. }
  130. // Player numbers: Team 2
  131. /********************************************
  132. Remove code here so that numbers can repeat
  133. *********************************************/
  134. count = 0;
  135. for(int i = 0; i < players; i++) {
  136. unsigned short number = rand() % 51;
  137. for(int j = 0; j < count; j++) {
  138. if(number == team2[i].getNumber()) {
  139. number = rand() % 51;
  140. }
  141. }
  142. team2.push_back(BPlayer(number));
  143. }
  144. int game = 1;
  145. while(game) {
  146. int team;
  147. cout << "Choose a team (1 or 2): ";
  148. cin >> team;
  149. if(team == 1){
  150. options(team1, game);
  151. }
  152. else{
  153. options(team2, game);
  154. }
  155. }
  156. cout << "The game has ended.\n\n";
  157. displayGameStats(team1, team2);
  158. totalTeam1 = totalPoints(team1);
  159. totalTeam2 = totalPoints(team2);
  160. if(totalTeam1 > totalTeam2) {
  161. cout << totalTeam1 << " - " << totalTeam2 << " TEAM 1 HAS WON!\n\n";
  162. }
  163. else if(totalTeam1 < totalTeam2) {
  164. cout << totalTeam1 << " - " << totalTeam2 << " TEAM 2 HAS WON!\n\n";
  165. }
  166. else {
  167. cout << totalTeam1 << " - " << totalTeam2 << " IT'S A TIE!\n\n";
  168. }
  169. return 0;
  170. }