-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame.c
255 lines (222 loc) · 4.86 KB
/
game.c
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
int WithComputer();
int WithPartner();
int main () {
int i, n1,n,z=1, z2=1;
time_t t;
srand((unsigned) time(&t));
n1 =rand() % 3;
printf("\t\tWELCOME TO THE GAME OF STONE PAPER SCISSOR !!!\n\n");
printf("********************************************************************************************************************************************\n\n");
printf("The game is available in two forms - Game with Computer & Two Player Game\n");
printf("To Play with computer, Press 1 \n To Play with a partner, Press 2\n");
scanf("%d", &n);
if(n==1){
while(z!=0){
z = WithComputer();
}
printf("THE END!!");
}
else if(n==2){
while(z2!=0){
z2 = WithPartner();
}
printf("THE END!!");
}
else{
printf("Wrong Input !! Please run again to start a new game !!");
}
return 0;
}
int WithComputer(){
int m,z,z2,n;
int e;
char ch2,p2,temp;
time_t t1;
srand((unsigned) time(&t1));
n =rand() % 3;
printf("so you want to play with Computer!!\n");
printf("Let's start!!\n Enter 1 for Scissor\t||\tEnter 2 for Stone \t||\t Enter 3 for paper\n");
ch2 = getch();
p2 =ch2;
ch2='*';
printf("%c\n", ch2);
temp=getch();
m = p2 - '0';
if(m<=0|| m>3){
printf("wrong input by Player1 !!\n");
goto next;
}
if(n==0){
if(m==1){
printf("COMPUTER- Scissor | PLAYER -scissor\n" );
printf("Game Draw!!\n\n");
}
else if(m==2){
printf("COMPUTER- Scissor | PLAYER -stone\n" );
printf("Player Wins!!\n\n");
}
else if(m==3){
printf("COMPUTER- Scissor | PLAYER -Paper\n" );
printf("Computer Wins!!\n\n");
}
else{
printf("Wrong Input By player !!\n Computer wins !!\n\n");
}
}
else if(n==1){
if(m==1){
printf("COMPUTER- Stone | PLAYER -scissor\n" );
printf("Computer Wins!!\n\n");
}
else if(m==2){
printf("COMPUTER- Stone | PLAYER -stone\n" );
printf("Game Draw!!\n\n");
}
else if(m==3){
printf("COMPUTER- Stone | PLAYER -Paper\n" );
printf("Player Wins!!\n\n");
}
else{
printf("Wrong Input By player !!\n Computer wins !!\n\n");
}
}
else{
if(m==1){
printf("COMPUTER- Paper | PLAYER -scissor\n" );
printf("Palyer Wins!!\n\n");
}
else if(m==2){
printf("COMPUTER- Paper | PLAYER -stone\n" );
printf("Computer Wins!!\n\n");
}
else if(m==3){
printf("COMPUTER- Paper | PLAYER -Paper\n" );
printf("Game Draw!!\n\n");
}
else{
printf("Wrong Input By player !!\n Computer wins !!\n\n");
}
}
printf("press 1 to exit else press any key to continue!!\n");
scanf("%d",&e);
if(e==1){
z=0;
}
else {
z=1;
}
return z;
next:
printf("press 1 to exit else press 0 to restart!!\n");
scanf("%d",&e);
if(e==1){
z2=0;
}
else {
z2=1;
}
return z2;
}
int WithPartner(){
int z2,m,b;
char ch,p1,ch2,p2,temp;
int e;
printf("so you want to play a Two Player Game!!\n");
printf("Let's start!!\n Enter 1 for Scissor\t||\t Enter 2 for Stone \t||\t Enter 3 for paper\n");
printf("Player1 Enter - \n");
ch = getch();
p1 =ch;
ch='*';
printf("%c\n", ch);
temp=getch();
b = p1 - '0';
if(b<=0|| b>3){
printf("wrong input by Player1 !!\n");
goto next;
}
printf("Player2 Enter -\n");
ch2 = getch();
p2 =ch2;
ch2='*';
printf("%c\n", ch2);
temp=getch();
m = p2 - '0';
if(m<=0 || m>3){
printf("wrong input by Player2 !!\n");
goto next;
}
if(b==1){
if(m==1){
printf("PLAYER1- Scissor | PLAYER2 -scissor\n" );
printf("Game Draw!!\n\n");
}
else if(m==2){
printf("PLAYER1- Scissor | PLAYER2 -stone\n" );
printf("Player2 Wins!!\n\n");
}
else if(m==3){
printf("PLAYER1- Scissor | PLAYER2 -Paper\n" );
printf("PLAYER1 Wins!!\n\n");
}
else{
printf("Wrong Input By player !!\n \n");
}
}
else if(b==2){
if(m==1){
printf("PLAYER1- Stone | PLAYER2 -scissor\n" );
printf("PLAYER1 Wins!!\n\n");
}
else if(m==2){
printf("PLAYER1- Stone | PLAYER2 -stone\n" );
printf("Game Draw!!\n\n");
}
else if(m==3){
printf("PLAYER1- Stone | PLAYER2 -Paper\n" );
printf("Player2 Wins!!\n\n");
}
else{
printf("Wrong Input By player !!\n\n");
}
}
else{
if(m==1){
printf("PLAYER1- Paper | PLAYER2 -scissor\n" );
printf("Palyer2 Wins!!\n\n");
}
else if(m==2){
printf("PLAYER1- Paper | PLAYER2 -stone\n" );
printf("PLAYER1 Wins!!\n\n");
}
else if(m==3){
printf("PLAYER1- Paper | PLAYER2 -Paper\n" );
printf("Game Draw!!\n\n");
}
else{
printf("Wrong Input By player !!\n \n");
}
}
printf("press 1 to exit else press 0 to continue!!\n");
scanf("%d",&e);
if(e==1){
z2=0;
}
else {
z2=1;
}
return z2;
next:
printf("press 1 to exit else press 0 to restart!!\n");
scanf("%d",&e);
if(e==1){
z2=0;
}
else {
z2=1;
}
return z2;
}