Created
November 16, 2017 17:07
-
-
Save RockfordWei/df257cc45c492dae328e277405cdd935 to your computer and use it in GitHub Desktop.
camel game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <time.h> | |
#define max_water 3 | |
#define max_food 3 | |
int done = 0; | |
int traveled = 0, thirst = 0, camel_tiredness = 0; | |
int hunger = 0, food = 3; | |
int distance = -20; | |
int water = max_water; | |
void drink(); | |
void common_speed(); | |
void high_speed(); | |
void rest(); | |
void check_status(); | |
void eat(); | |
void quit(); | |
int main(void) | |
{ | |
char choice = 0; | |
printf("Welcome to Camel!\n"); | |
printf("You have stolen a camel to make your way across the great Mobi desert.\n"); | |
printf("The natives want their camel back and are chasing you down! Survive your\n"); | |
printf("desert trek and outrun the natives.\n\n\n"); | |
srand((unsigned)time(NULL)); | |
while(!done) { | |
printf("A. Drink from your canteen.\n"); | |
printf("B. Ahead moderate speed.\n"); | |
printf("C. Ahead full speed.\n"); | |
printf("D. Stop and rest.\n"); | |
printf("E. Status check.\n"); | |
printf("F. Eat some food.\n"); | |
printf("Q. Quit.\n"); | |
printf("Your choice?"); | |
scanf("%c", &choice); | |
switch (choice) { | |
case 'A': | |
case 'a': | |
drink(); | |
break; | |
case 'B': | |
case 'b': | |
common_speed(); | |
break; | |
case 'C': | |
case 'c': | |
high_speed(); | |
break; | |
case 'D': | |
case 'd': | |
rest(); | |
break; | |
case 'E': | |
case 'e': | |
check_status(); | |
break; | |
case 'F': | |
case 'f': | |
eat(); | |
break; | |
case 'Q': | |
case 'q': | |
quit(); | |
done = 1; | |
break; | |
default: | |
printf("Please choose A,B,C,D,E,F or Q\n."); | |
break; | |
} | |
if (thirst >=6) { | |
printf("You died of thirst\n"); | |
done = 1; | |
} else if (thirst >=4) { | |
printf("You are thirsted.\n"); | |
} | |
if (hunger >=6) { | |
printf("You died of hunger\n"); | |
done = 1; | |
} else if (hunger >=4) { | |
printf("You are hungry.\n"); | |
} | |
if (camel_tiredness >=8) { | |
printf("Your camel is dead.\n"); | |
done = 1; | |
} else if (camel_tiredness >=5) { | |
printf("Your camel is getting tired\n"); | |
} | |
if (distance >=0 ) { | |
printf("They caught you, you died.\n"); | |
done = 1; | |
} else if (distance >= -15) { | |
printf("The natives are getting close!\n"); | |
} | |
if (traveled >= 200) { | |
printf("You win!!!\n"); | |
done = 1; | |
} | |
printf("\n\n======================\n"); | |
} | |
system("pause"); | |
return 0; | |
} | |
void drink() | |
{ | |
if (water >= 1) { | |
water--; | |
thirst = 0; | |
} else { | |
printf("error\n"); | |
} | |
} | |
void common_speed() | |
{ | |
int temp = rand() % 8 + 5; | |
traveled += temp; | |
printf("You travled %d miles\n", temp); | |
thirst++; | |
hunger++; | |
camel_tiredness += rand() % 2 + 1; | |
distance -= temp; | |
distance += rand() % 8 + 7; | |
int sur = rand() % 20; | |
if (sur == 1) { | |
printf("You find a green oasis!\n"); | |
water = max_water; | |
food = max_food; | |
hunger = 0; | |
thirst = 0; | |
camel_tiredness = 0; | |
} | |
} | |
void high_speed() | |
{ | |
int temp = rand() % 11 + 10; | |
traveled += temp; | |
printf("You travled %d miles\n", temp); | |
thirst += rand() % 2 + 1; | |
hunger += rand() % 2 + 1; | |
camel_tiredness += rand() % 3 + 1; | |
distance -= temp; | |
distance += rand() % 8 + 7; | |
int sur = rand() % 20; | |
if (sur == 1) { | |
printf("You find a green oasis!\n"); | |
water = max_water; | |
food = max_food; | |
hunger = 0; | |
thirst = 0; | |
camel_tiredness = 0; | |
} | |
} | |
void rest() | |
{ | |
camel_tiredness = 0; | |
printf("The camel is happy\n"); | |
distance += rand() % 8 + 7; | |
int sur = rand() % 20; | |
if (sur == 1) { | |
printf("You find a green oasis!\n"); | |
water = max_water; | |
food = max_food; | |
hunger = 0; | |
thirst = 0; | |
camel_tiredness = 0; | |
} | |
} | |
void check_status() | |
{ | |
printf("Miles traveled: %d\n", traveled); | |
printf("Drinks in canteen: %d\n", water); | |
printf("Food in package: %d\n", food); | |
printf("The natives are %d miles behind you.\n", distance); | |
} | |
void quit() | |
{ | |
printf("You leave\n"); | |
} | |
void eat() | |
{ | |
if (food>=1) { | |
food --; | |
hunger = 0; | |
} else { | |
printf("error\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment