Snake gun and water game in c programming
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int snakewatergun(char you, char comp)
{
// return 0 for draw return -1 for lose and return 1 for wining
if (you == comp)
{
return 0;
}
else if (you == 's' && comp == 'w')
{
return 1;
}
else if (you == 'w' && comp == 's')
{
return -1;
}
else if (you == 'g' && comp == 's')
{
return 1;
}
if (you == 's' && comp == 'g')
{
return -1;
}
if (you == 'w' && comp == 'g')
{
return 1;
}
else if (you == 'g' && comp == 'w')
{
return -1;
}
}
int main()
{
char you, comp;
int number;
srand(time(0));
number = rand() % 100 + 1;
if (number < 33)
{
comp = 's';
}
else if (number > 33 && number < 66)
{
comp = 'w';
}
else
{
comp = 'g';
}
printf("Enter the snake 's' , water 'w' and gun 'g':\n");
scanf("%c", &you);
int result = snakewatergun(you, comp);
// result 0 draw and if result 1 you win and if
// result -1 you lose
printf("you choosen '%c' and computer choosen '%c'\n", you, comp);
if (result == 0)
{
printf("Game Draw\n");
}
else if (result == 1)
{
printf("You win\n");
}
else if (result == -1)
{
printf("You loose\n");
}
return 0;
}