My new to me version of Triplex

#include
#include

void PrintIntroduction (int Difficulty)
{
std::cout << “\n\nYou are a traveler searching for treasure in the forest you come across three stone griffins.\n” ;
std::cout << R"(
______
,—’,—’
,-’—
,—’
/
(, —
___’,
/ ‘, , ,-' ;/) ,',,_/,' | /\ ,.'//\ -\ ,,' .
', ,-- .
‘/ / | , _ //'',.\_ .\\ ,{==>- __// __;_- \ ;.__,;' ((,--,) (((,------; –’
)" <<’\n’;
std::cout << “You need to discover the hidden numbers of each level (” << Difficulty;
std::cout << “) to continue to the treasure…\n”;
}

bool PlayGame (int Difficulty)
{
PrintIntroduction(Difficulty);

//Declare 3 number code
const int CodeA = rand() % Difficulty + Difficulty;
const int CodeB = rand() % Difficulty + Difficulty;
const int CodeC = rand() % Difficulty + Difficulty;

const int CodeSum= CodeA + CodeB + CodeC;
const int CodeProduct= CodeA * CodeB * CodeC;

//Print CodeSum and CodeProduct to the terminal
std::cout << "\n+ There are 3 numbers in the code";
std::cout << "\n+ The codes add up to: " << CodeSum;
std::cout << "\n+ The codes multiply to give: " << CodeProduct << std::endl;

// Store player guess
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;

const int GuessSum = GuessA + GuessB + GuessC;
const int GuessProduct = GuessA * GuessB * GuessC;

// Check if player guess is correct
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
    std::cout << "\nThe griffins move and reveal another set.";
    return true;
}
else
{
    std::cout << "\nYou entered the wrong code, the griffins give you another chance.";
    return false;
}

}

int main()
{
srand(time(NULL)); // Create new random sequence based on time of day

int LevelDifficulty = 1;
int const MaxLevel = 5;

while (LevelDifficulty <= MaxLevel) // Loop gane until all levels are completed

{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear(); // Clears any errors
std::cin.ignore(); // Discards the buffer

if (bLevelComplete)
{
    ++LevelDifficulty;
}

}

std::cout << "\nYou found the treasure, congratulations! Now run home!";
return 0;

}

1 Like

Looks very good! Great job! :smiley:

Privacy & Terms