C++程序设计电子宠物_第1页
C++程序设计电子宠物_第2页
C++程序设计电子宠物_第3页
C++程序设计电子宠物_第4页
C++程序设计电子宠物_第5页
已阅读5页,还剩9页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、最新 料推荐#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 geta() return age;/提取各个私有成员int geth() return hunger;int gett() return thirst;int getm() return mood;int gethe() retur

2、n 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;

3、/提取寿命值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()%15;if(m5)mood=mood-2;1最新 料推荐else if(m12)mood-;elsemood+;age+;hunger=hunger+;thirs

4、t=thirst+;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(emg=20)health-;if(hunger=3)mood-;cout 主人,我已经很饿了。endl;if(hunger=-2)mood-;cout 主人,我已经很饱了。3)mood=mood-2;heal

5、th-;cout 再不给我吃东西,我就要饿死啦!endl;if(hunger-2)mood=mood-2;health-;2最新 料推荐cout 再给我吃东西,我就要撑死啦!endl;if(thirst=2)mood-;cout 这天好热啊,主人,给口喝的吧。endl;if(thirst=-2)mood-;cout 面对着一大杯水,你的宠物恶心地说道:“主人,我已经喝够了。” 2)mood=mood-2;health-;cout 伟大的主人在上,我已经渴的快受不鸟啦。endl;if(thirst-2)mood=mood-2;health-;cout 好吧,我都喝撑的都吃不下饭了。6|thirs

6、t5)age=100;cout 啊“!天呐,你降道雷劈了这个万恶的主人吧!”说完,某宠物口吐白沫,到底不起。 5&thirst4)age=100;cout 如果有来世的话,打死我也不跟你混了。endl;if(health-6)age=100;cout 你骨瘦如柴的宠物最后饱含深情地看了你一眼,缓缓倒下了。endl;inline void pet:touch(int w)/抚摸函数3最新 料推荐step=step-3;switch(w)case 0:mood=mood+2;break;case 1:mood+;break;case 2:mood+;break;case 3:mood-;thirs

7、t-;break;case 4:mood-;hunger-;break;inline void pet:fun(int w)/ 玩耍函数step=step-8;switch(w)case 0:mood=mood+2;break;case 2:hunger+;thirst+;health+;break;case 3:hunger=hunger+2;thirst+;health+;break;case 4:hunger+;thirst+;4最新 料推荐health+;break;void instruction()/饲养说明cout 饲养说明: endl;cout 每个时间段作为主人的你新增5 点

8、行动点,未用完可以累积到下一时段,初始有 20 点。 endl;cout 当行动点相当低时,出现bad end,饲养结束。endl;cout 每天有三个时间段,你可以进行5 项操作,喂食、喂水、抚摸、玩耍、不做任何事。 endl;cout 行动点对应消耗:喂食5 点,喂水3 点,抚摸3 点,玩耍8 点。 endl;cout 选择不做任何事,则跳到下一时间段。endl;cout 当饥饿与口渴相当低的时候,或者健康指数相当低的时候,会出现bad end,宠物死亡。 endl;cout 当宠物年龄到达寿命极限时,出现happy end,宠物寿终正寝。endl;coutps :不同的天气对宠物的心情和

9、健康又影响。endl;cout 在不同天气中进行抚摸玩耍会有特殊情况发生,请注意。endl;cout-endl;class rabbit:virtual public pet/pet 类派生的兔子类public:rabbit(int l=31)life=l;int getl()return life;void action(int act,int w,int emg);/ 主人对小牛的动作函数,虚函数成员private:int life;/ 兔子的寿命;inline void rabbit:action(int act,int w,int emg)switch(act)case 0:5最新 料

10、推荐instruction();break;case 1:feed();break;case 2:drink();break;case 3:touch(w);break;case 4:fun(w);break;case 5:break;case 6:emg=0;doctor();break;class horse:virtual public pet/pet 类派生的小马驹类public:horse(int l=41)life=l;int getl()return life;void action(int act,int w,int emg);/ 主人对小牛的动作函数,虚函数成员private

11、:int life;/小马的寿命;inline void horse:action(int act,int w,int emg)switch(act)case 0:instruction();break;6最新 料推荐case 1:feed();break;case 2:drink();break;case 3:touch(w);break;case 4:fun(w);break;case 5:break;case 6:emg=0;doctor();break;class calf:virtual public pet/pet 类派生的小牛类public:calf(int l=51) life

12、=l;int getl()return life;void action(int act,int w,int emg);/ 主人对小牛的动作函数,虚函数成员private:int life;/ 小牛的寿命;inline void calf:action(int act,int w,int emg)switch(act)case 0:instruction();break;case 1:feed();break;case 2:drink();break;case 3:touch(w);break;case 4:fun(w);break;7最新 料推荐case 5:break;case 6:emg

13、=0;doctor();break;void petshop(int select)/宠物外形switch(select)case 1:cout 恭喜,你已经领养了一只兔子。endl;cout-endl;cout,-*,-*endl;cout(endl;cout) _.-._endl;cout_)/ ,*,*.endl;cout,*,-.*.endl;cout,*0*endl;cout(y(;*.endl;cout*-._,;endl;cout(_ ,-* ,-*_,*_,*endl;cout(_,- (_,-*endl;cout-endl;break;case 2:cout 恭喜,你已经领养

14、了一匹小马驹。endl;cout-endl;cout%_,_,endl;cout%-*/./endl;cout%-*/ *.endl;cout%*.,-;endl;8最新 料推荐cout%*:oendl;cout%*:*.endl;cout%*.-,*endl;cout%*.*-.-*.endl;cout%*:*-.(,;endl;cout%*:*.-.*endl;cout%*;endl;cout-endl;break;case 3:cout 恭喜,你已经领养了一头小牛犊。endl;cout-endl;cout/endl;cout/endl;cout|_|endl;cout/endl;cout

15、/-_|/|_-endl;cout/ = /| |o|o| |/ = /endl;cout-_- | |_-+-+-_| | -_-endl;cout|/|endl;cout/endl;cout(oo)endl;cout/./endl;cout-_-|endl;cout|/_/|endl;cout|/|9最新 料推荐endl;cout|/|endl;cout| |endl;cout| |endl;cout-endl;break;void period(int t)/时间函数t=t%3;switch(t)case 0:cout 上午。 endl;break;case 1:cout 下午。 end

16、l;break;case 2:cout 晚上。 endl;break;int weather()/ 天气函数int w;w=rand()%5;switch(w)case 0:cout 天气:晴。 endl;break;case 1:cout 天气:阴。 endl;break;case 2:cout 天气:小雨。 endl;break;case 3:cout 天气:暴雨。 endl;break;case 4:cout 天气:大风。 getl();/提取寿命for(date=1;datelife;date+)/ 开始饲养,如无意外,则到寿命时循环结束cout 今天是你领养第date 日 p2();

17、/ 调用饥饿、口渴以及心情随时间的变化函数while(t3)/ 控制时间的循环emg=rand()%20;/emg 为随机数,控制是否生病coutendl;cout 现在是 ;period(t);/调用时间函数cout-endl;coutgetst();/ 提取行动点数cout 你的行动点数还有:nstependl;coutshow();/ 调用数值输出函数if(emg-19)=1)cout健康状况:生病endl;elsecout健康状况:良好endl;cout 请选择你想做的事:endl;cout0 、参看说明1、喂食2、喂水3、抚摸4、逗它玩耍5、不做任何事 ;if(emg-19)=1)c

18、out 6 、看医生。 endl;11最新 料推荐elsecoutendl;coutact;cout-action(act,w,emg);/调用主人动作函数while(act+1)%6);petx-emergency(emg);/ 调用特殊状态函数nage=petx-geta();/ 提取年龄if(nagelife)cout-endl;cout 很遗憾,由于饲养不善,你的宠物已经死亡。endl;cout-endl;break;/非正常死亡, bad endif(nstep0)cout-endl;cout 真不幸,宠物的饲养已经让你感到心力交瘁。endl;cout 看来你和它共同的生活要就此告一段落了。endl;cout 唉,你的修行还未够班啊,继续努力吧。endl;cout-endl;break;/非正常结束饲养,bad endt+;cout-life|nstep0)break;/ 非正常死亡,跳出循环system(cls);/ 调用系统清屏函数if

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论