Virtual Pet Game Feed-Back

I made the following game.

If your pet is older than 10 years old he will die because of his age and there is nothing you can do, but you have to be careful if he is ill not to die or if you don't feed him for a long time he can die also.

I want to make this game like a project so I need ideas for improving it.
Also it could be nice if I can include concepts like inheritance and polymorphism. Does anyone have some cool ideas?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#include "stdafx.h"
#include <iostream>

using namespace std;

class Pet
{
private:
	int mHunger;
	int mBoredom;
	int mSick;
	double mAge;

	int GetMood() const;
	double GetAge() const;
	void PassTime(double time = 1);

public:
	Pet(int Hunger = 0, int Boredom = 0, int Sick = 0, double Age = 0.0);
	void Talk();
	void Eat(int food = 4);
	void Play(int fun = 4);
	void Medicine(int medicine = 2);
	void Age();
	void DisplayStats();
	
};

Pet::Pet(int hunger, int boredom, int sick, double age):
	mHunger(hunger),
	mBoredom(boredom),
	mSick(sick),
	mAge(age)
	{}

void Pet::PassTime(double time)
{
	int sick = rand() % 5;
	mHunger +=time;
	mBoredom +=time;
	if( sick == 3)
	{
	mSick +=sick;
	}
	mAge +=time/10;
}


void Pet::DisplayStats()
{
	cout << "\nHunger level is: " << mHunger << endl;
	cout << "Boredom level is: " << mBoredom << endl;
	cout << "Sickness level is: " << mSick << endl;
	cout << "Age is: " << mAge << endl;
}

int Pet::GetMood() const
{
	return mHunger + mBoredom + mSick;
}

double Pet ::GetAge() const
{
	return mAge;
}

void Pet::Age()
{
	double age = GetAge();
	if(age > 10.0)
	{
		cout << "Your pet is too old and died!";
		_getch();
		exit(0);
		
	}

	else if(age > 5.0)
	{
		cout << "Your pet is an adult.";
	}
	else if(age > 1.0)
	{
		cout <<"Your pet is a child.";
	}
	else if(age < 1.0)
	{
		cout << "Your pet is a baby.";
	}

}
void Pet::Talk()
{
	if(mSick > 15)
	{
		cout << "Your pet was sick and was not treated in time and he died!";
		_getch();
		exit(0);
	}

	if(mHunger > 15 )
	{
		cout << "You didn't feed your pet int time and he died!";
		_getch();
		exit(0);
	}

	cout <<"I am your pet and I feel: ";
	int mood = GetMood();

	if(mood > 15)
	{
		cout <<"mad";
	}
	else if (mood > 10)
	{
		cout << "frustrated";
	}
	else if(mood > 5)
	{
		cout << "ok";
	}
	else 
	{
		cout << "happy";
	}

	
	PassTime();
}

void Pet::Eat(int food)
{
	cout <<"Brruppp!\n";
	mHunger -=food;
	if(mHunger < 0)
		mHunger = 0;
	PassTime();
}

void Pet::Play(int fun)
{
	cout <<"Wheee!\n";
	mBoredom -=fun;
	if(mBoredom < 0)
		mBoredom = 0;
	PassTime();
}

void Pet::Medicine(int medicine)
{
	cout <<"Thanks!\n";
	mSick -=medicine;
	if(mSick < 0)
		mSick = 0;
	PassTime();
}

int main()
{
	Pet pet;
	
	cout << "\nWelcome to the Pet Game 1.0 !\n\n";
	int choice;

	do
	{
		
		cout << "\n\n0 - Quit\n";
		cout << "1 - Listen to your pet\n";
		cout << "2 - Feed your pet\n";
		cout << "3 - Play with your pet\n";
		cout << "4 - Display age\n";
		cout << "5 - Give your pet medicine\n";
		cout << "6 - Display pet stats\n\n";
		cout << "Choice: ";
		cin >> choice;
	

		switch(choice)
		{
		case 0:
			cout <<"Good-bye!\n";
			break;
		case 1:
			pet.Talk();
			break;
		case 2:
			pet.Eat();
			break;
		case 3:
			pet.Play();
			break;
		case 4:
			pet.Age();
			break;
		case 5:
			pet.Medicine();
			break;
		case 6:
			pet.DisplayStats();
			break;
		default:
			cout <<"Sorry but choice " <<choice << " isn't a valid choice\n";
		}
	}while(choice !=0);

	system("pause");
}
Last edited on
You could have the age more random. so theres a chance that the pet could live up to 12, but its unlikely.
Thank you for the idea. Yes, that will make the game less predictable and more interesting.
Topic archived. No new replies allowed.