Snake, gun, water game in C(Version 1)
#include <stdio.h>
int snakegame(char you, char comp)
{
if (comp == you)
{
return 0;
}
if (comp == 'w' && you == 's')
{
return 1;
}
else if (comp == 's' && you == 'w')
{
return -1;
}
if (comp == 'w' && you == 'g')
{
return -1;
}
else if (comp == 'g' && you == 'w')
{
return 1;
}
if (comp == 'g' && you == 's')
{
return -1;
}
else if (comp == 's' && you == 'g')
{
return 1;
}
}
int main()
{
char you, comp;
comp = 'g';
int value;
printf("Enter your choice from 'w','s','g':");
scanf("%c", &you);
value=snakegame(you, comp);
if (value==0)
{
printf("Game draw");
}
else if (value==1)
{
printf("You win");
}
else
{
printf("You Lose");
}
return 0;
}
Comments
Post a Comment