forked from Fennel/rps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrps.cpp
More file actions
127 lines (117 loc) · 2.01 KB
/
Copy pathrps.cpp
File metadata and controls
127 lines (117 loc) · 2.01 KB
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
#include <iostream>
#include <stdio.h>
//some modification
<<<<<<< HEAD
<<<<<<< HEAD
//new line is new
=======
//this code needs to be rewritten
>>>>>>> upstream/master
using namespace std;
=======
>>>>>>> upstream/master
class Tool {
int strength;
protected:
char type;
public:
void setStrength(int strength){
this->strength = strength;
};
bool fight(Tool);
char get_type(){
return type;
}
};
using namespace std;
const char* stringify(Tool* pt){
char type = pt->get_type();
const char* result;
switch(type){
case 'r':
result = "Rock";
break;
case 'p':
result = "Paper";
break;
case 's':
result = "Scissors";
break;
default:
break;
}
return result;
}
bool Tool::fight(Tool t){
printf("Before bonus: %s %d VS %s %d\n",stringify(this),strength,stringify(&t),t.strength);
int tmp = strength;
if(type == 'r'){
if(t.type == 's')
tmp *= 2;
else if(t.type == 'p')
tmp /= 2;
}
if(type == 'p'){
if(t.type == 's')
tmp /= 2;
else if(t.type == 'r')
tmp *= 2;
}
if(type == 's'){
if(t.type == 'p')
tmp *= 2;
else if(t.type == 'r')
tmp /= 2;
}
printf("After bonus: %s %d VS %s %d\n",stringify(this),tmp,stringify(&t),t.strength);
bool result = tmp > t.strength;
/*
if(result){
cout << "WIN" << endl;
}else{
cout << "LOSE" << endl;
}*/
//cout << result << endl;
return result;
}
/*
Implement class Scissors
*/
class Scissors : public Tool{
public:
Scissors(int strength){
setStrength(strength);
type = 's';
};
};
/*
Implement class Paper
*/
class Paper : public Tool{
public:
Paper(int strength){
setStrength(strength);
type = 'p';
};
};
/*
Implement class Rock
*/
class Rock : public Tool{
public:
Rock(int strength){
setStrength(strength);
type = 'r';
};
};
int main() {
// Example main function
// You may add your own testing code if you like
Scissors s1(5);
Paper p1(7);
Rock r1(15);
cout << s1.fight(p1) << p1.fight(s1) << endl;
cout << p1.fight(r1) << r1.fight(p1) << endl;
cout << r1.fight(s1) << s1.fight(r1) << endl;
return 0;
}