搞到半夜3点还在搞,郁闷,出错中…解决思路
搞到半夜3点还在搞,郁闷,出错中……
Baby.h
truct BabyInformation//用与传递宝宝信息
{
char name[20];
int mounths;
int hungerlevel;
int napplylevel;
int boredomlevel;
bool babystate;
BabyInformation(char name[20],int mounths,int hungerlevel=0,int napplylevel=0,int boredomlevel=0,bool babystate=0)
{
strcpy(this-> name,name);
this-> mounths=mounths;
this-> hungerlevel=hungerlevel;
this-> napplylevel=napplylevel;
this-> boredomlevel=boredomlevel;
this-> babystate=babystate;
}
};
class Baby
{
private:
char name[20];
int mounths;
int hungerlevel;
int napplylevel;
int boredomlevel;
bool babystate;//0代表不哭,1代表正在哭。
public:
Baby(char name[20],int mounths,int hungerlevel=0,int napplylevel=0,int boredomlevel=0,Baby *NextBaby=NULL);
char* GetName();
void Feed();
void NappyChange();
void Play();
//以上3个方法用来更新对应的level;
//以上这3个方法根据玩家的输入来决定使用何种方法.
void BabyUpdata();
/*BabyUpdata(){1. 饥饿等级的增长是宝宝年龄的两倍
2. 尿布等级增长是2*(12-宝宝的年龄)
3. 无聊等级增长是20}*/
bool IsBabyCry();
//根据baby更新后的属性判断baby是否哭
BabyInformation* GetBabyInformation();
};
Baby.cpp
#include "string.h "
#include "baby.h "
Baby::Baby(char name[20],int mounths,int hungerlevel,int napplylevel,int boredomlevel,Baby *NextBaby)
{
strcpy(this-> name,name);
this-> mounths=mounths;
this-> hungerlevel=hungerlevel;
this-> napplylevel=napplylevel;
this-> boredomlevel=boredomlevel;
if((this-> hungerlevel> =100)||(this-> napplylevel> =100)||(this-> boredomlevel> =100))
{
babystate=1;
}
else
{
babystate=0;
}
}
char* Baby::GetName()
{
return name;
}
void Baby::Feed()
{
hungerlevel=0;
}
void Baby::NappyChange()
{
napplylevel=0;
}
void Baby::Play()
{
boredomlevel=0;
}
void Baby::BabyUpdata()
{
hungerlevel+=mounths*2;
napplylevel+=2*(12-mounths);
boredomlevel+=20;
}
bool Baby::IsBabyCry()
{
if((this-> hungerlevel> =100)||(this-> napplylevel> =100)||(this-> boredomlevel> =100))
{
babystate=1;
}
else
{
babystate=0;
}
return babystate;
}
BabyInformation* Baby::GetBabyInformation()
{
BabyInformation static *BabyInformation_point=new BabyInformation(name,mounths,hungerlevel,napplylevel,boredomlevel,babystate);
return BabyInformation_point;
}
上面是我写的类,
main()
{
……
Baby *Baby_Bob=new Baby( "Bob ",6);
Baby *Baby_Ann=new Baby( "Ann ",12);
Baby *Baby_Hana=new Baby( "Hana ",7);
//创建3个孩子类。
vector <Baby> Baby_vector;
//创建Baby容器。
Baby_vector.push_back(*Baby_Bob);
Baby_vector.push_back(*Baby_Ann);
Baby_vector.push_back(*Baby_Hana);
……
}
……
void DisplayBabyAllInformation(vector <Baby> Baby_vector_temp)
Baby.h
truct BabyInformation//用与传递宝宝信息
{
char name[20];
int mounths;
int hungerlevel;
int napplylevel;
int boredomlevel;
bool babystate;
BabyInformation(char name[20],int mounths,int hungerlevel=0,int napplylevel=0,int boredomlevel=0,bool babystate=0)
{
strcpy(this-> name,name);
this-> mounths=mounths;
this-> hungerlevel=hungerlevel;
this-> napplylevel=napplylevel;
this-> boredomlevel=boredomlevel;
this-> babystate=babystate;
}
};
class Baby
{
private:
char name[20];
int mounths;
int hungerlevel;
int napplylevel;
int boredomlevel;
bool babystate;//0代表不哭,1代表正在哭。
public:
Baby(char name[20],int mounths,int hungerlevel=0,int napplylevel=0,int boredomlevel=0,Baby *NextBaby=NULL);
char* GetName();
void Feed();
void NappyChange();
void Play();
//以上3个方法用来更新对应的level;
//以上这3个方法根据玩家的输入来决定使用何种方法.
void BabyUpdata();
/*BabyUpdata(){1. 饥饿等级的增长是宝宝年龄的两倍
2. 尿布等级增长是2*(12-宝宝的年龄)
3. 无聊等级增长是20}*/
bool IsBabyCry();
//根据baby更新后的属性判断baby是否哭
BabyInformation* GetBabyInformation();
};
Baby.cpp
#include "string.h "
#include "baby.h "
Baby::Baby(char name[20],int mounths,int hungerlevel,int napplylevel,int boredomlevel,Baby *NextBaby)
{
strcpy(this-> name,name);
this-> mounths=mounths;
this-> hungerlevel=hungerlevel;
this-> napplylevel=napplylevel;
this-> boredomlevel=boredomlevel;
if((this-> hungerlevel> =100)||(this-> napplylevel> =100)||(this-> boredomlevel> =100))
{
babystate=1;
}
else
{
babystate=0;
}
}
char* Baby::GetName()
{
return name;
}
void Baby::Feed()
{
hungerlevel=0;
}
void Baby::NappyChange()
{
napplylevel=0;
}
void Baby::Play()
{
boredomlevel=0;
}
void Baby::BabyUpdata()
{
hungerlevel+=mounths*2;
napplylevel+=2*(12-mounths);
boredomlevel+=20;
}
bool Baby::IsBabyCry()
{
if((this-> hungerlevel> =100)||(this-> napplylevel> =100)||(this-> boredomlevel> =100))
{
babystate=1;
}
else
{
babystate=0;
}
return babystate;
}
BabyInformation* Baby::GetBabyInformation()
{
BabyInformation static *BabyInformation_point=new BabyInformation(name,mounths,hungerlevel,napplylevel,boredomlevel,babystate);
return BabyInformation_point;
}
上面是我写的类,
main()
{
……
Baby *Baby_Bob=new Baby( "Bob ",6);
Baby *Baby_Ann=new Baby( "Ann ",12);
Baby *Baby_Hana=new Baby( "Hana ",7);
//创建3个孩子类。
vector <Baby> Baby_vector;
//创建Baby容器。
Baby_vector.push_back(*Baby_Bob);
Baby_vector.push_back(*Baby_Ann);
Baby_vector.push_back(*Baby_Hana);
……
}
……
void DisplayBabyAllInformation(vector <Baby> Baby_vector_temp)