C程序设计电子宠物

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

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

1、 i o s t r e#in elude using n amespace std; class pet/建立一个宠物类public:pet(i nt a=0,i nt h=0,i nt t=0,i nt m=0,i nt he=0,i nt st=15) age=a;hu nger=h;thirst=t;mood=m;health=he;step=st; int geta() retur n age;/构造函数/提取各个私有成员int geth() retur n hun ger;int gett() retur n thirst;int getm() return mood;int ge

2、the() retur n health;int getst() return step;void p2();void show();void emerge ncy(i nt w);void feed()hun ger-;step=step-5;void dri nk() thirst-;step=step-3;void doctor() step=step-10;void touch(i nt w);void fun (i nt w);virtual int getl() retur n age;饥饿、口渴以及心情随时间的变化函数/各个数值的输岀函数/各种特殊状态函数/喂食函数/喂水函数/看

3、医生函数/抚摸函数玩耍函数/提取寿命值virtual void acti on (i nt act,i nt w,i nt emg) /主人采取各种动作函数,定义为纯虚函数private:int age;int hun ger;int thirst;int mood;int health;int step;in li ne void pet:p2() int m;/年龄/饥饿值/口渴值心情指数/健康指数/行动点数/饥饿、口渴以及心情随时间的变化函数m=ra nd()%15; if(m5)mood=mood-2;else if(m12) mood-;elsemood+;age+;hun ger=

4、hu nger+; thirst=thirst+;/各个数值的输岀函数in li ne void pet:show()cout现在的状态:endl; cout年龄:age;饥饿度:hu nger; 口渴度:thirst; 心情指数:mood; 健康指数:health;COUtvvCOUtCOUtCOUtin li ne void pet:emerge ncy(i nt emg) step=step+5;/各种特殊状态函数if(emg=20)health-;if(hu nger=3)mood-;coutvv主人,我已经很饿了e ndl;if(hu nger=-2)mood-;coutvv主人,我

5、已经很饱了3)mood=mood-2;health-;coutvv再不给我吃东西,我就要饿死啦!e ndl;if(hu ngerv-2)mood=mood-2;health-;coutvv再给我吃东西,我就要撑死啦!if(thirst=2)e ndl;mood-;if(thirst=-2)mood-;cout面对着一大杯水,你的宠物恶心地说道:主人,我已经喝够了。” 2)mood=mood-2;health-;coutvv伟大的主人在上,我已经渴的快受不鸟啦。endl;if(thirst-2)mood=mood-2;health-;coutvv好吧,我都喝撑的都吃不下饭了。6|thirst5)

6、age=100;vve ndl;coutvv啊!天呐,你降道雷劈了这个万恶的主人吧!”说完,某宠物口吐白沫,到底不起。if(hu nger5&thirst4)age=100;coutvv如果有来世的话,打死我也不跟你混了。endl;if(healthv-6)age=100;coutvv你骨瘦如柴的宠物最后饱含深情地看了你一眼,缓缓倒下了。vvendl;in li ne void pet:touch(i nt w)/ 抚摸函数step=step-3;switch(w)case 0:mood=mood+2;break;case 1:mood+;break;case 2: mood+;break;c

7、ase 3:mood-;thirst-;break;case 4:mood-;hun ger-;break;in li ne void pet:fu n(i nt w)/ 玩耍函数step=step-8;switch(w)case 0:mood=mood+2;break;case 2:hun ger+;thirst+;health+;break;case 3:hun ger=hu nger+2;thirst+;health+;break;case 4:hun ger+;thirst+;health+;break;void in structio n()/ 饲养说明cout饲养说明:endl;c

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

9、tPS :不同的天气对宠物的心情和健康又影响。endl;coutvv在不同天气中进行抚摸玩耍会有特殊情况发生,请注意。endl;coute ndl;class rabbit:virtual public pet/pet 类派生的兔子类public:rabbit(i nt l=31)life=l;in t getl()return life;void actio n(int act,i nt w,i nt emg);/主人对小牛的动作函数,虚函数成员private:int life;/兔子的寿命;in li ne void rabbit:acti on (i nt act,i nt w,i nt

10、 emg)switch(act)case 0:in structi on() ;break;case 1:feed();break;case 2:drin k();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(i nt l=41)life=l;in t getl()return life;void actio n(int act,i nt w,i nt

11、 emg);/主人对小牛的动作函数,虚函数成员private:int life;小马的寿命;in li ne void horse:acti on (i nt act,i nt w,i nt emg)switch(act)case 0:in structi on() ;break;case 1:feed();break;case 2:drin k();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

12、 类派生的小牛类public:calf(i nt l=51) life=l;in t getl()return life;void actio n(int act,i nt w,i nt emg);/主人对小牛的动作函数,虚函数成员private:int life;/小牛的寿命;in li ne void calf:acti on (i nt act,i nt w,i nt emg)switch(act)case 0:in structi on() ;break;case 1:feed();break;case 2:drin k();break;case 3:touch(w);break;case 4:fun( w);break;case 5:break;case 6:emg=0;doctor();break;void petshop(i nt select)/ 宠物外形switch(select)case 1:cout恭喜,你已经领养了一只兔子。endl;Coute ndl;Cout1* *1)

展开阅读全文
相关资源
相关搜索

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

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