TripleX - Progress so far


void PrintIntroduction(int Difficulty)
{
    std::cout << "\n\nYou are a powerful king that set a multi-level security system on your kingdom's treasures,\nbut you bumped your head and forgot all the codes!\n";
    std::cout << "\nYou are now breaking into a level " << Difficulty;
    std::cout << " code system.\nEnter the correct code to continue...\n\n";
}

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

    const int CodeA = 2;
    const int CodeB = 3;
    const int CodeC = 4;

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


    // Print CodeSum and CodeProduct to the terminal
    std::cout << "+ 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;

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

    // Check if the players guess is correct
    if (GuessSum == CodeSum && GuessProduct == CodeProduct)
    {
        std::cout << "\n*** Well done! You are a lot closer to accessing your kingdom's treasures! Keep going!***";
        return true;
    }
    else
    {
        std::cout << "\n*** You entered the wrong code! Entering the wrong code too many times will cause the room to explode! Try again! ***";
        return false;
    }
}

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

    while (LevelDifficulty <= MaxDifficulty) // Loop game until all levels completed
    {
        bool bLevelComplete = PlayGame(LevelDifficulty);
        std::cin.clear(); // Clears any errors
        std::cin.ignore(); // Discards the buffer

        if (bLevelComplete)
        {
            ++LevelDifficulty;
        }

    }

    std::cout << "\n*** Great work! Your kingdom's treasures are now safe! ***\n";
    
    return 0;
}
2 Likes

Coming along nicely!

Privacy & Terms