-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStone_Paper_Scissor [vs Computer]
152 lines (150 loc) · 3.08 KB
/
Stone_Paper_Scissor [vs Computer]
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
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,m=0,n=0;
char a,b,e[1],f;
int c,r,d;
srand(time(NULL));
printf("\t\t\t\tSTONE_PAPER_SCISSOR GAME[Computer Opponent]:-\n\t\t\t\t\t -by M.MUHUNTHAN\nGame is built on 24.09.2019\n\nPRESS ANY KEY TO CONTINUE");
getch();
printf("\n\n\t\t\t-----MENU-----\n\t\t*press 1 for Stone\n\t\t*press 2 for Paper\n\t\t*press 3 for Scissor\n\n\t\tPRESS 1 TO VIEW THE RULE OF THE GAME, else enter any other key: ");
scanf("%c",&f);
if(f=='1')
printf("\n\n\t\tRULES:\n\t<< user have to play against computer>>\n\t<<5 Rounds>>\n\t<<Best of 5 is the winner>>");
for(i=0;i<5;i++)
{
j=0;
while(j<1)
{
printf("\n\nROUND %d:-",i+1);
printf("\nUser1's turn:");
e[0]=getch();
fflush(stdin);
d=atoi(e);
a=e[0];
if(isdigit(a))
{
if(d==1||d==2||d==3)
{
j++;
}
else
{
printf("\n\nPlease enter input from 1 to 3....");
}
}
else
{
printf("\n\nPlease enter input from 1 to 3....");
}
}
printf("\nComputer's turn:");
r=(rand()%3)+1;
b=r+'0';
if(b!='1'&&b!='2'&&b!='3')
{
printf("\nWrong input:Technical point to user1 ");
m++;
continue;
}
int c=(int)(a-'0')+(int)(b-'0');
if(a==b)
{
if(a=='1')
{
printf("\n\nBoth user and computer entered STONE");
printf("\nDRAW in this round,No points");
}
else if(a=='2')
{
printf("\n\nBoth user and computer entered PAPER");
printf("\nDRAW in this round,No points");
}
else if(a=='3')
{
printf("\n\nBoth user and computer entered SCISSOR");
printf("\nDRAW in this round,No points");
}
else
{
printf("\n\nBoth entered invalid option\nNo points to each other");
}
}
else if(c==3)
{
if(a=='1')
{
printf("\n\nUser1 entered STONE");
printf("\ncomputer entered PAPER");
n++;
printf("\ncomputer gets one point in this round");
}
else
{
printf("\n\nUser1 entered PAPER");
printf("\ncomputer entered STONE");
m++;
printf("\nUser1 gets one point in this round");
}
}
else if(c==4)
{
if(b!='3')
{
printf("\n\nUser1 entered SCISSOR");
printf("\ncomputer entered STONE");
n++;
printf("\ncomputer gets one point in this round");
}
else
{
printf("\n\nUser1 entered STONE");
printf("\ncomputer entered SCISSOR");
m++;
printf("\nUser1 gets one point in this round");
}
}
else if(c==5)
{
if(a=='2')
{
printf("\n\nUser1 entered PAPER");
printf("\ncomputer entered SCISSOR");
n++;
printf("\ncomputer gets one point in this round");
}
else
{
printf("\n\nUser1 entered SCISSOR");
printf("\ncomputer entered PAPER");
m++;
printf("\nUser1 gets one point in this round");
}
}
else
{
printf("\\nSomething went wrong!");
break;
}
if(m>2||n>2)
{
break;
}
}
printf("\n\n\t\t\tUser1 got %d points totally",m);
printf("\n\t\t\tComputer got %d points totally",n);
if(m>n)
{
printf("\n\n\t\t****User1 is the WINNER****");
}
else if(n>m)
{
printf("\n\n\t\t****Computer is the WINNER****");
}
else
{
printf("\n\n\t\t*****Match Draw*****");
}
getch();
}