#include<iostream>
#include<string>
#include <time.h>
using namespace std;
class Pet
{
public:
void change_with_time(int w); //随时间变化函数
void display();
void eat();
void drink();
void doctor();
void touch(int w);
void play(int w);
void named();
int emg();
virtual int get_life(); //提取寿命值(虚函数)
virtual void action(int act, int w) = 0; //主人行为函数(纯虚)
virtual void show()=0; // 显示宠物图像
Pet(int a = 0, int hy = 0, int th = 0, int m = 0, int he = 0, int sp = 20)
{
age = a;
hungry_index = hy;
thirsty_index = th;
health_index = he;
mood_index = m;
step_points = sp;
}
void get_named()
{
cout << name;
}
int get_step_points()
{
return step_points;
}
int get_health_index()
{
return health_index;
}
int get_mood_index()
{
return mood_index;
}
int get_thirsty_index()
{
return thirsty_index;
}
int get_hungry_index()
{
return hungry_index;
}
void reduce()
{
hungry_index++;
thirsty_index++;
}
void add_step_points()
{
step_points += 5;
}
private:
int age; //年龄
string name; //名字
int hungry_index; //饥饿度
int thirsty_index; //口渴度
int mood_index; //心情
int health_index; //健康度
int step_points; //行动点数
};
int Pet::get_life()
{
return age;
}
void Pet::play(int w)
{
switch (w)
{
case 0:
mood_index += 2;
break;
case 1:
mood_index += 1;
break;
case 2:
hungry_index += 1;
thirsty_index += 1;
health_index += 1;
break;
case 3:
hungry_index += 2;
thirsty_index += 1;
health_index += 1;
break;
case 4:
hungry_index += 1;
thirsty_index += 1;
health_index += 1;
break;
default:
break;
}
step_points -= 8;
}
//抚摸函数
void Pet::touch(int w)
{
switch (w)
{
case 0:
mood_index += 2;
break;
case 1:
case 2:
mood_index += 1;
break;
case 3:
thirsty_index += 1;
break;
case 4:
mood_index -= 1;
hungry_index += 1;
break;
default:
break;
}
step_points -= 3;
}
//展示宠物状态
void Pet::display()
{
cout << "---------------------------------------------------------------------------------" << endl;
cout << "您的宠物现在状态:";
cout << " 饥饿度:" << hungry_index << " 口渴度:" << thirsty_index << " 心情:" << mood_index << " 健康度:" << health_index << endl;
cout << "---------------------------------------------------------------------------------" << endl;
cout << " 您的行动点数:" << step_points << endl;
system("pause");
}
//特殊状态
int Pet::emg()
{
int x;
srand((int)time(0));
x = rand() % 21;
if (x == 21)
{
cout << "您的宠物生病了!" << endl;
health_index -=2;
}
if (get_hungry_index() == 3)
{
mood_index -= 1;
cout << "饿了" << endl;
}
else if (get_hungry_index() == -2)
{
mood_index -= 1;
cout << "很饱了" << endl;
}
else if (get_hungry_index() > 3)
{
mood_index -= 1;
cout << "要饿死了" << endl;
}
else if (get_hungry_index() < -2)
{
mood_index -= 2;
health_index -= 1;
cout << "要撑死了" << endl;
}
if (get_thirsty_index() == 2)
{
mood_index -= 1;
cout << "好渴" << endl;
}
else if (get_thirsty_index() > 2)
{
mood_index -= 2;
health_index -= 1;
cout << "渴的受不了" << endl;
}
else if (get_thirsty_index() <-2)
{
mood_index -= 2;
health_index -= 1;
cout << "喝撑了" << endl;
}
if (get_hungry_index()>6 || get_thirsty_index() > 5)
{
//age = 100;
cout << "万恶的主人" << endl;
//system("pause");
return 0;
}
if (get_hungry_index() > 5 && get_thirsty_index() > 4)
{
//age = 100;
cout << "来世不跟你混了" << endl;
//system("pause");
return 0;
}
if (get_health_index() < -6)
{
//age = 100;
cout << "您的宠物倒下了" << endl;
//system("pause");
return 0;
}
if (get_step_points() == 0)
{
cout << "bad death" << endl;
//system("pause");
return 0;
}
return 1;
system("pause");
}
void Pet::eat()
{
step_points -= 5;
hungry_index -= 1;
}
void Pet::named()
{
cin >> name;
}
void Pet::drink()
{
step_points -= 3;
thirsty_index -= 2;
}
void Pet::doctor()
{
step_points -= 10;
//flag = 0; //生病的状态
}
void Pet::change_with_time(int w)
{
switch (w)
{
case 0:
mood_index += 2;
break;
case 1:
mood_index += 1;
break;
case 2:
mood_index -= 0;
break;
case 3:
mood_index -= 1;
break;
case 4:
mood_index -= 2;
break;
default:
break;
}
thirsty_index += 1;
}
//饲养说明
void Instruction()
{
cout << "饲养说明:" << endl;
cout << "每个时间段作为主人的你新增5点行动点,未用完可以累积到下一时段,初始有20点。" << endl;
cout << "当行动点相当低时,出现bad end,饲养结束。" << endl;
cout << "每天有三个时间段,你可以进行5项操作,喂食、喂水、抚摸、玩耍、不做任何事。" << endl;
cout << "行动点对应消耗:喂食5点,喂水3点,抚摸3点,玩耍8点。" << endl;
cout << "选择不做任何事,则跳到下一时间段。" << endl;
cout << "当饥饿与口渴相当低的时候n ,或者健康指数相当低的时候,会出现bad end,宠物死亡。" << endl;
cout << "当宠物年龄到达寿命极限时,出现happy end,宠物寿终正寝。" << endl;
cout << "PS:不同的天气对宠物的心情和健康又影响。" << endl;
cout << "在不同天气中进行抚摸玩耍会有特殊情况发生,请注意。" << endl;
cout << "-------------------------------------------------------------------------------" << endl;
system("pause");
}
class Rabbit :virtual public Pet
{
public:
Rabbit(int l = 31)
{
life = l;
}
int get_life();//虚函数
void action(int act, int w);
void show();
private:
int life;
};
class House :virtual public Pet
{
public:
House(int l = 41)
{
life = l;
}
int get_life();//虚函数
void action(int act, int w);
void show();
private:
int life;
};
class Cow :virtual public Pet
{
public:
Cow(int l = 51)
{
life = l;
}
int get_life();//虚函数
void action(int act, int w);
void show();
private:
int life;
};
void Cow::action(int act, int w)
{
switch (act)
{
case 0:
Instruction();
break;
case 1:
eat();
break;
case 2:
drink();
break;
case 3:
play(w);
break;
case 4:
touch(w);
break;
case 5:
doctor();
break;
default:
break;
}
}
void House::action(int act, int w)
{
switch (act)
{
case 0:
Instruction();
break;
case 1:
eat();
break;
case 2:
drink();
break;
case 3:
play(w);
break;
case 4:
touch(w);
break;
case 5:
doctor();
break;
default:
break;
}
}
void Rabbit::action(int act, int w)
{
switch (act)
{
case 0:
Instruction();
break;
case 1:
eat();
break;
case 2:
drink();
break;
case 3:
play(w);
break;
case 4:
touch(w);
break;
case 5:
doctor();
break;
default:
break;
}
}
void Rabbit::show()
{
cout << " ( ( ( " << endl;
cout << " \ ) ) _..-.._ " << endl;
cout << " __)/ ,*,* *. " << endl;
cout << " ,* ** ,--. *. " << endl;
cout << " ,* 0 *' * \ " << endl;
cout << " (Y ( ;**. " << endl;
cout << " *--.____, \ , ; " << endl;
cout << " ((_ ,----* ,---* _,*_,* " << endl;
cout << " (((_,- (((______,-* " << endl;
cout << "-------------------------------------------------------------------------------" << endl;
}
void Cow::show()
{
cout << " /~~~~/ /~~~~/ " << endl;
cout << " / / / / " <
c++写的电子宠物系统
需积分: 50 53 浏览量
2017-12-04
20:06:14
上传
评论 10
收藏 2.9MB ZIP 举报
唯爱的单
- 粉丝: 7
- 资源: 22
最新资源
- week6.1.7z
- 移动机器人自主路径规划之RRTStar算法MATLAB实现代码
- 基于Python+OpenCV+FFmpeg实现自动识别电影剪辑+分析剪辑主题颜色+源码+文档(毕业设计&课程设计&项目开发)
- 基于python的二手商品交易平台 python+django开发的供需平台
- 微信小程序源码 侧滑布局小程序 (源码下载 +内附使用说明)
- heima-JUC-资料
- coreg_FSL.sh
- ROS+YOLOV8+SLAM智能小车导航实战(四、激光雷达+SLAM建图)
- 什么是决策树,有哪些适用场景?
- 基于python开发的口红色号识别程序+源码+开发文档+源码解析(毕业设计&课程设计&项目开发)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0