Snake water gun game
#include<stdio.h>
#include<conio.h>
#include<time.h>
int results(char you ,char computer){
if (you == computer){
return 0;
}
if (you == 'w'&&computer =='s'){
return -1;
}
else if (you == 's'&&computer== 'w'){
return 1;
}
else if (you == 'w'&&computer== 'g'){
return 1;
}
else if (you == 'g'&&computer =='w'){
return -1;
}
else if (you == 's'&&computer =='g'){
return -1;
}
else if (you == 'g'&&computer =='s'){
return 1;
}
return 2;
}
int main(){
char you ,computer ;
int result,number;
srand(time(0));
number = rand()%100;
//system ("cls");
clrscr();
if (number<33){
computer = 'w';
}
else if (number>33 && number <66){
computer = 's';
}
else{
computer = 'g';
}
printf("\nenter 's' for snake 'w' for water and 'g'for gun\n");
scanf("%c",&you);
result = results(you,computer);
printf ("computer chosse %c\n",computer);
if (result == 0){
printf("macth draw\n");
}
else if(result == 1){
printf("you win the macth\n");
}
else if(result == -1){
printf("you lose the macth\n");
}
else{
printf("you should type either 's' or 'g' or 'w'\n");
}
//system ("cls");
getch();
return 0;
}
Comments
Post a Comment