My TripleX game code

#include <iostream>

void PrintIrtroduction(int LevalDifficulty)
{
   std::cout << "\nYou're a secret agent breaking into a Leval " << LevalDifficulty;
    std::cout << " secure server room...\nEnter the correct code to continue...\n\n"; //setup the premis of the game
}

bool PlayGame(int LevalDifficulty, int WrongTries, int MaxLevels)
{
    PrintIrtroduction(LevalDifficulty);

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

    int CodeSum = CodeA + CodeB + CodeC;
    int CodeProduct = CodeA * CodeB * CodeC; // do stuff the the variables

    std::cout << "+ There are three numbers in the code...\n";
    std::cout << "+ The product of the codes are: " << CodeProduct << "\n+ The Sum of the codes are " << CodeSum << "\n\n";

    int GuessA, GuessB, GuessC;

    std::cin >> GuessA >> GuessB >> GuessC;

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

    if (GuessSum == CodeSum && GuessProduct == CodeProduct && LevalDifficulty < MaxLevels)
    {
        std::cout << "\nYou cracked the code. Move on to the next server room...\n";
        return true;
    }
    else if (LevalDifficulty >= MaxLevels)
    {
        std::cout << "You found all of Nestle's dirty secrets. Good job!";
        return true;
    }
    else if (WrongTries >= 1)
    {
        std::cout << "\nSecurity caught you. You're going away for a long time.";
        return false;
    }
    else
    {
        std::cout << "\nSecurity is onto you. You have one more attemt before they trianglulate your location\n";
        return false;
    }
}

int main()
{
    int Difficulty = 1;
    int MaxDifficulty;
    int WrongTries = 0;

    std::cout << "How many levels of the game do you wish to play?\n";
    std::cin >> MaxDifficulty;

    while (Difficulty <= MaxDifficulty)
    {
        bool bLevalCompleat = PlayGame(Difficulty, WrongTries, MaxDifficulty);
        std::cin.clear();
        std::cin.ignore();

        if (bLevalCompleat)
        {
            Difficulty++;
            WrongTries = 0;
        }
        else
        {
            WrongTries++;
            if (WrongTries >= 2)
            {
                Difficulty += 10;
            }
        }
    }

    return 0;
}
1 Like

Thanks for sharing.!

Privacy & Terms