




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
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) /構(gòu)造函數(shù)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 hea
2、lth;int getst() return step;void p2(); /饑餓、口渴以及心情隨時間的變化函數(shù) void show(); /各個數(shù)值的輸出函數(shù)void emergency(int w); /各種特殊狀態(tài)函數(shù)void feed() /喂食函數(shù)hunger-;step=step-5;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) /主人采取各種動作函數(shù),定義為純虛函數(shù) private:int age; /年齡int hunger; /饑餓值int thirst; /口渴值int mood; /心情指數(shù)int health; /健康指數(shù)int step; /行動點數(shù);inline void pet:p2() /饑餓、口渴以及心情隨時間的變化函數(shù)int m;m=rand()%15;if(m5)mood=mood-2;else if(m12)mood-;elsemood+;age+;hunger=hunger+;thirst=t
4、hirst+;inline void pet:show() /各個數(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) /各種特殊狀態(tài)函數(shù)step=step+5;if(emg=20)health-;if(hunger=3)mood-;cout主人,我已經(jīng)很餓了。endl;if(hunger=-2)mood-;cout主人,我已經(jīng)很飽了。3)mood=mood-2;health-;cout
5、再不給我吃東西,我就要餓死啦!endl;if(hunger-2)mood=mood-2;health-;cout再給我吃東西,我就要撐死啦!endl;if(thirst=2)mood-;cout這天好熱啊,主人,給口喝的吧。endl;if(thirst=-2)mood-;cout面對著一大杯水,你的寵物惡心地說道:“主人,我已經(jīng)喝夠了?!?)mood=mood-2;health-;cout偉大的主人在上,我已經(jīng)渴的快受不鳥啦。endl;if(thirst-2)mood=mood-2;health-;cout好吧,我都喝撐的都吃不下飯了。6|thirst5)age=100;cout“?。√靺?,你
6、降道雷劈了這個萬惡的主人吧!”說完,某寵物口吐白沫,到底不起。5&thirst4)age=100;cout如果有來世的話,打死我也不跟你混了。endl;if(health-6)age=100;cout你骨瘦如柴的寵物最后飽含深情地看了你一眼,緩緩倒下了。endl;inline void pet:touch(int w) /撫摸函數(shù)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-;hunger-;br
7、eak;inline void pet:fun(int w) /玩耍函數(shù)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+;health+;break; void instruction() /飼養(yǎng)說明cout飼養(yǎng)說明:endl;cout每個時間段作為主人的你新增5點行動點,未用完可以累積到下一時段,初始有20點。endl;cout當行動點相當?shù)蜁r
8、,出現(xiàn)bad end,飼養(yǎng)結(jié)束。endl;cout每天有三個時間段,你可以進行5項操作,喂食、喂水、撫摸、玩耍、不做任何事。endl;cout行動點對應(yīng)消耗:喂食5點,喂水3點,撫摸3點,玩耍8點。endl;cout選擇不做任何事,則跳到下一時間段。endl;cout當饑餓與口渴相當?shù)偷臅r候,或者健康指數(shù)相當?shù)偷臅r候,會出現(xiàn)bad end,寵物死亡。endl;cout當寵物年齡到達壽命極限時,出現(xiàn)happy end,寵物壽終正寢。endl;coutPS:不同的天氣對寵物的心情和健康又影響。endl;cout在不同天氣中進行撫摸玩耍會有特殊情況發(fā)生,請注意。endl;cout-endl;clas
9、s rabbit:virtual public pet /pet類派生的兔子類public:rabbit(int l=31) life=l;int getl() return life;void action(int act,int w,int emg); /主人對小牛的動作函數(shù),虛函數(shù)成員private:int life; /兔子的壽命;inline void rabbit:action(int act,int w,int emg) switch(act)case 0:instruction();break;case 1:feed();break;case 2:drink();break;c
10、ase 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); /主人對小牛的動作函數(shù),虛函數(shù)成員private:int life; /小馬的壽命;inline void horse:action(int act,int w,int e
11、mg) 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 /pet類派生的小牛類public:calf(int l=51) life=l;int getl() return life;void action(int act,int w,int emg); /主人對小
12、牛的動作函數(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 select) /寵物外形switch(select)case 1:cou
13、t恭喜,你已經(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恭喜,你已經(jīng)領(lǐng)養(yǎng)了一匹小馬駒。endl;cout-endl;
14、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;cout / / endl; cout / / /
15、/ 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; cout |
16、| | | endl;cout-endl;break;void period(int t) /時間函數(shù)t=t%3;switch(t)case 0:cout上午。endl;break;case 1:cout下午。endl;break;case 2:cout晚上。endl;break;int weather() /天氣函數(shù)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
17、 4:cout天氣:大風(fēng)。getl(); /提取壽命for(date=1;datelife;date+) /開始飼養(yǎng),如無意外,則到壽命時循環(huán)結(jié)束cout今天是你領(lǐng)養(yǎng)第date日p2(); /調(diào)用饑餓、口渴以及心情隨時間的變化函數(shù)while(t3) /控制時間的循環(huán)emg=rand()%20; /emg為隨機數(shù),控制是否生病coutendl;cout現(xiàn)在是; period(t); /調(diào)用時間函數(shù)cout-endl;coutgetst(); /提取行動點數(shù)cout你的行動點數(shù)還有:Nstependl; coutshow(); /調(diào)用數(shù)值輸出函數(shù)if(emg-19)=1)cout 健康狀況:生病e
18、ndl;elsecout 健康狀況:良好endl;cout請選擇你想做的事:endl; cout0、參看說明 1、喂食 2、喂水 3、撫摸 4、逗它玩耍 5、不做任何事;if(emg-19)=1)cout 6、看醫(yī)生。endl;elsecoutendl; coutact;cout-action(act,w,emg); /調(diào)用主人動作函數(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看來你和它共同的生活要就此告一段落了。endl;cout唉,你的修行還未夠班啊,繼續(xù)努力吧。endl;cout-endl;break; /非正常結(jié)束飼養(yǎng),bad end t+;cout-life|Nstep0)break; /非正常死亡,跳出
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 村里協(xié)議書范本模板
- 2025年03月安徽省地震局公開招聘事業(yè)單位博士學(xué)位工作人員筆試歷年典型考題(歷年真題考點)解題思路附帶答案詳解
- 2025年03月四川成都市青羊區(qū)總工會公開招聘工會社會工作者2人筆試歷年典型考題(歷年真題考點)解題思路附帶答案詳解
- 中級電子商務(wù)設(shè)計師-2019年下半年(下午)《電子商務(wù)設(shè)計師》案例分析真題
- 云南省昆明市祿勸縣第一中學(xué)2025年高三下學(xué)期期末調(diào)研考試歷史試題含解析
- 廣西中醫(yī)藥大學(xué)賽恩斯新醫(yī)藥學(xué)院《蒙臺梭利教學(xué)法》2023-2024學(xué)年第二學(xué)期期末試卷
- 吉林電子信息職業(yè)技術(shù)學(xué)院《生命應(yīng)急救護》2023-2024學(xué)年第二學(xué)期期末試卷
- 江蘇省揚州市江都區(qū)實驗初級中學(xué)2025屆中考英語試題命題比賽模擬試卷(1)含答案
- 浙江省選考十校聯(lián)盟2025屆高三下學(xué)期第三次考試數(shù)學(xué)試題試卷含解析
- 甘肅省甘南藏族自治州碌曲縣2024-2025學(xué)年數(shù)學(xué)五下期末復(fù)習(xí)檢測試題含答案
- 旋挖鉆機基坑支護工程施工隱患排查治理清單
- 空調(diào)維保質(zhì)量保障體系及措施方案
- 平面向量在三角函數(shù)中的應(yīng)用(學(xué)案)
- 中藥的道地藥材課件
- 《跋傅給事帖》2020年浙江嘉興中考文言文閱讀真題(含答案與翻譯)
- 幼兒園《3-6歲兒童學(xué)習(xí)與發(fā)展指南》健康領(lǐng)域知識試題及答案
- 國家職業(yè)技能標準 (2021年版) 嬰幼兒發(fā)展引導(dǎo)員
- 幼兒園小班科學(xué):《小雞和小鴨》 PPT課件
- 伯努利方程-ppt課件
- 年產(chǎn)20噸阿齊沙坦原料藥生產(chǎn)車間的設(shè)計和實現(xiàn)材料學(xué)專業(yè)
- 電子公章模板
評論
0/150
提交評論