#include<iostream>
using namespace std;
int random;
int random2;
char wb;
char input;
int i;
int check;
string yn;
string yn2;
class Animal
{
public:
int eat();
int drink();
int sleep();
int findwater();
void die();
int stolen();
int checkdead();
int checkhunger();
int checkthirst();
int checktiredness();
int checkfood();
int checkwater();
int check();
protected:
int hunger;
int thirst;
int tiredness;
int food;
int water;
};
int Animal::eat()
{
if((food==1)&&(hunger<10))
{
hunger+=5;
if(hunger>10)
hunger=10;
food=0;
thirst-=1;
tiredness-=1;
return hunger;
}
else if((food==1)&&(hunger==10))
{
return 11;
}
else if(water==0)
{
return 12;
}
}
int Animal::drink()
{
if((water==1)&&(thirst<10))
{
thirst+=5;
if(thirst>10)
thirst=10;
water=0;
hunger-=1;
tiredness-=1;
return thirst;
}
else if((water==1)&&(thirst==10))
{
return 11;
}
else if(water==0)
{
return 12;
}
}
int Animal::stolen()
{
if(food==1)
{
random = rand() % 300 + 1;
if(random<=100)
{
food=0;
return 1;
}
else
{
return 0;
}
}
else
{
return 0;
}
}
int Animal::sleep()
{
if(tiredness<10)
{
tiredness+=5;
if(tiredness>10)
tiredness=10;
return tiredness;
}
else if(tiredness==10)
{
return 11;
}
}
int Animal::findwater()
{
if(water==0)
{
random = rand() % 300 + 1;
if(random<=200)
{
water=1;
hunger-=1;
thirst-=1;
tiredness-=2;
return 1;
}
else if((random>200)&&(random<=300))
{
thirst-=1;
hunger-=1;
tiredness-=2;
return 0;
}
water=1;
hunger-=1;
thirst-=1;
tiredness-=2;
}
else
{
return 11;
}
}
void Animal::die()
{
cout<<"Uh-oh; you're dead!\n";
cin.get();
exit(0);
}
int Animal::checkdead()
{
if((hunger<=0)||(thirst<=0)||(tiredness<=0))
return 1;
else
return 0;
}
int Animal::checkhunger()
{
return hunger;
}
int Animal::checkthirst()
{
return thirst;
}
int Animal::checktiredness()
{
return tiredness;
}
int Animal::checkfood()
{
return food;
}
int Animal::checkwater()
{
return water;
}
int Animal::check()
{
tiredness-=1;
}
class Bear : public Animal
{
public:
Bear();
~Bear();
int seek();
};
Bear::Bear()
{
hunger=10;
thirst=10;
tiredness=10;
food=0;
water=0;
}
Bear::~Bear()
{
}
int Bear::seek()
{
if(food==0)
{
random = rand() % 300 + 1;
if(random<=100)
{
food=1;
thirst-=1;
hunger-=1;
tiredness-=2;
return 1;
}
else if((random>100)&&(random<=200))
{
food=1;
thirst-=1;
hunger-=1;
tiredness-=2;
return 2;
}
else if((random>200)&&(random<=300))
{
thirst-=1;
hunger-=1;
tiredness-=2;
return 0;
}
}
else if(food==1)
{
return 11;
}
}
class Wolf : public Animal
{
public:
Wolf();
~Wolf();
int hunt();
};
Wolf::Wolf()
{
hunger=10;
thirst=10;
tiredness=10;
food=0;
water=0;
}
Wolf::~Wolf()
{
}
int Wolf::hunt()
{
if(food==0)
{
random = rand() % 300 + 1;
if(random<=100)
{
food=1;
thirst-=1;
hunger-=1;
tiredness-=2;
return 1;
}
else if((random>100)&&(random<=200))
{
food=1;
thirst-=1;
hunger-=1;
tiredness-=2;
return 2;
}
else if((random>200)&&(random<=300))
{
thirst-=1;
hunger-=1;
tiredness-=2;
random2 = rand() % 300 + 1;
if(random2<=100)
return 3;
else if((random2>100)&&(random2<=200))
return 4;
else if((random2>200)&&(random2<=300))
return 5;
}
}
else if(food==1)
{
return 11;
}
}
Bear user;
void e()
{
check=user.eat();
if(check<=10)
{
cout<<"You ate the food you were carrying.\n";
cout<<"You're hunger level is now at "<<check<<".\n\n";
}
else if(check==11)
{
cout<<"But you're not hungry!\n\n";
}
else if(check==12)
{
cout<<"But you don't have any food to eat!\n\n";
}
}
void d()
{
check=user.drink();
if(check<=10)
{
cout<<"You drunk out of the water you were near.\n";
cout<<"You're thirst level is now at "<<check<<".\n\n";
}
else if(check==11)
{
cout<<"But you're not thirsty!\n\n";
}
else if(check==12)
{
cout<<"But you're not near any water to drink!\n\n";
}
}
void s()
{
check=user.sleep();
if(check<=10)
{
cout<<"You lay down and took a nap.\n";
cout<<"You're tiredness level is now at "<<check<<".\n\n";
check=user.stolen();
if(check==1)
cout<<"As you get up, you realise that someone has stolen the food you were carrying!\n\n";
}
else if(check==11)
{
cout<<"But you're not tired!\n\n";
}
}
void f()
{
check=user.findwater();
if(check==1)
{
cout<<"You found water! It took a lot of effort though!\n\n";
}
else if(check==0)
{
cout<<"Unfourtunatley, after all the effort you put in, you still didn't find any water!\n\n";
}
else if(check==11)
{
cout<<"But you're all ready at water!\n\n";
}
}
void c()
{
if(user.checkfood()==1)
yn="yes";
else
yn="no";
if(user.checkwater()==1)
yn2="yes";
else
yn2="no";
cout<<"Hunger: "<<user.checkhunger()<<".\n";
cout<<"Thirst: "<<user.checkthirst()<<".\n";
cout<<"Tiredness: "<<user.checktiredness()<<".\n";
cout<<"Near Water: "<<yn2<<".\n";
cout<<"Carrying Food: "<<yn<<".\n\n";
user.check();
cout<<"That took some effort telling yourself your stats!\n\n";
}
int main(void)
{
user.~Bear();
cout<<"Do you want to be a wolf (w) or a bear (b)? ";
cin>>wb;
cin.ignore();
if(wb=='b')
{
Bear user;
cout<<"You are a bear living in the deep dark forests of Ramsainia.\nYou are the greatest and strongest bear in the forest so no-one dare challenge you but still, the life of a bear is hard, and merely surviving is a challenge in itself...\n\n";
cout<<"The controls: e - eat any food you are carrying\n d - drink any water that is near you\n s - sleep\n f - find water\n g - gather food\n c - check current statistics\n x - end the program\n\n";
cout<<"The statistics: hunger\n thirst\n tiredness\n near water\n carrying food\n\n";
cout<<"The rules: You must eat to replenish hunger, drink to replenish thirst and sleep to replenish tiredness.\n You must have food to eat and you must be near water to drink.\n You're hunger thirst and tiredness fall gradually every turn you take, also if you do something that involves moving, you're sleep falls by extra.\n If you're hunger, thirst or sleep falls to zero, you die.\n\n";
for(i=10;i>5;i++)
{
if(user.checkdead()==0)
{
cout<<"What do you want to do? ";
cin>>input;
cin.ignore();
if(input=='e')
{
e();
}
else if(input=='d')
{
d();
}
else if(input=='s')
{
s();
}
else if(input=='f')
{
f();
}
else if(input=='g')
{
check=user.seek();
if(check==1)
{
cout<<"You found some berries! It took a lot of effort though!\n\n";
}
else if(check==2)
{
cout<<"You found some honey! It took a lot of effort though!\n\n";
}
else if(check==0)
{
cout<<"Unfourtunatley, after all the effort you put in, you still didn't find any food!\n\n";
}
else if(check==11)
{
cout<<"You can only carry one thing at a time!\n\n";
}
}
else if(input=='c')
{
c();
}
else if(input=='x')
{
cout<<"Thanks for playing!\n";
break;
}
else
{
cout<<"\nError - you did not input a valid command!\n\n";
}
}
else if(user.checkdead()==1)
{
user.die();
}
}
}
if(wb=='w')
{
Wolf user;
cout<<"You are a wolf living in the deep dark forests of Ramsainia.\nYou are the greatest and strongest wolf in the forest so no-one dare challenge you but still, the life of a wolf is hard, and merely surviving is a challenge in itself...\n\n";
cout<<"The controls: e - eat any food you are carrying\n d - drink any water that is near you\n s - sleep\n f - find water\n h - hunt for food\n c - check current statistics\n x - end the program\n\n";
cout<<"The statistics: hunger\n thirst\n tiredness\n near water\n carrying food\n\n";
cout<<"The rules: You must eat to replenish hunger, drink to replenish thirst and sleep to replenish tiredness.\n You must have food to eat and you must be near water to drink.\n You're hunger thirst and tiredness fall gradually every turn you take, also if you do something that involves moving, you're sleep falls by extra.\n If you're hunger, thirst or sleep falls to zero, you die.\n\n";
for(i=10;i>5;i++)
{
if(user.checkdead()==0)
{
cout<<"What do you want to do? ";
cin>>input;
cin.ignore();
if(input=='e')
{
e();
}
else if(input=='d')
{
d();
}
else if(input=='s')
{
s();
}
else if(input=='f')
{
f();
}
else if(input=='h')
{
check=user.hunt();
if(check==1)
{
cout<<"You found and killed a deer! It took a lot of effort though!\n\n";
}
else if(check==2)
{
cout<<"You found and killed a wild boar! It took a lot of effort though!\n\n";
}
else if(check==3)
{
cout<<"Unfourtunatley, after all the effort you put in, you still didn't find any food!\n\n";
}
else if(check==4)
{
cout<<"Unfourtunatley, you found a deer but it got away! That chase was tiring though!\n\n";
}
else if(check==5)
{
cout<<"Unfourtunatley, you found a wild boar but you couldn't kill it! That fight was tiring though!\n\n";
}
else if(check==11)
{
cout<<"You can only carry one thing at a time!\n\n";
}
}
else if(input=='c')
{
c();
}
else if(input=='x')
{
cout<<"Thanks for playing!\n";
break;
}
else
{
cout<<"\nError - you did not input a valid command!\n\n";
}
}
else if(user.checkdead()==1)
{
user.die();
}
}
}
else
{
cout<<"Unidentified Error! Aborting!";
cin.get();
return 0;
}
cin.get();
return 0;
}
Everything works fine except when you choose wolf, the hunt function seems to work fine changing food to 1 but when you check stats or try to eat, it acts as if food is still at 0.
Thanks for your help
Ratchet


Sign In
Create Account


Back to top









