-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrps.cpp
161 lines (141 loc) · 2.64 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//This program initializes the classes' constructors and methods.
#include "rps.h"
using namespace std;
// Initialized default Tool constructor
Tool::Tool(){
strength = 1;
type = 's';
}
Tool::Tool(int newStrength, char newType){
strength = newStrength;
type = newType;
}
// Initialized default Rock constructor
Rock::Rock(){
strength = 1;
type = 'r';
}
// Initialized default Paper constructor
Paper::Paper(){
strength = 1;
type = 'p';
}
// Initialized default Scissors constructor
Scissors::Scissors(){
strength = 1;
type = 'p';
}
// Initialized Rock constructor
Rock::Rock(int r){
strength = r;
type = 'r';
}
// Initialized Paper constructor
Paper::Paper(int p){
strength = p;
type = 'p';
}
// Initialized Scissors constructor
Scissors::Scissors(int s){
strength = s;
type = 's';
}
// Initialized fight method for Rock class
bool Rock::fight(Tool opponent){
if (opponent.getType() == 's'){
strength *= 2;
}
else if (opponent.getType() == 'p'){
strength *= 0.5;
}
else{
strength;
}
if (strength > opponent.getStrength()){
return true;
}else{
return false;
}
}
// Initialized fight method for Paper class
bool Paper::fight(Tool opponent){
if (opponent.getType() == 'r'){
strength *= 2;
}
else if (opponent.getType() == 's'){
strength *= 0.5;
}
else{
strength;
}
if (strength > opponent.getStrength()){
return true;
}else{
return false;
}
}
// Initialized fight method for Scissors class
bool Scissors::fight(Tool opponent){
if (opponent.getType() == 's'){
strength *= 2;
}
else if (opponent.getType() == 'r'){
strength *= 0.5;
}
else{
strength;
}
if(strength > opponent.getStrength()){
return true;
}else{
return false;
}
}
// Returns Tool strength
int Tool::getStrength(){
return strength;
}
// Initializes strength to new strength (s)
void Tool::setStrength(int s){
strength = s;
}
// Returns Tool type
char Tool::getType(){
return type;
}
// Initializes type to new type (t)
void Tool::setType(char t){
type = t;
}
// Function to check who won between two objects (Rock, Paper, or Scissors)
void checkWinner(bool win, Tool a, Tool b){
if (win == true){
switch (a.getType()){
case 'r' :
cout << "Rock wins!" << endl;
break;
case 'p' :
cout << "Paper wins!" << endl;
break;
case 's' :
cout << "Scissors wins!" << endl;
break;
default :
cout << "Something went wrong" << endl;
}
}else{
switch (b.getType()){
case 'r' :
cout << "Rock wins!" << endl;
break;
case 'p' :
cout << "Paper wins!" << endl;
break;
case 's' :
cout << "Scissors wins!" << endl;
break;
default :
cout << "Something went wrong" << endl;
}
}
}