-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRockPaperScissorGame.c
110 lines (99 loc) · 2.27 KB
/
RockPaperScissorGame.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
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <time.h>
/*
Rock, Paper & Scissor Game
*/
int userChoice, machChoice;
int userScore = 0;
int machScore =0;
int main()
{
srand(time(0));
printf("\t\t\t\t==========*Welcome To Rock, Paper & Scissor Game*==========");
while (userChoice != 4){
printf("\nPlease select the option:");
printf("\n1.Rock");
printf("\n2.Paper");
printf("\n3.Scissor");
printf("\n4.Quit\n");
scanf("%d", &userChoice);
machChoice = (rand() % 3) +1; // rand -> Random Function
checkOptions(userChoice, machChoice);
}
}
void funcWon(){
printf("--------------------\n");
printf("| Victory! You Won |\n");
printf("--------------------\n");
userScore++;
}
void funcLose(){
printf("-----------------------\n");
printf("| Game Over! You Lose |\n");
printf("-----------------------\n");
machScore++;
}
void funcTie(){
printf("--------------\n");
printf("| It's a Tie |\n");
printf("--------------\n");
}
void funcFinalScore(){
printf("| Final Score: |\n");
printf("| You: %d |\n",userScore);
printf("| Machine: %d |\n",machScore);
printf("------------------------\n");
printf("\a");
}
void checkOptions(int user, int mach){
// 1 = Scissor, 2 = Paper, 3 = Rock
if(user == mach){
funcTie();
}
else if(user == 1){
if(mach == 2){
funcWon();
}
else
{
funcLose();
}
}
else if(user == 2){
if(mach == 1){
funcWon();
}
else
{
funcLose();
}
}
else if(user == 3){
if(mach == 1){
funcWon();
}
else
{
funcLose();
}
}
else if(userChoice == 4){
printf("------------------------\n");
if(userScore > machScore){
printf("| Victory! You Won |\n");
}
else if(userScore < machScore){
printf("| Game Over! You Lose |\n");
}
else{
printf("| Friendship Won |\n");
}
funcFinalScore();
}
else{
Beep(750, 500);
printf("\n Invalid Option");
}
}