Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include <fstream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- /**************************************
- * *
- * Object Prototypes *
- * *
- **************************************/
- class Enemy {
- private:
- int choice,
- wins,
- losses;
- public:
- Enemy();
- string name;
- int getChoice();
- int getWins();
- int getLosses();
- void addWin();
- void addLoss();
- };
- class Player {
- private:
- int choice,
- wins,
- losses;
- string name;
- public:
- Player();
- int getChoice();
- int getWins();
- int getLosses();
- void addWin();
- void addLoss();
- };
- class GameBoard {
- private:
- int opSys;
- public:
- GameBoard();
- void gamePlay(Player&, Enemy&);
- void mainMenu(Player&, Enemy&);
- void clearConsole();
- };
- /**************************************
- * *
- * Object Constructors *
- * *
- **************************************/
- Player::Player(){
- wins = 0;
- losses = 0;
- cout << "\nPlease enter your name: \a";
- getline(cin, name);
- }
- Enemy::Enemy(){
- srand(time(NULL)); //assigns the random function the seed from time
- wins = 0;
- losses = 0;
- cout << "\nPlease enter the name of the computer: \a";
- getline(cin, name);
- }
- GameBoard::GameBoard(){
- opSys = 0;
- while(opSys == 0){
- cout << "\nEnter your operating system\a" << endl;
- cout << "______________________________"<< endl;
- cout << "1. Windows" << endl;
- cout << "2. Unix/OsX" << endl;
- cin >> opSys;
- if ((opSys == 1) || (opSys == 2)){
- cout << "Thank you." << endl;
- }
- else{
- cout << "You must enter a valid choice (1 or 2)" << endl;
- }
- }
- }
- /**************************************
- * *
- * Increment values in objects *
- * *
- **************************************/
- void Player::addWin(){
- wins = (wins + 1);
- }
- void Player::addLoss(){
- losses = ( losses + 1);
- }
- void Enemy::addWin(){
- wins = (wins + 1);
- }
- void Enemy::addLoss(){
- losses = ( losses + 1);
- }
- /**************************************
- * *
- * Get values from the objects *
- * *
- **************************************/
- int Enemy::getWins(){
- return wins;
- }
- int Enemy::getLosses(){
- return losses;
- }
- int Enemy::getChoice(){ //Were the AI chooses rpc
- choice = 1 + rand() % 3; //
- return choice; //
- }
- int Player::getWins(){
- return wins;
- }
- int Player::getLosses(){
- return losses;
- }
- int Player::getChoice(){ //Were player chooses rpc
- choice = 0; //
- //
- while (choice == 0){
- cout << "1. Rock" << endl;
- cout << "2. Paper" << endl;
- cout << "3. Scissors" << endl;
- cin >> choice;
- if ((choice == 1) && (choice <=3)){
- return choice;
- }
- else{
- cout << "Your choice was not valid, it must be 1, 2, or 3" << endl;
- }
- }
- }
- /**************************************
- * *
- * Gameboard functions *
- * *
- **************************************/
- void GameBoard::mainMenu(Player& , Enemy& ){
- void gamePlay(Player&, Enemy&);
- bool cont = 0;
- while (cont == 0){
- int pChoice = 0;
- clearConsole();
- cout << " Rock, Paper, Scissors ++ \a" << endl;
- cout << "_____________________________\a"<< endl;
- cout << " Player Wins: " << human.getWins() << " " << "Player Losses: " << human.getLosses() <<endl;
- cout << " Enemy Wins: " << enemy.getWins() << "" << "Enemy Losses: " << enemy.getLosses() << endl;
- cout << "_____________________________"<< endl;
- cout << "1. Play a game\a" << endl;
- cout << "2. Quit forever\a" << endl;
- cin >> pChoice;
- if (pChoice == 1){
- Board.gamePlay(human, enemy);
- }
- else if(pChoice == 2){
- exit(0);
- }
- else{
- cout << "\nYou must select a proper choice(1 or 2)" << endl;
- }
- }
- }
- void GameBoard::gamePlay(Player&, Enemy&){
- int playerChoice, enemChoice;
- clearConsole();
- cout << " Rock, Paper, Scissors ++ \a" << endl;
- cout << "_____________________________\a"<< endl;
- playerChoice = human.getChoice();
- enemChoice = enemy.getChoice();
- if (playerChoice == 1){
- cout << "\nYou chose Rock." << endl;
- if (enemChoice == 1){
- cout << enemy.name << " chose rock." << endl;
- cout << "DRAW, Press enter to continue" << endl;
- cin.get();
- }
- else if(enemChoice == 2){
- cout << enemy.name << " chose paper." << endl;
- cout << "You lose!" << endl;
- cout << "Press enter to continue" <<endl;
- human.addLoss();
- enemy.addWin();
- cin.get();
- }
- else{
- cout << enemy.name << " chose scissors." << endl;
- cout << "You win!" << endl;
- cout << "Press enter to continue:" << endl;
- human.addWin();
- enemy.addLoss();
- cin.get();
- }
- }
- else if(playerChoice == 2){
- cout << "\nYou chose paper." << endl;
- if (enemChoice == 1){
- cout << enemy.name << " chose rock." << endl;
- cout << "You win!" << endl;
- cout << "Press enter to continue:" << endl;
- human.addWin();
- enemy.addLoss();
- cin.get();
- }
- else if(enemChoice == 2){
- cout << enemy.name << " chose paper." << endl;
- cout << "DRAW, Press enter to continue" << endl;
- cin.get();
- }
- else{
- cout << enemy.name << " chose scissors." << endl;
- cout << "You lose!" << endl;
- cout << "Press enter to continue" <<endl;
- human.addLoss();
- enemy.addWin();
- cin.get();
- }
- }
- else{
- cout << "\nYou chose scissors." << endl;
- if (enemChoice == 1){
- cout << enemy.name << " chose rock." << endl;
- cout << "You lose!" << endl;
- cout << "Press enter to continue" <<endl;
- player.addLoss();
- enemy.addWin();
- cin.get();
- }
- else if(enemChoice == 2){
- cout << enemy.name << " chose paper." << endl;
- cout << "You win!" << endl;
- cout << "Press enter to continue:" << endl;
- player.addWin();
- enemy.addLoss();
- cin.get();
- }
- else{
- cout << enemy.name << " chose scissors." << endl;
- cout << "DRAW, Press enter to continue" << endl;
- cin.get();
- }
- }
- }
- void GameBoard::clearConsole(){
- if (opSys == 1){
- system("cls");
- }
- else{
- system("clear");
- }
- }
- /**************************************
- * *
- * Client program start *
- * *
- **************************************/
- int main() {
- cout << "Welcome to Rock, Paper, Scissors++!\a" << endl;
- Player human; //creates the player object
- Enemy enemy; //creates the enemy object
- GameBoard Board; //creates the game board
- Board.clearConsole();
- Board.mainMenu(human, enemy);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement