Skip to content

Commit

Permalink
Teaching programming to newbie🤫
Browse files Browse the repository at this point in the history
  • Loading branch information
DhananjayPorwal authored Jul 9, 2021
1 parent d8f1de4 commit 3f005b7
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions C Language/Projects/SnakeWaterGun_GAME.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int gameFunction(char userInput, char computerInput)
{
if (userInput == computerInput)
{
return 0;
}
if (userInput == 's' && computerInput == 'w')
{
return 1;
}
else if (userInput == 'w' && computerInput == 's')
{
return -1;
}
if (userInput == 'w' && computerInput == 'g')
{
return 1;
}
else if (userInput == 'g' && computerInput == 'w')
{
return -1;
}
if (userInput == 'g' && computerInput == 's')
{
return 1;
}
else if (userInput == 's' && computerInput == 'g')
{
return -1;
}
}

int main()
{
char userInput, computerInput;
srand(time(0));
int number = rand() % 100 + 1;
if (number > 33)
{
computerInput = 's';
}
else if (number < 33 && number > 66)
{
computerInput = 'w';
}
else
{
computerInput = 'g';
}
printf("Enter 's' for SNAKE, 'w' for WATER and 'g' for GUN\n");
scanf("%c", &userInput);
int temp = gameFunction(userInput, computerInput);
printf("You choose %c and computer choose %c\n", userInput, computerInput);
if (temp == 0)
{
printf("Match Tie\n");
}
else if (temp == 1)
{
printf("Victory\n");
}
else
{
printf("Better Luck Next Time\n");
}

return 0;
}

0 comments on commit 3f005b7

Please sign in to comment.