Question: Can someone help me with this project? Project 2 The PetSim puts the player in charge of his own virtual pet. The player is completely
Can someone help me with this project?
Project 2
The PetSim puts the player in charge of his own virtual pet. The player is completely responsible for keeping the pet happy. He can feed and play with the pet to keep it in a good mood. He can also listen to the pet to learn how the pet is feeling, which can range from happy to mad. If you fail to feed or entertain your pet, it will have a mood change for the worse. But, with the proper care your pet can return to a sunny mood. NOTE: Improvise the game if necessary.
Declare your variables as static variables
PetMood()
The pets mood is directly based on its hunger and boredom levels. This function returns the sum of pets hunger and boredom levels, a pets mood gets worse as the number increases. This member function it should only be invoked by another member function of the project.
Talk()
This function allows the pet to be able to tell the player how its feeling. The pets mood can be happy, okay, frustrated, or mad which is determined by the value returned by PetMood() function. The pet is happy if mood is less than than 7, Okay if mood is 7 or higher, frustrated if the mood is between 16 and 21 and mad if greater than 21. Finally, Talk() calls PassTime() to simulate the passage of time.
FeedPet()
The FeedPet function allows the player to be able to feed the pet to reduce its hunger. FeedPet() displays an appropriate message indicating that the pet has been fed. This function reduces pets hunger level by a certain amount. This amount can be passed as a parameter or as default parameter. The max amount of food that can be fed to the pet is value of 4. The pets hunger level is kept in check and is not allowed to go below zero. Finally, PassTime() is called to simulate the passage of time.
Play()
The Play function allows the player to be able to reduce the pets boredom. Play() displays an appropriate message indicating that the pet was allowed to play. The function reduces a pets boredom level by a certain amount. This amount can be passed as a parameter or as default parameter. The max amount of fun a pet can have is value of 4. The pets boredom level is kept in check and is not allowed to go below zero. Finally, PassTime() is called to simulate the passage of time.
PassTime()
PassTime() is a private member function that increases a pets hunger and boredom levels by adding the specified amount of time to the member variables hungerLevel and boredomLevel.
It is invoked at the end of each member function where the pet does something
(eats, plays, or talks) to simulate the passage of time. You can pass the member function the amount of time that has passed; otherwise, time gets the default argument value of 1.
DisplayPetBehavior()
This function displays appropriate pet behavior based on the hunger level and boredom levels. This function must also displays the actual hunger and boredom levels.
The hunger and boredom levels less than 3 indicate that the pet is neither hungry nor bored.
Boredom levels between 3 and 11 indicate that the pet is a little bored, otherwise it is very bored.
Hunger level between 3 and 11 indicate that the pet is modertely hungry.Hunger levels greater than 11 indicate that the pet is very hungry. This function is called by member functions Talk(), FeedPet() and Play().
Menu ()
It is basically be a game loop that asks the player whether he wants to listen to, feed, or play with the pet, or quit the game. Heres the pseudocode:
While the player doesnt want to quit the game
Present a menu of choices to the player
If the player wants to listen to the pet
Make the pet talk
If the player wants to feed the pet
Feed the pet
If the player wants to play with the pet
Make the pet play
main()
In main().You can supply specific values for Name, Hunger or
Boredom or leave it at default values. When the data members start out at 0, the pet begins life happy and content.
#include
#include
using namespace std;
int hungerLevel = 0;
int boredomLevel = 0;
int foodAmt = 3;
int funAmt = 3;
int timeAmt = 1;
string petName = "your pet";
int PetMood();
void Talk();
void PassTime(int);
void FeedPet();
void Play();
void DisplayPetBehavior();
void menu();
void main() {
cout << "Welcome to PetSim! :)" << endl;
cout << "What would you like to name your pet?: ";
cin >> petName;
cout << endl;
menu();
system("pause");
}
void menu()
{
Implement this Function
}
void Talk() {
int moodLevel = PetMood();
string mood = "none";
if (moodLevel < 7) {
mood = "Happy";
}
else if (moodLevel >= 7 && moodLevel < 16) {
mood = "Okay";
}
else if (moodLevel >= 16 && moodLevel <= 21) {
mood = "Frustrated";
}
else if (moodLevel > 21) {
mood = "Mad";
}
cout << petName << "'s current mood is: " << mood << endl;
PassTime(timeAmt);
DisplayPetBehavior();
}
void FeedPet() {
if (hungerLevel >= foodAmt) {
hungerLevel -= foodAmt;
}
else {
hungerLevel = 0;
}
cout << petName << " has been fed." << endl;
PassTime(timeAmt);
DisplayPetBehavior();
}
void Play() {
if (boredomLevel >= funAmt) {
boredomLevel -= funAmt;
}
else {
boredomLevel = 0;
}
cout << petName << " was allowed to play." << endl;
PassTime(timeAmt);
DisplayPetBehavior();
}
void PassTime(int timeAmt) {
hungerLevel += timeAmt;
boredomLevel += timeAmt;
}
int PetMood() {
int mood = hungerLevel + boredomLevel;
return mood;
}
void DisplayPetBehavior() {
if (hungerLevel < 3 && boredomLevel < 3) {
cout << petName << " is neither hungry or bored." << endl;
}
else if (boredomLevel >= 3 && boredomLevel <= 11) {
cout << petName << " is a little bored." << endl;
}
else if (boredomLevel > 11) {
cout << petName << " is very bored." << endl;
}
if (hungerLevel >= 3 && hungerLevel <= 11) {
cout << petName << " is moderately hungry." << endl;
}
else if (hungerLevel > 11) {
cout << petName << " is very hungry." << endl;
}
cout << "Hunger Level: " << hungerLevel << endl
<< "Boredom Level: " << boredomLevel << endl;
}
/* OUTPUT
Welcome to PetSim! :)
What would you like to name your pet?: Sparky
What would you like to do with Sparky?
************************
1 - Listen to Pet
2 - Feed Pet
3 - Play with Pet
4 - Exit Game
Enter your choice: 1
Sparky's current mood is: Happy
Sparky is neither hungry or bored.
Hunger Level: 1
Boredom Level: 1
What would you like to do with Sparky?
************************
1 - Listen to Pet
2 - Feed Pet
3 - Play with Pet
4 - Exit Game
Enter your choice: 2
Sparky has been fed.
Sparky is neither hungry or bored.
Hunger Level: 1
Boredom Level: 2
What would you like to do with Sparky?
************************
1 - Listen to Pet
2 - Feed Pet
3 - Play with Pet
4 - Exit Game
Enter your choice: 3
Sparky was allowed to play.
Sparky is neither hungry or bored.
Hunger Level: 2
Boredom Level: 1
What would you like to do with Sparky?
************************
1 - Listen to Pet
2 - Feed Pet
3 - Play with Pet
4 - Exit Game
Enter your choice: 5
ERROR: Invalid selection. Please try again.
What would you like to do with Sparky?
************************
1 - Listen to Pet
2 - Feed Pet
3 - Play with Pet
4 - Exit Game
Enter your choice: 4
Exiting...
*/
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
