-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrockPaperScissor.c
173 lines (172 loc) · 5.79 KB
/
rockPaperScissor.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
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
char choose(void);
int updateScore(char);
void checkWinner(void);
int playerScore = 0, computerScore = 0;
char name[30];
int main(void)
{
int rounds;
char playerChoice, computerChoice;
printf("\t\t\t\t\t\tWELCOME TO 4028 B.S\n");
printf("\t\t\t\t\t\tWHERE THE AI RULES\n");
printf("(Press any key to continue:) ");
getch();
printf("\nAgent47: Human is that you??\n");
printf(" Ohh That's really You.\n");
printf(" It's been a while I had seen any humans\n");
printf("(Press any key to continue:) ");
getch();
printf("\nAgent47: Let me introduce myself\n");
printf(" Iam Agent47 an AI created by Bijay Dulal\n");
printf("(Press any key to continue:) ");
getch();
printf("\n As Bijay had created me he also created Altron(The most Powerful & Smart AI)\n");
printf(" Altron was created to protect the humans but Unfortunately there was bug in the Altron Code\n");
printf("(Press any key to continue:) ");
getch();
printf("\nAgent47: It started killing humans and created his army of Powerful AI\n");
printf(" and Bijay also got killed trying to stop Altron\n");
printf("(Press any key to continue:) ");
getch();
printf("\nAgent47: When he was dying he told me that only humans have that intelligence to defeat Altron\n");
printf(" And he had designed a game to challenge Altron\n");
printf(" But noone was able to win the game till now.\n");
printf("(Press any key to continue:) ");
getch();
printf("\n.........\n");
getch();
printf("\nAgent47: What!!! What iam hearing you want to play that game for us?? Really??\n");
printf("(Press any key to continue:) ");
getch();
printf("\n\nAgent47: Ooooh! That's so nice of you\n");
printf("May i know the name of the Courageous Person: ");
scanf("%s", &name);
printf("\n........");
getch();
printf("\n\nAgent47: Let me load the game for you:\n");
printf("(Press any key to load Game:) ");
getch();
printf("\nAgent47: Again, thank you for showing your fearless behaviour %s", name);
printf("(Press any key to continue:) ");
getch();
system("cls");
printf("\n(Press any key to play GAME:) ");
getch();
system("cls");
printf("\t\t\t\t\t\tROCK PAPER & SCISSORS\t\t\t==>Developed by Bijay Dulal\n\n\n");
printf("\t\t\t\t\tGuide: (Press P for Paper S for scissors & R for Rock)\n");
printf("\n\n");
printf("Enter how many round you want to play: ");
scanf("%d", &rounds);
do
{
system("cls");
printf("\t\t\t\t\t\tROCK PAPER & SCISSORS\t\t\t==>Developed by Bijay Dulal\n\n\n");
printf("\t\t\t\t\tGuide: (Press P for Paper S for scissors & R for Rock)\n\n");
printf("\t\t\t\t\t\t%s's Score: %d", name, playerScore);
printf("\t\t\tAltron's Score: %d\n\n", computerScore);
printf("\t\t\t\t\t\t\t\t Round%s left: %d\n", rounds > 1 ? "'s" : "", rounds);
if (rounds == 0)
break;
if (playerScore > computerScore)
{
printf("Agent47: Let's go %s You can do it\n", name);
printf(" Entire human generation has hope on you");
}
if (computerScore > playerScore)
{
printf("Altron ==> \"Haha!! %s you fool You can't even beat me in your dream hahaha\"\n",name);
printf(" \"IAM THE POWERFUL ALTRON HAHAHA\"");
}
printf("\n\n");
printf("\n\n");
playerChoice = choose();
printf("\n%s's choice: %c", name, playerChoice);
printf("\n\n");
updateScore(playerChoice);
getch();
rounds--;
} while (1);
checkWinner();
getch();
}
char choose(void)
{
char choice;
printf("%s Your Choice: ", name);
scanf(" %c", &choice);
if (choice == 'R' || choice == 'S' || choice == 'P')
;
else if (choice == 'r')
choice = choice - 32;
else if (choice == 's')
choice -= 32;
else if (choice == 'p')
choice -= 32;
else
{
do
{
printf("Wrong Choice(Enter either R, P or S): ");
scanf(" %c", &choice);
if (choice == 'r')
choice -= 32;
else if (choice == 's')
choice -= 32;
else if (choice == 'p')
choice -= 32;
if (choice == 'R' || choice == 'S' || choice == 'P')
break;
} while (1);
}
return choice;
}
int updateScore(char choice)
{
char computer;
srand(time(NULL));
int temp = rand() % 100;
if (temp <= 33)
computer = 'R';
else if (temp <= 67)
computer = 'S';
else
computer = 'P';
printf("Altron's Choice: %c", computer);
if ((choice == 'S' && computer == 'P') || (choice == 'P' && computer == 'R') || (choice == 'R' && computer == 'S'))
{
printf("\n\n%s win this round", name);
playerScore++;
}
else if ((choice == 'R' && computer == 'P') || (choice == 'S' && computer == 'R') || (choice == 'P' && computer == 'S'))
{
printf("\n\nAltron win this round");
computerScore++;
}
else
{
printf("\n\nRound Draw");
}
}
void checkWinner(void)
{
if (playerScore > computerScore)
{
printf("\n\nAltron ==> \"Noooooooooo Noooooooo\"");
printf(" (Press any key to continue:) ");getch();
printf("\n\n\n\nCongratulations!!! %s You defeated that ugly AI and Saved US", name);
}
else if (playerScore < computerScore)
{
printf("\n\n\n\nAltron ==> \"Wooh! Wooh!! I won the game you Human Sucks: \"");
}
else
{
printf("\n\n\nThe game is Draw\n");
printf("Agent47: Well Played %s", name);
}
}