




版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、#include #include using namespace std;class pet /建立一個(gè)寵物類(lèi)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;構(gòu)造函數(shù)int geta() return age; / int geth() return hunger;提取各個(gè)私有成員int gett() return thirst;int getm() return mood;int gethe() return h
2、ealth;int getst() return step;void p2(); /饑餓、口渴以及心情隨時(shí)間的變化函數(shù)void show(); /各個(gè)數(shù)值的輸出函數(shù)void emergency(int w); /各種特殊狀態(tài)函數(shù)void feed() /hunger-;step=step-5;喂食函數(shù)void drink() thirst-;step=step-3; /喂水函數(shù)void doctor() step=step-10; /看醫(yī)生函數(shù)void touch(int w); /撫摸函數(shù)void fun(int w); /玩耍函數(shù)virtual int getl() return age;
3、 /提取壽命值virtual void action(int act,int w,int emg) /主人采取各種動(dòng)作函數(shù),定義為純虛函數(shù)private:int age; /年齡int hunger; /饑餓值int thirst; /口渴值int mood; /心情指數(shù)int health; /健康指數(shù)int step; /行動(dòng)點(diǎn)數(shù);inline void pet:p2() /饑餓、口渴以及心情隨時(shí)間的變化函數(shù) int m;m=rand()%15;if(m5)mood=mood-2;else if(m12)mood-;elsemood+;age+;hunger=hunger+;thirst=
4、thirst+; inline void pet:show() /各個(gè)數(shù)值的輸出函數(shù)cout 現(xiàn)在的狀態(tài) :endl;cout 年齡 :age;cout饑餓度 :hunger;cout口渴度 :thirst;cout心情指數(shù) :mood;cout健康指數(shù) :health; inline void pet:emergency(int emg) /step=step+5;if(emg=20)health-;if(hunger=3)mood-;各種特殊狀態(tài)函數(shù)cout 主人,我已經(jīng)很餓了。if(hunger=-2)mood-;endl;cout3)endl;mood=mood-2;health-;c
5、out 再不給我吃東西,我就要餓死啦endl;if(hunger-2)mood=mood-2;health-;cout 再給我吃東西,我就要撐死啦endl;if(thirst=2)mood-;cout 這天好熱啊,主人,給口喝的吧。endl;if(thirst=-2)mood-;cout 面對(duì)著一大杯水,你的寵物惡心地說(shuō)道: “主人,我已經(jīng)喝夠了?!?2)mood=mood-2;health-;cout 偉大的主人在上,我已經(jīng)渴的快受不鳥(niǎo)啦。endl;if(thirst-2)mood=mood-2;health-;cout 好吧,我都喝撐的都吃不下飯了。6|thirst5)age=100;co
6、ut “啊天吶,你降道雷劈了這個(gè)萬(wàn)惡的主人吧”說(shuō)完,某寵物口吐白沫,到底不起。 5&thirst4)age=100;cout 如果有來(lái)世的話(huà),打死我也不跟你混了。endl;if(health-6)age=100;cout 你骨瘦如柴的寵物最后飽含深情地看了你一眼,緩緩倒下了。endl;inline void pet:touch(int w) /step=step-3;switch(w)case 0:mood=mood+2;break;case 1:mood+;break;case 2:mood+;break;case 3:mood-;thirst-;break;case 4:mood-;撫摸函
7、數(shù)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+;玩耍函數(shù)thirst+;health+;break;void instruction() /飼養(yǎng)說(shuō)明cout 飼養(yǎng)說(shuō)明 :endl;cout 每個(gè)時(shí)間段作為主人的你新增5 點(diǎn)行動(dòng)點(diǎn),未用完可以累積到下一時(shí)段,初始有 20 點(diǎn)。
8、endl;cout 當(dāng)行動(dòng)點(diǎn)相當(dāng)?shù)蜁r(shí),出現(xiàn)bad end ,飼養(yǎng)結(jié)束。 endl;cout 每天有三個(gè)時(shí)間段,你可以進(jìn)行 5 項(xiàng)操作,喂食、喂水、撫摸、玩耍、不做任何事。 endl;cout 行動(dòng)點(diǎn)對(duì)應(yīng)消耗 : 喂食 5 點(diǎn),喂水 3 點(diǎn),撫摸 3 點(diǎn),玩耍 8 點(diǎn)。endl;cout 選擇不做任何事,則跳到下一時(shí)間段。endl;cout 當(dāng)饑餓與口渴相當(dāng)?shù)偷臅r(shí)候,或者健康指數(shù)相當(dāng)?shù)偷臅r(shí)候,會(huì)出現(xiàn)badend,寵物死亡。 endl;cout 當(dāng)寵物年齡到達(dá)壽命極限時(shí),出現(xiàn)happy end ,寵物壽終正寢。endl;coutPS: 不同的天氣對(duì)寵物的心情和健康又影響。endl;cout 在不同
9、天氣中進(jìn)行撫摸玩耍會(huì)有特殊情況發(fā)生,請(qǐng)注意。 endl; cout-endl;class rabbit:virtual public pet /petpublic:rabbit(int l=31)life=l;int getl()return life;類(lèi)派生的兔子類(lèi)void action(int act,int w,int emg); /主人對(duì)小牛的動(dòng)作函數(shù),虛函數(shù)成員 private:int life; /兔子的壽命;inline void rabbit:action(int act,int w,int emg)switch(act)case 0:instruction();break;c
10、ase 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 /petpublic:horse(int l=41)life=l;類(lèi)派生的小馬駒類(lèi)int getl()return life;void action(int act,int w,int emg); /主人對(duì)小牛的動(dòng)作函數(shù),虛函數(shù)成員private:int life; /小馬的壽命;inlin
11、e void horse: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;case 5:break;case 6:emg=0;doctor();break;class calf:virtual public pet /petpublic:calf(int l=51) life=l;int getl()return life;類(lèi)派生的小牛類(lèi)void
12、 action(int act,int w,int emg); /主人對(duì)小牛的動(dòng)作函數(shù),虛函數(shù)成員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;case 5:break;case 6:emg=0;doctor();break;void petshop(int s
13、elect) /switch(select)case 1:寵物外形cout 恭喜,你已經(jīng)領(lǐng)養(yǎng)了一只兔子。 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、恭喜,你已經(jīng)領(lǐng)養(yǎng)了一匹小馬駒。 endl; cout-endl;cout %_,_, endl;cout %-*/./ endl;cout %-* / *. endl;cout %* . ,-; endl;cout %* : O endl;cout %* : *. endl;cout %* *. -, * endl;cout %* .*-.- *. endl;cout %* : *-. (,; endl;cout %* : *.-.* endl;cout %* ; endl;cout-endl;break;case 3:cout 恭喜,你已經(jīng)領(lǐng)養(yǎng)了一頭小牛犢。 endl; cout-endl;
15、cout / / endl;cout / / / / endl;cout | |_| | endl;cout / / endl;cout /-_| / / |_- endl;cout / = /| | O| |O | |/ = / endl;cout -_- | |_-+-+-_| | -_- endl;cout |/ /| endl;cout / / endl;cout ( O O ) endl;cout / ./ endl;cout -_-| endl;cout | |/_/| | endl;cout | |/| |endl;cout | / |endl;cout | | | |endl;
16、cout | | | |endl;cout-endl;break;void period(int t) /t=t%3;switch(t)時(shí)間函數(shù)case 0:cout上午。 endl;break;case 1:cout下午。 endl;break;case 2:cout;晚上。 endl;break;int weather() /int w;w=rand()%5;switch(w)天氣函數(shù)case 0:cout天氣 : 晴。 endl;break;case 1:cout天氣 : 陰。 endl;break;case 2:cout天氣 : 小雨。 endl;break;case 3:cout天氣
17、 : 暴雨。 endl;break;case 4:cout天氣 : 大風(fēng)。 getl(); /提取壽命for(date=1;datelife;date+) /開(kāi)始飼養(yǎng),如無(wú)意外,則到壽命時(shí)循環(huán)結(jié)束cout 今天是你領(lǐng)養(yǎng)第 date 日p2(); /調(diào)用饑餓、口渴以及心情隨時(shí)間的變化函數(shù)while(t3) /控制時(shí)間的循環(huán)emg=rand()%20; /emg 為隨機(jī)數(shù),控制是否生病coutendl;cout 現(xiàn)在是 ;period(t); /調(diào)用時(shí)間函數(shù)cout-endl;coutgetst(); /提取行動(dòng)點(diǎn)數(shù)cout 你的行動(dòng)點(diǎn)數(shù)還有 :Nstependl;coutshow(); /調(diào)用數(shù)
18、值輸出函數(shù)if(emg-19)=1)cout健康狀況 : 生病 endl;elsecout健康狀況 : 良好 endl;cout 請(qǐng)選擇你想做的事 :endl;cout0 、參看說(shuō)明 1 、喂食 2 、喂水 3 、撫摸 4 、逗它玩耍 5 、不做任何事 ;if(emg-19)=1)cout 6 、看醫(yī)生。 endl;elsecoutendl;coutact;cout-action(act,w,emg); /調(diào)用主人動(dòng)作函數(shù)while(act+1)%6);petx-emergency(emg); /調(diào)用特殊狀態(tài)函數(shù)Nage=petx-geta(); /提取年齡if(Nagelife)cout-endl;cout 很遺憾,由于飼養(yǎng)不善,你的寵物已經(jīng)死亡。endl;cout-endl;break; /非正常死亡, bad endif(Nstep0)cout-endl;cout 真不幸,寵物的飼養(yǎng)已經(jīng)讓你感到心力交瘁。endl;cout 看來(lái)你和它共同的生活要就此告一段落了。endl;cout 唉,你的修行還未夠班啊,繼續(xù)努力吧。endl;cout-endl;break; /非正常結(jié)束飼養(yǎng), bad endt+;cout-life|Nstep0)break; /非正常死亡,跳出循環(huán)system(c
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 合作聯(lián)營(yíng)協(xié)議合同范本
- 創(chuàng)建積極工作氛圍的年度計(jì)劃
- 腦梗死的護(hù)理目標(biāo)
- 完善水務(wù)責(zé)任追究機(jī)制計(jì)劃
- 塑造強(qiáng)大品牌形象的成功秘笈計(jì)劃
- 秘書(shū)職能的社會(huì)認(rèn)知提升計(jì)劃
- 廣東省廉江市實(shí)驗(yàn)學(xué)校高中政治 3.2 樹(shù)立正確的消費(fèi)觀2教學(xué)實(shí)錄(必修1)
- 2025年荊州貨運(yùn)從業(yè)資格證模擬考試題庫(kù)
- 2025年高中化學(xué)40個(gè)化學(xué)實(shí)驗(yàn)反應(yīng)的動(dòng)圖太神奇了
- 第3課+中古時(shí)期的歐洲高中歷史統(tǒng)編版(2019)必修中外歷史綱要下冊(cè)
- 人教版五年級(jí)數(shù)學(xué)下冊(cè)第二單元練習(xí)題
- 酒店傳染病防控緊急預(yù)案
- 《研學(xué)旅行課程設(shè)計(jì)》課件-制訂研學(xué)課程目標(biāo)
- 2024年3月河北省定向選調(diào)生面試題及參考答案
- 混合采訪(fǎng)區(qū)預(yù)案
- 2023年北京重點(diǎn)校初二(下)期中數(shù)學(xué)試卷匯編:一次函數(shù)
- GA/T 2015-2023芬太尼類(lèi)藥物專(zhuān)用智能柜通用技術(shù)規(guī)范
- HGT 4095-2023 化工用在線(xiàn)氣相色譜儀 (正式版)
- 新華DCS軟件2.0版使用教程-文檔資料
- 2024臨床免疫學(xué)定性檢驗(yàn)程序性能驗(yàn)證指南
- 健康體檢報(bào)告分析結(jié)果
評(píng)論
0/150
提交評(píng)論