-
Notifications
You must be signed in to change notification settings - Fork 0
/
rock.cpp
134 lines (132 loc) · 4.29 KB
/
rock.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
//J Herzberg
//Rock, Paper, Scissors... and shoot.
//Made game while first learning c++ for fun.
#include <iostream>
#include <string>
#include <cstdlib>
#include <fstream>
using namespace std;
int main()
{
string player1, player2, move1, move2, exit, winner, tie, retest, replay;
int total1 = 0;
int total2 = 0;
string comp[3] = {"r", "p", "s"};
cout << "Are you ready to ROCK...Paper...Scissors\n";
replay = "y";
tie = "Nobody... Boring it is a Tie";
retest = "y";
cout <<"\nPlease enter player name:\n";
cin>> player1;
getchar();
cout <<"Welcome: " + player1 + "\n";
player2 = "computer";
while (replay == "y")
{
cout <<player1 + " please select rock 'r' paper 'p' or scissors 's':\n";
cin>> move1;
getchar();
//make random computer thing
move2 = comp[rand() % 2];
retest = "y";
while (retest == "y")
{
retest = "no";
// cout << move1 + move2;
// determin who won
if(move1 == "r")
{
if(move2 == "s")
{
winner = player1;
}
else if(move2 == "p")
{
winner = player2;
}
else if(move2 == "r")
{
winner = tie;
}
else
{
cout<<"Player 2, please chose only valid moves:(r,p, or s)" <<endl;
cout <<"please select rock 'r' paper 'p' or scissors 's': " <<endl;
cin>> move2;
getchar();
retest = "y";
}
}
else if(move1 == "s")
{
if(move2 == "s")
{
winner = tie;
}
else if(move2 == "p")
{
winner = player1;
}
else if(move2 == "r")
{
winner = player2;
}
else
{
cout<<"Player 2, please chose only valid moves:(r,p, or s)\n";
cout <<"please select rock 'r' paper 'p' or scissors 's':\n";
cin>> move2;
getchar();
retest = "y";
}
}
else if(move1 == "p")
{
if(move2 == "s")
{
winner = player2;
}
else if(move2 == "p")
{
winner = tie;
}
else if(move2 == "r")
{
winner = player1;
}
else
{
cout<<"Player 2, please chose only valid moves:(r,p, or s)\n";
cout <<"please select rock 'r' paper 'p' or scissors 's':\n";
cin>> move2;
getchar();
retest = "y";
}
}
else
{
cout<<"Player 1, please chose only valid moves:(r,p, or s)\n";
cout <<"please select rock 'r' paper 'p' or scissors 's':\n";
cin>> move1;
getchar();
retest = "y";
}
}
cout<< player1 + " chose " + move1 + " and " + player2 + " chose " + move2 << endl;
cout<< "winner is " + winner;
if (winner == player1)
{
total1++;
}
else if(winner == player2)
{
total2++;
}
cout << "\n" + player1 +"'s total is " << total1 << endl;
cout << player2 +"'s total is " << total2 << endl;
cout<< "__________\nDo you want to play again? (y for yes)\n";
cin>> replay;
getchar();
}
return 0;
}