New to C++ Help with virtual pet project?

Hi guys. I'm just playing around with C++ and I'm trying to make a sort of virtual pet game. I know its not the best looking code but I'm trying. But as of right now I'm trying to be able to animate the game a little . For example , if a user decides to "pet" their "pet" I want the pets mouth to open from '_' to ^o^ like this:

() ()
('_') -> () ()
(^o^) and switch back and forth. I'm not sure how to do this I was thinking of using a For loop but I'm not sure. Can you guys help? Thanks so much!

Here's my code:


#include <iostream>
#include <cstring>
using namespace std;




void Greeting()
{
cout<<"===================================================";
cout<<"\t\t\t Welcome to Kayla's Kawaii Pet Game!";
cout<<"===================================================";
cout<<"\n";

}

void PrintPet()
{
cout<<"\t\t";
cout<<"() ()";
cout<<"\t\t";
cout<<"\n";
cout<<"\t\t";
cout<<"('_')";
cout<<"\t\t";
cout<<"\n";
cout<<"\t\t";
cout<<"(> < )";
cout<<"\t\t";
cout<<"\n";
cout<<"\t\t";
cout<<" u--u";

}

void PetMenu()
{
cout<<"\n";
cout<<"1.Pet";
cout<<"\n";
cout<<"2.Feed";
cout<<"\n";
cout<<"3.Put to bed.";
cout<<"\n";
cout<<"4.Play";
cout<<"\n";


}


void Pet()
{

char mouth='_';



cout<<"\t\t";
cout<<"() ()";
cout<<"\t\t";
cout<<"\n";
cout<<"\t\t";
cout<<"(^_^)";cout<<"♥";
cout<<"\t\t";
cout<<"\n";
cout<<"\t\t";
cout<<"(> < )";
cout<<"\t\t";
cout<<"\n";
cout<<"\t\t";
cout<<" u--u";




}


int main ()

{


string name;
string tamaname;
int userchoice;

Greeting();
cout<<"What's your name?: ";
cin>>name;
cout<<"Hello "<<name<< ", What would you like to name your Kawaii pet?: ";
cin>>tamaname;
cout<<"Okay! Here is your pet, "<<tamaname<<" ! ";
cout<<"\n";


PrintPet();
cout<<"\n";

cout<<"What would you like to do with " <<tamaname<< "?";
PetMenu();
cin>>userchoice;

if(userchoice==1)
{

Pet(); //function for petting
}


}



You can't do that in console.
Yeah you can. You can do a lot of stuff in the console. If you want it to have an animation like that just do something like this.

1
2
3
4
5
6
7
8
for (int i = 0; i < 5; i++) {
    system("cls");
    DrawFace1();
    Sleep(100);
    system("cls");
    DrawFace2();
    Sleep(100);
}
Last edited on
Oh, for a second I forgot "system" still existed...
Hi,

There is a thing called ncurses that will do these things in a standard way - no system function calls and no Microsoft Sleep function.

o<:+)
Kindly take note of post formatting features before posting thanks.
Topic archived. No new replies allowed.