#include
#include
using namespace std;
class pet //建立一个宠物类
{
public:
pet(int a=0,int h=0,int t=0,int m=0,int he=0,int st=15) //构造函数
{age=a;hunger=h;thirst=t;mood=m;health=he;step=st;}
int getage() {return age;} //提取各个私有成员
int gethunger() {return hunger;}
int getthrist() {return thirst;}
int getmood() {return mood;}
int gethealth() {return health;}
int getstep() {return step;}
void p2(); //饥饿、口渴以及心情随时间的变化函数
void show(); //各个数值的输出函数
void emergency(int w); //各种特殊状态函数
void feed() //喂食函数
{
hunger–;
step=step-5;
}
void drink() {thirst–;step=step-3;} //喂水函数
void doctor() {step=step-10;health=5;} //看医生函数
void touch(int w); //抚摸函数
void fun(int w); //玩耍函数
virtual int getlife()
{return age;} //提取寿命值
virtual void action(int act,int w,int emg)=0; //主人采取各种动作函数,纯虚函数
private:
int age; //年龄
int hunger; //饥饿值
int thirst; //口渴值
int mood; //心情指数
int health; //健康指数
int step; //行动点数
};
inline void pet::p2() //饥饿、口渴以及心情随时间的变化函数
{
int m;
m=rand()%15;
if(m<5)
{
mood=mood-2;
thirst++;
hunger++;
}
else if(m<10)
{
mood–;
thirst++;
hunger++;
}
else
{
mood++;
hunger=hunger+2;
thirst=thirst+2;
age++;
}
}
inline void pet::show() //各个数值的输出函数
{
cout<<“这是你的狗宠物现在的状态:”<<endl;
cout<<“年龄:”<<age;
cout<<“饥饿度:”<<hunger;
cout<<“口渴度:”<<thirst;
cout<<“心情指数:”<<mood;
cout<<“健康指数:”<<health;
}
inline void pet::emergency(int emg) //各种特殊状态函数
{
step=step+5;
if(emg5)
health–;
if(hunger3)
{
mood–;
cout<<“主人,你的萌萌小可爱饿了~”<<endl;
}
if(hunger==-2)
{
mood–;
cout<<“主人,你的萌萌小可爱胖了一大圈呢~”<<endl;
}
if(hunger>3)
{
mood=mood-2;
health–;
cout<<“再不给我吃东西,我就要把自己吃掉啦!”<<endl;
}
if(hunger<-2)
{
mood=mood-2;
health–;
cout<<“再给我吃东西,我就要撑死啦!”<<endl;
}
if(thirst2)
{
mood–;
cout<<“这天好热啊,主人,给口冰阔落吧~”<<endl;
}
if(thirst-2)
{
mood–;
cout<<“面对着一大杯冰阔落,你的宠物恶心地说道:“主人,我去你妈逼。””<<endl;
}
if(thirst>2)
{
mood=mood-2;
health–;
cout<<“伟大的主人在上,我已经渴的快受不鸟啦。”<<endl;
}
if(thirst<-2)
{
mood=mood-2;
health–;
cout<<“好吧,我都喝撑的都吃不下饭了。”<<endl;
}
if(mood<-6)
{
age=100;
cout<<“日出东海落西山,愁也一天,喜也一天;遇事不钻牛角尖,人也舒坦,心也舒坦。”<<endl;
}
if(hunger>3||thirst>3||hunger<-2||thirst<-2)
{
age=100;
cout<<“假如人生不曾相遇,我还是那个我,偶尔做做梦,”<<endl;
cout<<“然后,开始日复一日的奔波,淹