C++程序設計電子寵物_第1頁
C++程序設計電子寵物_第2頁
C++程序設計電子寵物_第3頁
C++程序設計電子寵物_第4頁
C++程序設計電子寵物_第5頁
已閱讀5頁,還剩9頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

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)/ 構造函數(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() retur

2、n health;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;1最新 料推薦else if(m12)mood-;elsemood+;age+;hunger=hunger+;thirs

4、t=thirst+;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;heal

5、th-;cout 再不給我吃東西,我就要餓死啦!endl;if(hunger-2)mood=mood-2;health-;2最新 料推薦cout 再給我吃東西,我就要撐死啦!endl;if(thirst=2)mood-;cout 這天好熱啊,主人,給口喝的吧。endl;if(thirst=-2)mood-;cout 面對著一大杯水,你的寵物惡心地說道:“主人,我已經(jīng)喝夠了?!?2)mood=mood-2;health-;cout 偉大的主人在上,我已經(jīng)渴的快受不鳥啦。endl;if(thirst-2)mood=mood-2;health-;cout 好吧,我都喝撐的都吃不下飯了。6|thirs

6、t5)age=100;cout 啊“!天吶,你降道雷劈了這個萬惡的主人吧!”說完,某寵物口吐白沫,到底不起。 5&thirst4)age=100;cout 如果有來世的話,打死我也不跟你混了。endl;if(health-6)age=100;cout 你骨瘦如柴的寵物最后飽含深情地看了你一眼,緩緩倒下了。endl;inline void pet:touch(int w)/撫摸函數(shù)3最新 料推薦step=step-3;switch(w)case 0:mood=mood+2;break;case 1:mood+;break;case 2:mood+;break;case 3:mood-;thirs

7、t-;break;case 4:mood-;hunger-;break;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+;4最新 料推薦health+;break;void instruction()/飼養(yǎng)說明cout 飼養(yǎng)說明: endl;cout 每個時間段作為主人的你新增5 點

8、行動點,未用完可以累積到下一時段,初始有 20 點。 endl;cout 當行動點相當?shù)蜁r,出現(xiàn)bad end,飼養(yǎng)結束。endl;cout 每天有三個時間段,你可以進行5 項操作,喂食、喂水、撫摸、玩耍、不做任何事。 endl;cout 行動點對應消耗:喂食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 :不同的天氣對寵物的心情和

9、健康又影響。endl;cout 在不同天氣中進行撫摸玩耍會有特殊情況發(fā)生,請注意。endl;cout-endl;class 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:5最新 料

10、推薦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 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

11、:int life;/小馬的壽命;inline void horse:action(int act,int w,int emg)switch(act)case 0:instruction();break;6最新 料推薦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

12、=l;int getl()return life;void action(int act,int w,int emg);/ 主人對小牛的動作函數(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;7最新 料推薦case 5:break;case 6:emg

13、=0;doctor();break;void petshop(int select)/寵物外形switch(select)case 1:cout 恭喜,你已經(jī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)領養(yǎng)

14、了一匹小馬駒。endl;cout-endl;cout%_,_,endl;cout%-*/./endl;cout%-*/ *.endl;cout%*.,-;endl;8最新 料推薦cout%*:Oendl;cout%*:*.endl;cout%*.-,*endl;cout%*.*-.-*.endl;cout%*:*-.(,;endl;cout%*:*.-.*endl;cout%*;endl;cout-endl;break;case 3:cout 恭喜,你已經(jīng)領養(yǎng)了一頭小牛犢。endl;cout-endl;cout/endl;cout/endl;cout|_|endl;cout/endl;cout

15、/-_|/|_-endl;cout/ = /| |O|O| |/ = /endl;cout-_- | |_-+-+-_| | -_-endl;cout|/|endl;cout/endl;cout(OO)endl;cout/./endl;cout-_-|endl;cout|/_/|endl;cout|/|9最新 料推薦endl;cout|/|endl;cout| |endl;cout| |endl;cout-endl;break;void period(int t)/時間函數(shù)t=t%3;switch(t)case 0:cout 上午。 endl;break;case 1:cout 下午。 end

16、l;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 4:cout 天氣:大風。 getl();/提取壽命for(date=1;datelife;date+)/ 開始飼養(yǎng),如無意外,則到壽命時循環(huán)結束cout 今天是你領養(yǎng)第date 日 p2();

17、/ 調用饑餓、口渴以及心情隨時間的變化函數(shù)while(t3)/ 控制時間的循環(huán)emg=rand()%20;/emg 為隨機數(shù),控制是否生病coutendl;cout 現(xiàn)在是 ;period(t);/調用時間函數(shù)cout-endl;coutgetst();/ 提取行動點數(shù)cout 你的行動點數(shù)還有:Nstependl;coutshow();/ 調用數(shù)值輸出函數(shù)if(emg-19)=1)cout健康狀況:生病endl;elsecout健康狀況:良好endl;cout 請選擇你想做的事:endl;cout0 、參看說明1、喂食2、喂水3、撫摸4、逗它玩耍5、不做任何事 ;if(emg-19)=1)c

18、out 6 、看醫(yī)生。 endl;11最新 料推薦elsecoutendl;coutact;cout-action(act,w,emg);/調用主人動作函數(shù)while(act+1)%6);petx-emergency(emg);/ 調用特殊狀態(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;/非正常結束飼養(yǎng),bad endt+;cout-life|Nstep0)break;/ 非正常死亡,跳出循環(huán)system(cls);/ 調用系統(tǒng)清屏函數(shù)if

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論