My TripleX game so far

So, my code so far,

#include <iostream>

void PrintMainIntroduction()
{  
    std::cout << "\nYou've woken up from a deep sleep and find yourself in a locked room.";
    std::cout << "\nThe door does not appear to have any handels or keyholes.  Theres a terminal which may open the door.";
    
}

void PrintRepeatedIntroduction(int Difficulty)
{
    //Prints the initial text to the console
    std::cout << "\nThe terminal requests for the correct level " << Difficulty << " code to open the door.\n\n";
}


bool PlayGame(int Difficulty){
    //Prints the initial text to the console
    PrintRepeatedIntroduction(Difficulty);
        

    //Delcares the variables 
    const int CodeA = 4;
    const int CodeB = 7;
    const int CodeC = 2;

    //Sums the variables and provides the product also.
    const int CodeSum = (CodeA + CodeB + CodeC);
    const int CodeProduct = (CodeA * CodeB * CodeC);

    //Displays the sum and product to the console.
    std::cout << "+ The code contains 3 numbers in total.";
    std::cout << "\n+ All the numbers add up to " << CodeSum;
    std::cout << "\n+ The codes multiply by each other to give " << CodeProduct;

    //Delcare Guess Variables
    int GuessA, GuessB, GuessC;

    //Prompt For GuessA
    std::cout << "\n\nPlease Enter each of the three numbers followed by a space...\n\n";
    std::cin >> GuessA >> GuessB >> GuessC;

    //Present Numbers Entered
    //std::cout << "You entered " << GuessA << GuessB << GuessC << std::endl;

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

    if(GuessSum == CodeSum && GuessProduct == CodeProduct)
    {
        std::cout << "\nYou have successfully guessed the correct code!";
        std::cout << "\nThe Terminal clicks and clucks.....\n\n";
        return true;

    }
    else
    {
        std::cout << "\nYou Guessed incorrectly and continue to remain trapped in the room.....\n\n";
        return false;
    }

}

void NextLevelText()
{
    std::cout << "\nThe Terminal begins loading another locked screen....\n\n";
}

int main()
{
    //Set Base Difficulty Level;
    int LevelDifficulty = 1;

    //Set the Max Level to run to.
    const int MaxDifficulty = 10;

    //Initial Introduction
    PrintMainIntroduction();

    while(LevelDifficulty <= MaxDifficulty) //Loop Levels untill Max Level is reached.
    {
        bool bLevelComplete = PlayGame(LevelDifficulty);

        //The two statments below are to resolve any problems caused by the usage of characters entered rather than numbers.
        std::cin.clear();
        std::cin.ignore();

        if (bLevelComplete)
        {
            ++LevelDifficulty;

            if(LevelDifficulty <= MaxDifficulty)
            {
                NextLevelText();
            }
        }
        else
        {
            std::cout << "\nThe Terminal makes a beeping sound... it almost feels like its lauging...\n";
            std::cout << "Reloading the previous level code\n\n";
        }
        
    }

    std::cout << "You have cracked the Terminal! The door opens and you make your escape...\n";
    
    //Finishes the program with no errors.
    return 0;

}
3 Likes

Looking good! :clap:

2 Likes

Thanks Kevin.

Privacy & Terms