没有合适的资源?快使用搜索试试~ 我知道了~
C++程序设计电子宠物.pdf
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 197 浏览量
2023-08-27
23:08:50
上传
评论
收藏 780KB PDF 举报
温馨提示
试读
31页
C++程序设计电子宠物.pdf
资源推荐
资源详情
资源评论
---
#include <iostream>
#include <stdlib.h> 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 geta() {return age;} // int
geth() {return hunger;}
int gett() {return thirst;}
int getm() {return mood;}
int gethe() {return health;} int getst() {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;} 看医生函数 抚摸函数
void touch(int w); // // void fun(int w);
玩耍函数 //virtual int getl() {return age;}
提取寿命值 virtual void action(int act,int w,int emg) {}
//主人采取各种动作函数,定义为纯虚函 数
private:
年龄//int age; //饥饿值 int hunger;
口渴值//int thirst; // 心情指数 int mood; 健
康指数// int health; 行动点数// int step;
};
// 饥饿、口渴以及心情随时间的变化函数 inline
void pet::p2() {
int m;
-----
---
m=rand(); if(m<5)
mood=mood-2;
-----
---
else if(m<12)
mood--; else
mood++; age++;
hunger=hunger++;
thirst=thirst++;
}
// 各个数值的输出函数 inline void pet::show()
{
<<endl;
cout<< 现在的状态: <<age; 年龄:cout<<
<<hunger; cout<< 饥饿度: <<thirst; 口渴度:cout<<
<<mood; cout<< 心情指数: <<health;
健康指数:cout<< }
各种特殊状态函数// inline void
pet::emergency(int emg) {
step=step+5;
if(emg==20)
health--; if(hunger==3) {
mood--;
<<endl; 主人,我已经很饿 cout<< 了。}
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(thirst==2) {
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(hunger>6||thirst>5)
{
age=100;
cout<< 啊“!天呐,你降道雷劈了这个万恶的主人吧! ”
说完,某宠物口吐白沫, <<endl;
到底不起。 }
if(hunger>5&&thirst>4)
{
age=100;
剩余30页未读,继续阅读
资源评论
hhappy0123456789
- 粉丝: 60
- 资源: 5万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功