-
Notifications
You must be signed in to change notification settings - Fork 0
/
RPS Game all in Main.cpp
156 lines (136 loc) · 3.33 KB
/
RPS Game all in Main.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
// Based on old version V.1.1
#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
void main()
{
string p1, p2;
char play, p1choice, p2choice, repeatchoice;
cout << "Enter your name, Player one" << endl;
cin >> p1;
cout << endl << "Enter your name, Player two" << endl;
cin >> p2;
playchoice:
cout << endl << endl << "Welcome " << p1 << " and " << p2 << endl;
cout << "Are you ready to play Rock Papers Scissors? (y/n)";
cin >> play;
if (play == 'y' || play == 'Y')
{
goto Game;
}
else if (play == 'n' || play == 'N')
{
goto Exit;
}
else
{
cout << endl << "Invalid option, Please try again with (y/n)" << endl;
goto playchoice;
}
Game:
cout << endl << "------------------------------------------------------------------------" << endl << endl;
cout << "The game shall start now" << endl << endl;
cout << p1 << ", please choose your move Rock, Paper or Scissor (R, P, S)" << endl;
cin >> p1choice;
cout << p2 << ", please choose your move Rock, Paper or Scissor (R, P, S)" << endl;
cin >> p2choice;
Player1Choice:
if (p1choice == 'r' || p1choice== 'R')
{
if (p2choice == 'r' || p2choice == 'R')
{
cout << "It's a draw" << endl << endl;
goto Repeat;
}
else if (p2choice == 'p' || p2choice == 'P')
{
cout << p2 << " is the winner" << endl << endl;
goto Repeat;
}
else if (p2choice == 's' || p2choice == 'S')
{
cout << p1 << " is the winner" << endl << endl;
goto Repeat;
}
else
{
goto P2Error;
}
}
else if (p1choice == 'p' || p1choice == 'P')
{
if (p2choice == 'r' || p2choice == 'R')
{
cout << p1 << " is the winner" << endl << endl;
goto Repeat;
}
else if (p2choice == 'p' || p2choice == 'P')
{
cout << "It's a draw" << endl << endl;
goto Repeat;
}
else if (p2choice == 's' || p2choice == 'S')
{
cout << p2 << " is the winner" << endl << endl;
goto Repeat;
}
else
{
goto P2Error;
}
}
else if (p1choice == 's' || p1choice == 'S')
{
if (p2choice == 'r' || p2choice == 'R')
{
cout << p2 << " is the winner" << endl << endl;
goto Repeat;
}
else if (p2choice == 'p' || p2choice == 'P')
{
cout << p1 << " is the winner" << endl << endl;
goto Repeat;
}
else if (p2choice == 's' || p2choice == 'S')
{
cout << "It's a draw" << endl << endl;
goto Repeat;
}
else
{
goto P2Error;
}
}
else
{
goto P1Error;
}
P1Error:
cout << endl << endl << p1 << " You have chosen invalid options, please select either Rock (r), Paper (p) or Scissor (s)";
goto Game;
P2Error:
cout << endl << endl << p2 << " You have chosen invalid options, please select either Rock (r), Paper (p) or Scissor (s)";
goto Game;
Repeat:
cout << endl << "Would you like to play again? (y/n)";
cin >> repeatchoice;
if (repeatchoice=='Y'|| repeatchoice=='y')
{
cout << "\033[2J\033[1;1H";
goto Game;
}
else if (repeatchoice=='N'|| repeatchoice=='n')
{
cout << "\033[2J\033[1;1H";
goto Exit;
}
else
{
cout << "Wrong choice selected. Please select with either Y or N" << endl;
goto Repeat;
}
Exit:
cout << endl << endl << "Thank you for playing, " << p1 << " and " << p2 << " hope you had a great time" << endl << endl;
system("pause");
}