Hi all,
Just a silly game, and a random story I ran with
Added attempts to get a fail state.
void PrintIntroduction()
{
system("Color 0A");
// Welcome messages
cout << "\n \n __ __ _____ _____ _____ _____ _____ _____ __ _____ \n| | | | | | __ | | __| _ | | | ||_ _|\n|_ _| | | | | -| | __| | | | |__| | \n |_| |_____|_____|__|__| |__| |__|__|_____|_____|_| ";
cout << "\n\nYour parents marriage needs your help, their math preferences are slowly tearing their marriage apart.\nIt is your job to select numbers that both your mum and dad likes and make them reach their next milestones in their marriage.\n" ;
}
int CalculateAddtionResult(int a, int b, int c)
{
return a + b + c;
}
int CalculateMultiplicationResult(int a, int b, int c)
{
return a * b * c;
}
void FailedMessage (int Attempts)
{
switch (--Attempts)
{
case 0:
cout << "\n\nYou failed. Mom and dad are separting, they say its temporary... But you know thats a lie. They are selling your childhood home. You used to be so happy here, now you have to move into the city, change schools and probably loose all your friends.\nAs you look at your life slowly being packed down in boxes, you are overwhelmed with a sinking feeling in your stomach. You know. You know for certain that it was...\n";
cout << " \n __ __ _____ _____ _____ _____ _____ _____ __ _____ \n| | | | | | __ | | __| _ | | | ||_ _|\n|_ _| | | | | -| | __| | | | |__| | \n |_| |_____|_____|__|__| |__| |__|__|_____|_____|_| \n\n\n";
break;
case 1:
cout <<"\n\n*** Mom and dad is getting closer to a divorce.***\n" << "*** Only " << Attempts << " more try to get this to work!! ***\n";
break;
default:
cout << "\n\n*** Mom and dad is getting closer to a divorce. ***\n" << "*** You only have " << Attempts << " more tries to get this to work. *** \n\n";
}
}
bool PlayGame(int Difficulty, int Attempts)
{
//Decalartions
const int NumberA = rand() % Difficulty + 1;
const int NumberB = rand() % Difficulty + 1;
const int NumberC = rand() % Difficulty + 1;
const int MomsSum = CalculateAddtionResult(NumberA, NumberB, NumberC);
const int DadsProduct = CalculateMultiplicationResult (NumberA, NumberB, NumberC);
// Explain the game and what level you are at and ask for input.
cout <<"\nYour parents are "<< Difficulty << " years of marriage in \n\n";
cout << " - There is three numbers you have to give mom and dad." << "\n - The number that moms want is the addition, the sum should be: " << MomsSum << " \n - The number that dads want is the multiplication, the product should be: " << DadsProduct;
cout << "\n\nGet to work child, guess: ";
// Get input
int PlayerGuessA, PlayerGuessB, PlayerGuessC;
cin >> PlayerGuessA >> PlayerGuessB >> PlayerGuessC;
int ChildGuessSum = CalculateAddtionResult (PlayerGuessA, PlayerGuessB, PlayerGuessC);
int ChildGuessProduct = CalculateMultiplicationResult (PlayerGuessA, PlayerGuessB, PlayerGuessC);
cout << "\nYou presented for mom: " << ChildGuessSum;
cout << "\nYou presented for dad: " << ChildGuessProduct;
//check if player guess correct or incorrectly
if (MomsSum == ChildGuessSum && DadsProduct == ChildGuessProduct)
{
cout << "\n\n*** They seem happy for now. We'll see how it goes for mom and dad next year ***\n";
cout << "\n\n ------------------------------------------- ONE YEAR LATER ------------------------------------------- \n";
return true;
}
else
{
FailedMessage(Attempts);
return false;
}
}
int main()
{
srand(time(NULL));
int Attempts = 3;
int LevelDifficulity = 1;
const int MaxLevel = 5;
PrintIntroduction();
//Loop game until it is done
while (LevelDifficulity <= MaxLevel)
{
bool bLevelComplete = PlayGame(LevelDifficulity, Attempts);
cin.clear(); // clear errors
cin.ignore(); //discard the buffer
if (bLevelComplete)
{
++LevelDifficulity;
}
else
{
--Attempts;
}
if (Attempts < 1)
{
return 0;
}
}
//Success message
cout <<"\n __ \n __ __ _ _ _ _ _ _ _ _ _ _ | |\n| | |___ _ _ ___ ___ ___ ___|_|___ _| | | |_| |_ ___ | |_ _ _ ___ _| |___ ___ _ _ _ ___| | | ___ ___ |_|___ _ _ _ _ ___ _ _ ___ | |_ ___ ___ _ _ _____ ___| |\n|_ _| . | | | | _| .'| _| _| | -_| . | | _| | -_| | . | | | _| . | -_| | | | | | -_| | |_ | -_| | | | . | | | | | | . | | | _| | _| _| .'| | | | .'|__|\n |_| |___|___| |___|__,|_| |_| |_|___|___| |_| |_|_|___| |___|___|_| |___|___|_|_| |_____|___|_|_| | |___|_|_|_| |___|_ | |_ |___|___|_| |_| |_| |__,|___|_|_|_|__,|__|\n |_| |___| |___| |___| ";
return 0;
}