-
Notifications
You must be signed in to change notification settings - Fork 0
/
RPS.cpp
107 lines (99 loc) · 3.19 KB
/
RPS.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "RPS.h"
#include <iostream>
#include <fstream>
using namespace std;
/**
* Default Constructer
*/
RPS::RPS(){
}
/**
* Getters and Setters for the players
*/
void RPS::setPlayerOne(string newPlayerOne){
players[0] = newPlayerOne;
}
void RPS::setPlayerTwo(string newPlayerTwo){
players[1] = newPlayerTwo;
}
string RPS::getPlayerOne(){
return players[0];
}
string RPS::getPlayerTwo(){
return players[1];
}
/**
* set/getplayerchoice let's the player choose between rock paper and scissors
*/
void RPS::setPlayerOneChoice(){
bool choiceLoop = false;
while(choiceLoop == false){
cout << players[0] << ", choose Rock (R), Paper (P), or Scissors (S)." << endl;
cin >> playerOneChoice;
if(playerOneChoice == "R" || playerOneChoice == "r" || playerOneChoice == "rock"){
playerOneChoice = "Rock";
choiceLoop = true;
}
else if(playerOneChoice == "P" || playerOneChoice == "p" || playerOneChoice == "paper"){
playerOneChoice = "Paper";
choiceLoop = true;
}
else if(playerOneChoice == "S" || playerOneChoice == "s" || playerOneChoice == "scissors"){
playerOneChoice = "Scissors";
choiceLoop = true;
}
else{
cout << "Please enter one of the three choices\n";
}
}
}
string RPS::getPlayerOneChoice(){
return playerOneChoice;
}
void RPS::setPlayerTwoChoice(){
bool choiceLoop = false;
while(choiceLoop == false){
cout << players[1] << ", choose Rock (R), Paper (P), or Scissors (S)." << endl;
cin >> playerTwoChoice;
if(playerTwoChoice == "R" || playerTwoChoice == "r" || playerTwoChoice == "rock"){
playerTwoChoice = "Rock";
choiceLoop = true;
}
else if(playerTwoChoice == "P" || playerTwoChoice == "p" || playerTwoChoice == "paper"){
playerTwoChoice = "Paper";
choiceLoop = true;
}
else if(playerTwoChoice == "S" || playerTwoChoice == "s" || playerTwoChoice == "scissors"){
playerTwoChoice = "Scissors";
choiceLoop = true;
}
else{
cout << "Please enter one of the three choices\n";
}
}
}
string RPS::getPlayerTwoChoice(){
return playerTwoChoice;
}
/**
* determineWinner compares the two player choices, if they are the same it'll be a tie, otherwise the winning player will get points
*/
void RPS::determineWinner(){
if (playerOneChoice == playerTwoChoice){
cout << "It's a tie! No points are awarded." << endl;
tie = true;
}
else{
if (playerOneChoice == "Rock" && playerTwoChoice == "Scissors" || playerOneChoice == "Scissors" && playerTwoChoice == "Paper" || playerOneChoice == "Paper" && playerTwoChoice == "Rock"){
cout << players[0] << " wins! ";
winner = players[0];
}
else if (playerTwoChoice == "Rock" && playerOneChoice == "Scissors" || playerTwoChoice == "Scissors" && playerOneChoice == "Paper" || playerTwoChoice == "Paper" && playerOneChoice == "Rock"){
cout << players[1] << " wins! ";
winner = players[1];
}
}
}
string RPS::getWinner(){
return winner;
}