C++程序设计电子宠物

上传人:M****1 文档编号:562390273 上传时间:2024-01-27 格式:DOC 页数:27 大小:186.50KB
返回 下载 相关 举报
C++程序设计电子宠物_第1页
第1页 / 共27页
C++程序设计电子宠物_第2页
第2页 / 共27页
C++程序设计电子宠物_第3页
第3页 / 共27页
C++程序设计电子宠物_第4页
第4页 / 共27页
C++程序设计电子宠物_第5页
第5页 / 共27页
点击查看更多>>
资源描述

《C++程序设计电子宠物》由会员分享,可在线阅读,更多相关《C++程序设计电子宠物(27页珍藏版)》请在金锄头文库上搜索。

1、#include#includeusingnamespacestd;classpet/建立一个宠物类public:pet(inta=0,inth=0,intt=0,intm=0,inthe=0,intst=15)/构造函数age=a;hunger=h;thirst=t;mood=m;health=he;step=st;intgeta()returnage;/提取各个私有成员intgeth()returnhunger;intgett()returnthirst;intgetm()returnmood;intgethe()returnhealth;intgetst()returnstep;void

2、p2();voidshow();voidemergency(intw);voidfeed()hunger-;step=step-5;/饥饿、口渴以及心情随时间的变化函数/各个数值的输出函数/各种特殊状态函数/喂食函数voiddrink()thirst-;step=step-3;voiddoctor()step=step-10;voidtouch(intw);voidfun(intw);virtualintgetl()returnage;/喂水函数/看医生函数/抚摸函数/玩耍函数/提取寿命值virtualvoidaction(intact,intw,intemg)/主人采取各种动作函数,定义为纯

3、虚函private:intage;inthunger;intthirst;intmood;inthealth;intstep;/年龄/饥饿值/口渴值/心情指数/健康指数/行动点数inlinevoidpet:p2()inlinevoidpet:p2()/饥饿、口渴以及心情随时间的变化函数intm;m=rand()%15;if(m5)mood=mood-2;elseif(m3)mood=mood-2;inlinevoidpet:emergency(intemg)step=step+5;if(emg=20)health-;if(hunger=3)mood-;coutvv主人,我已经很饿了。if(hu

4、nger=-2)mood-;coutvv主人,我已经很饱了。if(hunger3)mood=mood-2;/各种特殊状态函数vvendl;vvendl;health-;health-;if(hunger2)mood=mood-2;health-;coutvv伟大的主人在上,我已经渴的快受不鸟啦。vvendl;if(thirstv-2)mood=mood-2;health-;coutvv好吧,我都喝撑的都吃不下饭了。vvendl;if(hunger6|thirst5)age=100;coutvv啊“!天呐,你降道雷劈了这个万恶的主人吧!”说完,某宠物口吐白沫,到底不起。vvendl;if(hun

5、ger5&thirst4)age=100;coutvv如果有来世的话,打死我也不跟你混了。vvendl;if(healthv-6)age=100;/抚摸函数/抚摸函数inlinevoidpet:touch(intw)step=step-3;switch(w)case0:mood=mood+2;break;case1:mood+;break;case2:mood+;break;case3:mood-;thirst-;break;case4:mood-;hunger-;break;/玩耍函数inlinevoidpet:fun(intw)step=step-8;switch(w)case0:mood

6、=mood+2;break;case2:hunger+;thirst+;health+;break;case3:hunger=hunger+2;thirst+;health+;break;case4:hunger+;thirst+;health+;break;voidinstruction。/饲养说明coutvv饲养说明:vvendl;coutvv每个时间段作为主人的你5点行动点,未用完可以累积到下一时段,初始新增有20点。vvendl;coutvv当行动点相当低时,出现badend,饲养结束。vvendl;coutvv每天有三个时间段,你可以进行5项操作,喂食、喂水、抚摸、玩耍、不做任何事o

7、vvendl;coutvv行动点对应消耗:喂食5点,喂水3点,抚摸3点,玩耍8点。vvendl;coutvv选择不做任何事,则跳到下一时间段。vvendl;coutvv当饥饿与口渴相当低的时候,或者健康指数相当低的时候,会出现badend,宠物死亡。vvendl;coutvv当宠物年龄到达寿命极限时,出现happyend,宠物寿终正vvendl;寝。coutvvPS:不同的天气对宠物的心情和健康又影响。vvendl;coutvv在不同天气中进行抚摸玩耍会有特殊情况发生,请注意。vvendl;coutvvvvendl;classrabbit:virtualpublicpetpublic:rabb

8、it(intl=31)life=l;/pet类派生的兔子类intgetl()returnlife;voidaction(intact,intw,intemg);private:/主人对小牛的动作函数,虚函数成员intlife;/兔子的寿命;inlinevoidrabbit:action(intact,intw,intemg)switch(act)case0:case1:feed();break;case2:drink();break;case3:touch(w);break;case4:fun(w);break;case5:break;case6:emg=0;doctor。;break;/类派

9、生的小马驹类petclasshorse:virtualpublicpetpublic:horse(intl=41)life=l;intgetl()returnlife;voidaction(intact,intw,intemg);private:/主人对小牛的动作函数,虚函数成员intlife;/小马的寿命;inlinevoidhorse:action(intact,intw,intemg)switch(act)case0:instruction();break;case1:feed();break;case2:drink();break;case3:touch(w);break;case4:

10、fun(w);break;case5:break;case6:emg=0;doctor();break;classcalf:virtualpublicpet/类派生的小牛类petpublic:calf(int1=51)life=l;intgetl()returnlife;虚函数成员voidaction(intact,intw,intemg);主人对小牛的动作函数,private:intlife;小牛的寿命;inlinevoidcalf:action(intact,intw,intemg)switch(act)case0:instruction();break;case1:feed();brea

11、k;case2:drink();break;case3:touch(w);break;case4:fun(w);break;case5:break;case6:emg=O;doctor。;break;voidpetshop(intselect)宠物外形switch(select)case1:coutvv恭喜,你已经领养了一只兔子。vvendl;vvendl;coutvv-vvendl;coutvv*厂5vvendl;coutvv(vvendl;coutvv)_.-vvendl;coutvv_)/,*,*vvendcoutvv5*l;*vvendcoutvv*50Il;vvendl;*coutvv(Y(;*5vvendl;coutvv*,vvendl;coutvv(_,-*vvendl;coutvv(,-(*vvendl;cou

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 活动策划

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号