TripleX - Escape the Tyrant's dungeon!

So as is most peoples who are taking this course… This is my first game in C++.

#include <iostream> // This Preprocessor Directive allows us to access the features of <iostream> allowing us to e.g. output to the console.
#include <ctime>

void PrintIntroduction(int Difficulty)
{
    std::cout << "#############################################################" << std::endl;
    std::cout << "#                  _  _                                     #" << std::endl;  
	std::cout << "#                 ( `   )_                                  #" << std::endl;  
	std::cout << "#                (    )    `)                               #" << std::endl;  
	std::cout << "#              (_   (_ .  _) _)                             #" << std::endl;  
	std::cout << "#                                             _             #" << std::endl;  
	std::cout << "#                                            (  )           #" << std::endl;  
	std::cout << "#             _ .                         ( `  ) . )        #" << std::endl;  
	std::cout << "#           (  _ )_                      (_, _(  ,_)_)      #" << std::endl;  
	std::cout << "#         (_  _(_ ,)                                        #" << std::endl;
    std::cout << "#                                                           #" << std::endl;  
	std::cout << "#############################################################" << std::endl;

    std::cout << "\nThe year is 1565 and you're a master thief breaking out of a tyrant's level " << Difficulty << " dungeon!\n";
    std::cout << "You must enter the correct code to continue...\n\n";
}

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

    // Declaring 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;

    // Outputting CodeSum and CodeProduct.
    std::cout << "The combination padlock has three switches...\n";

    std::cout << "+ There must be three numbers in the code!";
    std::cout << "\n+ The codes add-up to: " << CodeSum;
    std::cout << "\n+ The codes multiple to: " << CodeProduct;
    std::cout << "\n\nCode: ";

    // Initialising the Guess(A/B/C) variables.
    int GuessA, GuessB, GuessC;

    // Storing a users input in each Guess variable.
    std::cin >> GuessA >> GuessB >> GuessC; 

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

    if (GuessSum == CodeSum && GuessProduct == CodeProduct)
    {
        std::cout << "\n** The door unlocks! You've got to keep going! **\n\n";
        return true;
    }
    else
    {
        std::cout << "\n** Unlucky, you failed to get the padlock open. Your execution is scheduled for tomorrow you'd better keep trying! **\n";
        std::cout << "\nA was " << CodeA << ", B was " << CodeB << " and, C was " << CodeC << "\n\n";
        return false;
    }

}

int main() 
{
    srand(time(NULL));
    int LevelDifficulty = 1;
    const int MaxDifficulty = 5;

    while (LevelDifficulty <= MaxDifficulty) // Loop the game 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 << "**** Congratulations you have escaped from the clutches of the tyrant... But be careful he'll never stop looking for you! ****";
    return 0;
}
2 Likes

Everything looks neat and clean! Great ASCII art!

1 Like

I like the concept, classic.

1 Like

Thank you.

Some really nice and clean code! Well done on the ASCII too

1 Like

Privacy & Terms