实验环境:vs2017
#include<iostream>
#include<fstream>
#include<stdlib.h>
#include <stdio.h>
#include<time.h>
#include<windows.h>
#include<string>
using namespace std;
int adopt(); //领养函数
void raise(); //确认领养函数
void start_Raise(int sel); //开始饲养函数
int weather(); //天气
void change_time(int t); //时间
int quit();
char pet_name[15]; //宠物名字
int select_t; //选择的宠物编号
int money; //主人拥有的金币数
class Pet
{
public:
Pet(int a = 0, int h = 0, int t = 0, int m = 0, int f = 0, int st = 15)
{
age = a; //年龄
hunger = h; //饥饿
thirst = t; //口渴
mood = m; //心情
fitness = f; //健康值
step = st; //活动点数
}
int get_age() { return age; }
int get_hunger() { return hunger; }
int get_thirst() { return thirst; }
int get_mood() { return mood; }
int get_fitness() { return fitness; }
int get_step() { return step; }
void change(); //饥、渴、心情随时间变化的函数
void show(); //每个值的显示函数
void feed(); //喂食
void drink() //喂水
{
thirst--;
step = step - 3;
}
void touch(int w); //抚摸
void play(int w); //玩耍
void doctor(int w); //看医生
void emergency(int w); //特殊状态函数
virtual int getl() //提取生命值
{
return age;
}
virtual void action(int act, int w, int emg) {}; //主人的各种动作(纯虚函数)
private:
int age;
int hunger;
int thirst;
int mood;
int fitness;
int step;
};
//饥、渴、心情随时间变化的函数
void Pet::change()
{
int m;
m = rand() % 20;
if (m < 5)
mood = mood - 2;
else if (m < 10)
mood--;
else
mood++;
age++;
hunger = hunger++;
thirst = thirst++;
}
//宠物信息显示函数
inline void Pet::show()
{
cout << "现在的状态:" << endl;
cout << "年龄:" << age<<endl;
cout << "饥饿值:" << hunger<<endl;
cout << "口渴值:" << thirst << endl;
cout << "心情指数:" << mood<<endl;
cout << "健康指数:" << fitness << endl;
}
//喂食
inline void Pet::feed()
{
int n;
step = step - 4;
mood++;
hunger--;
thirst++;
cout << endl;
cout << "你可以投喂的食物有:" << endl;
cout << "1.甜品($25) 2.水果($20) 3.炸鸡($35) 4.面包($10)" << endl;
cout << "请选择:";
cin >> n;
switch (n)
{
case 1:
money = money - 25;
cout << "*******************************" << endl;
cout << "太好吃啦!谢谢主人。" << endl;
break;
case 2:
money = money - 20;
cout << "*******************************" << endl;
cout << "-------------------------------------------------------------------------------" << endl;
break;
case 3:
money = money - 35;
cout << "-------------------------------------------------------------------------------" << endl;
cout <<"哇,我最爱吃炸鸡了!" << endl;
break;
case 4:
money = money - 10;
cout << "-------------------------------------------------------------------------------" << endl;
cout << "Yammy!" << endl;
break;
}
}
//抚摸函数
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--;
hunger--;
break;
}
}
//打工函数
inline void Pet::play(int w)
{
int a;
step = step - 3;
mood = mood + 2;
hunger = hunger + 2;
thirst = thirst + 2;
cout << "主人,我可以为你赚取金币哦。" << endl;
cout << " 1、发传单(+$30) 2、服务员(+$50) 3、家教(+$80)" << endl;
cout << "请选择宠物的打工类型:";
cin >> a;
switch (a)
{
case 1:
money = money + 30;
cout << "亲爱的主人,本宝宝给你带来了一笔收益,请查收。" << endl;