Advertisement
Guest User

rpcppNeedsDebug

a guest
Aug 27th, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <fstream>
  5. #include <cstdlib>
  6. #include <ctime>
  7.  
  8. using namespace std;
  9.  
  10. /**************************************
  11. *                                     *
  12. *   Object Prototypes                 *
  13. *                                     *
  14. **************************************/
  15.  
  16. class Enemy {
  17.    
  18.     private:
  19.         int choice,
  20.             wins,
  21.             losses;
  22.        
  23.     public:
  24.    
  25.     Enemy();
  26.     string name;
  27.     int getChoice();
  28.     int getWins();
  29.     int getLosses();
  30.     void addWin();
  31.     void addLoss();
  32.  
  33. };
  34.  
  35. class Player {
  36.    
  37.     private:
  38.         int choice,
  39.             wins,
  40.             losses;
  41.         string name;
  42.        
  43.     public:
  44.         Player();
  45.         int getChoice();
  46.         int getWins();
  47.         int getLosses();
  48.         void addWin();
  49.         void addLoss();
  50.            
  51. };
  52.  
  53. class GameBoard {
  54.    
  55.     private:
  56.         int opSys;
  57.        
  58.     public:
  59.         GameBoard();
  60.         void gamePlay(Player&, Enemy&);
  61.         void mainMenu(Player&, Enemy&);
  62.         void clearConsole();
  63. };
  64.  
  65. /**************************************
  66. *                                     *
  67. *   Object Constructors               *
  68. *                                     *
  69. **************************************/
  70.  
  71. Player::Player(){
  72.    
  73.     wins = 0;
  74.     losses = 0;
  75.     cout << "\nPlease enter your name: \a";
  76.     getline(cin, name);  
  77.    
  78. }
  79.  
  80. Enemy::Enemy(){
  81.    
  82.     srand(time(NULL));     //assigns the random function the seed from time
  83.    
  84.     wins = 0;
  85.     losses = 0;
  86.     cout << "\nPlease enter the name of the computer: \a";
  87.     getline(cin, name);
  88. }
  89.  
  90. GameBoard::GameBoard(){
  91.    
  92.     opSys = 0;
  93.    
  94.     while(opSys == 0){
  95.      
  96.         cout << "\nEnter your operating system\a" << endl;
  97.         cout << "______________________________"<< endl;
  98.         cout << "1. Windows" << endl;
  99.         cout << "2. Unix/OsX" << endl;
  100.         cin >> opSys;
  101.         if ((opSys == 1) || (opSys == 2)){
  102.             cout << "Thank you." << endl;    
  103.         }
  104.        else{
  105.          
  106.          cout << "You must enter a valid choice (1 or 2)" << endl;
  107.            
  108.         }
  109.     }      
  110. }
  111.  
  112. /**************************************
  113. *                                     *
  114. *   Increment values in objects       *
  115. *                                     *
  116. **************************************/
  117.  
  118. void Player::addWin(){
  119.     wins = (wins + 1);
  120. }
  121. void Player::addLoss(){
  122.     losses = ( losses + 1);
  123. }
  124. void Enemy::addWin(){
  125.     wins = (wins + 1);
  126. }
  127. void Enemy::addLoss(){
  128.     losses = ( losses + 1);
  129. }
  130.  
  131. /**************************************
  132. *                                     *
  133. *   Get values from the objects       *
  134. *                                     *
  135. **************************************/
  136. int Enemy::getWins(){
  137.     return wins;  
  138. }
  139. int Enemy::getLosses(){
  140.     return losses;  
  141. }
  142. int Enemy::getChoice(){           //Were the AI chooses rpc
  143.     choice = 1 + rand() % 3;     //
  144.     return choice;              //
  145. }
  146. int Player::getWins(){
  147.     return wins;  
  148. }
  149. int Player::getLosses(){
  150.     return losses;
  151. }
  152. int Player::getChoice(){       //Were player chooses rpc
  153.     choice = 0;               //
  154.                              //    
  155.     while (choice == 0){
  156.      
  157.         cout << "1. Rock" << endl;
  158.         cout << "2. Paper" << endl;
  159.         cout << "3. Scissors" << endl;
  160.         cin >> choice;
  161.        
  162.         if ((choice == 1) && (choice <=3)){
  163.             return choice;
  164.            
  165.         }
  166.         else{
  167.             cout << "Your choice was not valid, it must be 1, 2, or 3" << endl;
  168.                
  169.         }
  170.     }  
  171. }
  172.  
  173. /**************************************
  174. *                                     *
  175. *   Gameboard functions               *
  176. *                                     *
  177. **************************************/
  178.  
  179. void GameBoard::mainMenu(Player& , Enemy& ){
  180.    
  181.     void gamePlay(Player&, Enemy&);
  182.     bool cont = 0;
  183.    
  184.     while (cont == 0){
  185.        
  186.         int pChoice = 0;
  187.  
  188.         clearConsole();
  189.         cout << "   Rock, Paper, Scissors ++  \a" << endl;
  190.         cout << "_____________________________\a"<< endl;
  191.         cout << " Player Wins: " << human.getWins() << " " << "Player Losses: " << human.getLosses() <<endl;
  192.         cout << " Enemy Wins: " << enemy.getWins() << "" << "Enemy Losses: " << enemy.getLosses() << endl;
  193.         cout << "_____________________________"<< endl;
  194.         cout << "1. Play a game\a" << endl;
  195.         cout << "2. Quit forever\a" << endl;
  196.         cin >> pChoice;
  197.         if (pChoice == 1){
  198.             Board.gamePlay(human, enemy);
  199.            
  200.         }
  201.         else if(pChoice == 2){
  202.             exit(0);
  203.         }
  204.         else{
  205.          cout << "\nYou must select a proper choice(1 or 2)" << endl;  
  206.         }
  207.     }
  208. }
  209.  
  210. void GameBoard::gamePlay(Player&, Enemy&){
  211.    
  212.     int playerChoice, enemChoice;
  213.    
  214.     clearConsole();
  215.     cout << "   Rock, Paper, Scissors ++  \a" << endl;
  216.     cout << "_____________________________\a"<< endl;
  217.     playerChoice = human.getChoice();  
  218.     enemChoice = enemy.getChoice();
  219.    
  220.     if (playerChoice == 1){
  221.         cout << "\nYou chose Rock." << endl;
  222.         if (enemChoice == 1){
  223.             cout << enemy.name << " chose rock." << endl;
  224.             cout << "DRAW, Press enter to continue" << endl;
  225.             cin.get();
  226.         }
  227.         else if(enemChoice == 2){
  228.             cout << enemy.name << " chose paper." << endl;
  229.             cout << "You lose!" << endl;
  230.             cout << "Press enter to continue" <<endl;
  231.             human.addLoss();
  232.             enemy.addWin();
  233.             cin.get();
  234.         }
  235.         else{
  236.             cout << enemy.name << " chose scissors." << endl;
  237.             cout << "You win!" << endl;
  238.             cout << "Press enter to continue:" << endl;
  239.             human.addWin();
  240.             enemy.addLoss();
  241.             cin.get();  
  242.         }  
  243.     }
  244.     else if(playerChoice == 2){
  245.         cout << "\nYou chose paper." << endl;
  246.             if (enemChoice == 1){
  247.             cout << enemy.name << " chose rock." << endl;
  248.             cout << "You win!" << endl;
  249.             cout << "Press enter to continue:" << endl;
  250.             human.addWin();
  251.             enemy.addLoss();
  252.             cin.get();
  253.            
  254.         }
  255.         else if(enemChoice == 2){
  256.             cout << enemy.name << " chose paper." << endl;
  257.             cout << "DRAW, Press enter to continue" << endl;
  258.             cin.get();
  259.            
  260.         }
  261.         else{
  262.             cout << enemy.name << " chose scissors." << endl;
  263.             cout << "You lose!" << endl;
  264.             cout << "Press enter to continue" <<endl;
  265.             human.addLoss();
  266.             enemy.addWin();
  267.             cin.get();
  268.         }
  269.     }
  270.     else{
  271.             cout << "\nYou chose scissors." << endl;
  272.             if (enemChoice == 1){
  273.             cout << enemy.name << " chose rock." << endl;
  274.             cout << "You lose!" << endl;
  275.             cout << "Press enter to continue" <<endl;
  276.             player.addLoss();
  277.             enemy.addWin();
  278.             cin.get();
  279.         }
  280.         else if(enemChoice == 2){
  281.             cout << enemy.name << " chose paper." << endl;
  282.             cout << "You win!" << endl;
  283.             cout << "Press enter to continue:" << endl;
  284.             player.addWin();
  285.             enemy.addLoss();
  286.             cin.get();
  287.         }
  288.         else{
  289.             cout << enemy.name << " chose scissors." << endl;
  290.             cout << "DRAW, Press enter to continue" << endl;
  291.             cin.get();
  292.         }  
  293.     }
  294. }
  295. void GameBoard::clearConsole(){
  296.    
  297.     if (opSys == 1){
  298.         system("cls");  
  299.     }
  300.     else{
  301.         system("clear");
  302.     }
  303. }
  304.  
  305. /**************************************
  306. *                                     *
  307. *   Client program start              *
  308. *                                     *
  309. **************************************/
  310.  
  311. int main() {
  312.        
  313.     cout << "Welcome to Rock, Paper, Scissors++!\a" << endl;
  314.    
  315.     Player human;     //creates the player object
  316.     Enemy enemy;      //creates the enemy object
  317.     GameBoard Board;  //creates the game board
  318.    
  319.     Board.clearConsole();
  320.     Board.mainMenu(human, enemy);
  321.    
  322. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement