


版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、#include<iostream>#include<stdlib.h>usingnamespacestd;classpet(/建立一個寵物類public:pet(inta=0,inth=0,intt=0,intm=0,inthe=0,intst=15)/構(gòu)造函數(shù)age=a;hunger=h;thirst=t;mood=m;health=he;step=st;intgeta()returnage;/提取各個私有成員intgeth()returnhunger;intgett()returnthirst;intgetm()returnmood;intgethe()retur
2、nhealth;intgetst()returnstep;voidp2();voidshow();voidemergency(intw);voidfeed()hunger-;step=step-5;/饑餓、口渴以及心情隨時間的變化函數(shù)/各個數(shù)值的輸出函數(shù)/各種特殊狀態(tài)函數(shù)/喂食函數(shù)voiddrink()thirst-;step=step-3;voiddoctor()step=step-10;voidtouch(intw);voidfun(intw);virtualintgetl()returnage;virtualvoidaction(intact,intw,intemg)數(shù)/喂水函數(shù)/看醫(yī)生
3、函數(shù)/撫摸函數(shù)/玩要函數(shù)/提取壽命值/主人采取各種動作函數(shù),定義為純虛函private:intage;inthunger;intthirst;intmood;inthealth;intstep;/年齡/饑餓值/口渴值/心情指數(shù)/健康指數(shù)/行動點(diǎn)數(shù)inlinevoidpet:p2()/饑餓、口渴以及心情隨時間的變化函數(shù)intm;m=rand()%15;if(m<5)mood=mood-2;elseif(m<12)mood-;elsemood+;age+;hunger=hunger+;thirst=thirst+;inlinevoidpet:show()/各個數(shù)值的輸出函數(shù)cout&l
4、t;<"現(xiàn)在的狀態(tài):"<<endl;cout<<"年齡:"<<age;cout<<"饑餓度:"<<hunger;cout<<"口渴度:"<<thirst;cout<<"心情指數(shù):"<<mood;cout<<"健康指數(shù):"<<health;/各種特殊狀態(tài)函數(shù)inlinevoidpet:emergency(intemg)step=step+5;
5、if(emg=20)health-;if(hunger=3)mood-;cout<<"主人,我已經(jīng)很餓"<<endl;if(hunger=-2)mood-;cout<<"主人,我已經(jīng)很飽"<<endl;if(hunger>3)mood=mood-2;if(hunger<-2)(mood=mood-2;health-;if(thirst=2)(mood-;cout<<"這天好熱啊,主人,給口喝的吧。"<<endl;if(thirst=-2)(mood-;
6、cout<<"面對著一大杯水,你的寵物惡心地說道:“主人,我已經(jīng)喝夠了?!?quot;<<endl;if(thirst>2)(mood=mood-2;health-;cout<<"偉大的主人在上,我已經(jīng)渴的快受不鳥啦。"<<endl;if(thirst<-2)(mood=mood-2;health-;cout<<"好吧,我都喝撐的都吃不下飯了。"<<endl;if(hunger>6|thirst>5)(age=100;cout<<&quo
7、t;啊“!天吶,你降道宙劈了這個萬惡的主人吧!”說完,某寵物口吐白沫,到底不起。"<<endl;if(hunger>5&&thirst>4)(age=100;cout<<"如果有來世的話,打死我也不跟你混了。"<<endl;if(health<-6)(age=100;inlinevoidpet:touch(intw)撫摸函數(shù)(step=step-3;switch(w)(case0:mood=mood+2;break;case1:mood+;break;case2:mood+;break;case
8、3:mood-;thirst-;break;case4:mood-;hunger-;break;inlinevoidpet:fun(int/玩要函數(shù)w)(step=step-8;switch(w)(case0:mood=mood+2;break;case2:hunger+;thirst+;health+;break;hunger=hunger+2;thirst+;health+;break;case4:hunger+;thirst+;health+;break;voidinstruction()/飼養(yǎng)說明(cout<<"飼養(yǎng)說明:"<<endl;co
9、ut<<"每個時間段作為主人的你新增有20點(diǎn)。"<<endl;5點(diǎn)行動點(diǎn),未用完可以累積到下一時段,初始cout<<"當(dāng)行動點(diǎn)相當(dāng)?shù)蜁r,出現(xiàn)badend,飼養(yǎng)結(jié)束。"<<endl;cout<<"每天有三個時間段,你可以進(jìn)行5項(xiàng)操作,喂食、喂水、撫摸、玩耍、不做任何事。"<<endl;cout<<"行動點(diǎn)對應(yīng)消耗:喂食5點(diǎn),喂水3點(diǎn),撫摸3點(diǎn),玩要8點(diǎn)。"<<endl;cout<<"選擇不做任何事,則
10、跳到下一時間段。"<<endl;cout<<"當(dāng)饑餓與口渴相當(dāng)?shù)偷臅r候,或者健康指數(shù)相當(dāng)?shù)偷臅r候,會出現(xiàn)badend,寵物死亡。"<<endl;cout<<"當(dāng)寵物年齡到達(dá)壽命極限時,出現(xiàn)happyend,寵物壽終正寢。cout<<"PS:不同的天氣對寵物的心情和健康乂影響。"<<endl;cout<<"在不同天氣中進(jìn)行撫摸玩要會有特殊情況發(fā)生,請注意。"<<endl;cout<<"<<
11、endl;"<<endl;classrabbit:virtualpublicpet(public:rabbit(intl=31)(life=l;intgetl()(returnlife;voidaction(intact,intw,intemg);private:/pet類派生的兔子類/主人對小牛的動作函數(shù),虛函數(shù)成員intlife;/兔子的壽命;inlinevoidrabbit:action(intact,intw,intemg)(switch(act)(case0:instruction();break;case1:feed();break;case2:drink()
12、;break;case3:touch(w);break;case4:fun(w);break;case5:break;case6:emg=0;doctor();break;classhorse:virtualpublicpet/類派生的小馬駒類petpublic:horse(intl=41)life=l;intgetl()returnlife;voidaction(intact,intw,intemg);private:returnlife;voidaction(intact,intw,intemg);private:voidaction(intact,intw,intemg);private
13、:/主人對小牛的動作函數(shù),虛函數(shù)成員inlinevoidhorse:action(intact,intw,intemg)(switch(act)(case0:instruction();break;feed();break;case2:drink();break;case3:touch(w);break;case4:fun(w);break;case5:break;case6:emg=0;doctor();break;classcalf:virtualpublicpet/類派生的小牛類petpublic:calf(intl=51)life=l;intgetl()returnlife;voida
14、ction(intact,intw,intemg);主人對小牛的動作函數(shù),虛函數(shù)成員private:intlife;小牛的壽命;inlinevoidcalf:action(intact,intw,intemg)switch(act)case0:instruction();break;case1:feed();break;case2:drink();break;case3:touch(w);break;case4:fun(w);break;break;case6:emg=0;doctor();break;voidpetshop(intselect)/寵物外形switch(select)case1
15、:cout<<”恭喜,你已經(jīng)領(lǐng)養(yǎng)了一只兔子。"<<endl;cout<<”"<<endl;cout<<"-*_*,"<<endl;cout<<"("<<endl;cout<<")_.-._"<<endl;cout<<"_)/,*,*"<<end*cout<<",.*|;-.*土c"<<endcout<&l
16、t;"*Q|,l;"<<endl;*cout<<"(Y(;*."<<endl;cout<<"*-.,;"<<endl;cout<<"(_,*,-*_,*_,*"<<endl;cout<<"(_,-(,-*"<<endl;cout<<""<<endl;break;case2:cout<<"恭喜,你已經(jīng)領(lǐng)養(yǎng)了一匹小馬駒。&quo
17、t;<<endl;cout<<""<<endl;cout<<%_,_,"<<endl;cout<<"%-*/./"<<endl;cout<<"%/*-*"<<endl;cout<<"%.,-%*"<<endl;cout<<"%*:O"<<endl;cout<<"%*:*."<<endl;c
18、out<<"%*.*-."<<endl;cout<<"%*.*-.-*."<<endl;cout<<"%*:*-.(,;"<<endl;cout<<"%*:*.-.*"<<endl;cout<<"%*;"<<endl;cout<<"-"<<endl;break;case3:cout<<"恭喜,你已經(jīng)領(lǐng)養(yǎng)了一頭小牛
19、犢。"<<endl;cout<<"-"<<endl;cout<<"/"<<endl;cout<<"/"<<endl;cout<<"|"<<endl;cout<<"/"<<endl;cout<<"/_|/|_"<<endl;cout<<"/=/|O|O|/=/"<<end
20、l;cout<<"-_-|_-+-+-_|-_-"<<endl;cout<<"|/|"<<endl;cout<<"/"<<endl;cout<<"(OO)"<<endl;cout<<./-|I|/_/|II|/|I"<<endl;cout<<"<<endl;cout<<"<<endl;cout<<"
21、<<endl;cout<<""<<endl;cout<<""<<endl;cout<<""<<endl;cout<<""<<endl;break;/voidperiod(intt)/時間函數(shù)/t=t%3;switch(t)case0:cout<<"case1:cout<<"case2:cout<<"上午。"<<endl;b
22、reak;下午。"<<endl;break;晚上。"<<endl;break;intweather()intw;/天氣函數(shù)w=rand()%5;switch(w)case0:cout<<"天氣:case1:cout<<"天氣:case2:cout<<"天氣:case3:cout<<"天氣:case4:cout<<"天氣:晴。"<<endl;break;陰。"<<endl;break;小雨。"
23、;<<endl;break;暴雨。"<<endl;break;大風(fēng)。"<<endl;break;returnw;voidraise(intselect)(intlife,date,w,act;intt=0;intemg'Nstep'Nage;/動態(tài)建立對象,實(shí)現(xiàn)領(lǐng)養(yǎng)pet*petx;switch(select)(case1:petx=newrabbit;break;case2:petx=newhorse;break;case3:petx=newcalf;break;/提取壽命/開始飼養(yǎng),如無意外,則到壽命時循環(huán)結(jié)束/提取壽
24、命/開始飼養(yǎng),如無意外,則到壽命時循環(huán)結(jié)束life=petx->getl();for(date=1;date<life;date+)(cout<<"今天是你領(lǐng)養(yǎng)第w=weather();t=t%3;petx->p2();while(t<3)(emg=rand()%20;"<<date<<"日"<<endl;/調(diào)用天氣函數(shù)/t為控制時間整形/調(diào)用饑餓、口渴以及心情隨時間的變化函數(shù)/控制時間的循環(huán)/e為隨機(jī)數(shù),控制是否生病mgcout<<"<<endl;
25、cout<<"現(xiàn)在是"period(t);/調(diào)用時間函數(shù)cout<<""<<endl;cout<<endl;do(Nstep=petx->getst();cout<<"你的行動點(diǎn)數(shù)還有:cout<<"你的寵物"petx->show();/提取行動點(diǎn)數(shù)"<<Nstep<<endl;/調(diào)用數(shù)值輸出函數(shù)if(emg-19)=1)cout<<"健康狀況:生病"<<endl;
26、elsecout<<"健康狀況:良好"<<endl;cout<<"請選擇你想做的事:一_"<<endl;3、撫4、逗它玩5、不做任.'撞要cout<<"0、參看說明1、喂食2、喂水何事"if(emg-19)=1)cout<<"6、看醫(yī)生。"<<endl;elsecout<<endl;cout<<"請選擇:,.;"<<endl;/調(diào)用主人動作函數(shù)/調(diào)用特殊狀態(tài)函數(shù)/提取年
27、齡cin>>act;cout<<"petx->action(act,w,emg);while(act+1)%6);petx->emergency(emg);Nage=petx->geta();if(Nage>life)cout<<""<<endl;cout<<"很遺憾,由于飼養(yǎng)不善,你的寵物已經(jīng)死"<<endl;cout<<""<<endl;break;非正常死亡,badendif(Nstep<0)c
28、out<<"cout<<""<<endl;cout<<"真不幸,寵物的飼養(yǎng)已經(jīng)讓你感到心力交瘁。"<<endl;cout<<"看來你和它共同的生活要就此告一段落了。"<<endl;cout<<"唉,你的修行還未夠班啊,繼續(xù)努力吧。"<<endl;cout<<""<<endl;break;/非正常結(jié)束飼badend養(yǎng),t+;cout<<"
29、;"<<endl;if(Nage>life|Nstep<0)break;/非正常死亡,跳出循環(huán)system("cls");/調(diào)用系統(tǒng)清屏函數(shù)if(date=life)"<<endl;/正常死亡if(date=life)"<<endl;/正常死亡"<<endl;/正常死亡"<<endl;/正常死亡(cout<<"cout<<"恭喜,你的寵物已經(jīng)壽終正"<<endl;寢。intadopt()領(lǐng)養(yǎng)函數(shù),實(shí)現(xiàn)龍物的領(lǐng)養(yǎng)(intsel;intchi;charname10;c
溫馨提示
- 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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 提高公司財務(wù)團(tuán)隊(duì)服務(wù)水平的培訓(xùn)計劃
- 提升前臺溝通技巧的工作計劃
- 醫(yī)院財務(wù)管理優(yōu)化的策略與效果計劃
- 學(xué)習(xí)資源共享平臺建設(shè)計劃
- 《貴州創(chuàng)泰礦業(yè)有限公司修文縣龍場鎮(zhèn)高倉老二洞鋁鐵礦山礦產(chǎn)資源綠色開發(fā)利用方案(三合一)》專家組評審意見
- 第二單元課題2氧氣-教學(xué)設(shè)計-2024-2025學(xué)年九年級化學(xué)人教版上冊
- 2025年鎮(zhèn)江道路運(yùn)輸從業(yè)資格證模擬考試年新版
- 2025年湖州資格證模擬考試
- 2025年湖北貨車資格證考試題
- 2025年遼陽貨運(yùn)從業(yè)資格證模擬考試下載題
- 電廠應(yīng)急救援培訓(xùn)
- 2024-2030年中國建筑垃圾處理行業(yè)發(fā)展分析及投資規(guī)劃研究報告
- 心理測試課件教學(xué)課件
- 出生證警示教育培訓(xùn)
- 中小學(xué)生德育工作指南2022版
- 2024男性護(hù)膚市場趨勢洞察
- 部編版五年級語文上冊快樂讀書吧測試題及答案
- 通信工程建設(shè)標(biāo)準(zhǔn)強(qiáng)制性條文匯編(2023版)-定額質(zhì)監(jiān)中心
- 《現(xiàn)代家政導(dǎo)論》電子教案 4.2模塊四項(xiàng)目二家政教育發(fā)展認(rèn)知
- 現(xiàn)代家政導(dǎo)論-課件 5.2.2認(rèn)識我國家政服務(wù)業(yè)
- 物流園區(qū)倉儲管理手冊
評論
0/150
提交評論