My complete TripleX game!

#include <iostream>
#include <ctime>
void PrintIntroduction(){
    //Story prompt and game explanation
    std::cout << "Welcome to EnergyOrdie Corp!\n";
    std::cout << "We at EnergyOrDie Corp strive for perfection EVERY time! Which is why we make sure to use only the right amount of energy needed for every project!\n";
    std::cout << "...\n";
    std::cout << "Now I am aware that you are here through court order correct? \n...\n Perfect.\n";
    std::cout << "Listen here, bud... if mess up and use too much or too little energy for ANY reason, I'm tossing your ass back in the slammer...you got it?\n";
    std::cout << "...\n";
    std::cout << "PERFECT!\n";
    std::cout << "Now, in order to ensure we only use EXACTLY what we need, we store different amountd of energy into different cubes!\n";
    std::cout << "To not confuse your tiny brain too much, we put big numbers on all boxs!\n";
    std::cout << "The machine will NEED 3 boxes for each project!\n";
    std::cout << "To know which 3 boxes you need to full each project requiremnt, the machine will prompt the numerical sum and product of all three boxes.\n";
    std::cout << "Then it'll be up to you to figure out which three boxes fulfill those requirements!\n";
    std::cout << "...\n";
    std::cout << "If you fuck up... you're done...\n";
    std::cout << "...\n";
    std::cout << "On todays agenda, you have 10 projects to fulfill! Better get to work!\n\n";
}

bool PlayGame(int Difficulty){
    //declare three energy block values
    const int EnergyBlockA = rand() % Difficulty + Difficulty;
    const int EnergyBlockB = rand() % Difficulty + Difficulty;
    const int EnergyBlockC = rand() % Difficulty + Difficulty;

    const int EnergySum = EnergyBlockA + EnergyBlockB + EnergyBlockC;
    const int EnergyProd = EnergyBlockA * EnergyBlockB * EnergyBlockC;

    //print sum and prod to terminal
    std::cout << "\n\nAssignment " << Difficulty << "...\n";
    std::cout << "\nThere are three energy block slots in the machine... \nThe machine displays these messages. \n";
    std::cout << "+ Energy values sum up to: " << EnergySum << std::endl;
    std::cout << "+ The product of the energy values are: " << EnergyProd << std::endl;


    std::cout << "Choose three block values to put into the machine:\n ";
    int GuessA, GuessB, GuessC;
    std::cin >> GuessA >> GuessB >> GuessC;
    std::cout << "Blocks " << GuessA << ", " << GuessB << " and " << GuessC << " entered... the machine starts to hum...\n";

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

    if((GuessSum == EnergySum) && (GuessProd == EnergyProd)){
        std::cout << "Energy input sufficient...\n";
        return true;
    }else
    {
        std::cout << "ENERGY INSUFFICIENT!!!!\n" << "The machine glows a bright light and disintegrates everything in the room... including you.\n" << "GAME OVER\n";
        return false;
    }
    

}
int main()
{
    srand(time(NULL));
    int LevelDifficulty = 1;
    PrintIntroduction();
    int const MaxLevel = 5;
    while(LevelDifficulty <= MaxLevel){
        bool bLevelComplete = PlayGame(LevelDifficulty); //makes value T or F depending on PlayGame() return val
        std::cin.clear(); //clears any errors
        std::cin.ignore(); //discards any buffers

        if(bLevelComplete){
            LevelDifficulty++;
        }else{
            return 0;
        }

    }
    std::cout << "\n Congradulations, you survived... for now... \n";
   

    return 0;
}


1 Like

Awesome job!

Thank you!

Privacy & Terms