I'm so far off the rails!

I’ve gone so far off the rails! :joy:
Here’s my current code so far. If anyone wants to try this out, you’ll have to find a different .wav file to use since i can’t just drop it into this thread.
This code types out messages one character at a time, with a typing sound effect, rather than spitting messages out all at once.
To plug a sound file into it, save this code as a .cpp file into a folder then just change the string in the PlaySound() functions to the name of your .wav.

#include <iostream>
#include <windows.h>
#include <string>
#pragma comment(lib, "winmm.lib")

const int CodeOne = 4;
const int CodeTwo = 4;
const int CodeThree = 9;
bool bSumCorrect = false;
bool bProductCorrect = false;

int CodeSum;
int CodeProduct;
int GuessA, GuessB, GuessC;
int GuessSum, GuessProduct;

void PressEnter()
{
    std::cout << "\nPress enter to continue.\n";
    std::cin.get();
}

void TypeString(std::string TextIntoFunction, int TypingSpeed)
{
    PlaySound(NULL, NULL, NULL);
    if(TypingSpeed <= 60)
    {
        PlaySound(TEXT("Sounds/qkeyEdit.wav"), NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
    }
    else
    {
        PlaySound(TEXT("Sounds/qkey.wav"), NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
    }
    

    for (unsigned i=0; i<TextIntoFunction.length(); ++i)
    {
        std::cout << TextIntoFunction.at(i);
        Sleep(TypingSpeed);
    }
    PlaySound(NULL, NULL, NULL);
}

void TypeStringSilent(std::string TextIntoFunction, int TypingDelay)
{
    for (unsigned i=0; i<TextIntoFunction.length(); ++i)
    {
        std::cout << TextIntoFunction.at(i);
        Sleep(TypingDelay);
    }
}

void PrintIntroduction()
{
    //Output introduction text to the terminal.
    std::string IntroText1 = "\n\nWelcome to the Net3X mainframe access portal...\nUser credentials not verified!\nSystem maintenance mode engaged.\n";
    TypeString(IntroText1, 20);
}

void PrintCurrentLevel(int LevelDifficulty)
{
    TypeString("\n Current Sequence depth: ", 20);
    std::cout << LevelDifficulty;
    //Output hint text to ther terminal.
    TypeString("\n+ There are 3 numbers in the code.", 20);
    TypeString("\n+ The codes add up to: ", 20); TypeStringSilent("... ", 100);
    Sleep(300);
    std::cout << CodeSum;
    TypeString("\n+ The code multiples to equal: ", 20); TypeStringSilent("... ", 100);
    Sleep(300);
    std::cout << CodeProduct;
    TypeString("\n+ Enter the correct codes to continue...\n", 20);
}

bool PlayGame(int LevelDifficulty)
{

    //set the values of our hint text.
    CodeSum = CodeOne+CodeTwo+CodeThree;
    CodeProduct = CodeOne*CodeTwo*CodeThree;

    PrintCurrentLevel(LevelDifficulty);
    
    TypeString("\nPlease input first digit: ", 20);
    std::cin >> GuessA;
    std::cin.clear();
    std::cin.ignore();
    TypeString("Please input second digit: ", 20);
    std::cin >> GuessB;
    std::cin.clear();
    std::cin.ignore();
    TypeString("Please input third digit: ", 20);
    std::cin >> GuessC;
    std::cin.clear();
    std::cin.ignore();

    TypeString("\nUser Input: ", 20);
    Sleep(200);
    std::cout << GuessA;
    Sleep(50);
    std::cout << "-";
    Sleep(50);
    std::cout << GuessB;
    Sleep(50);
    std::cout << "-";
    Sleep(50);
    std::cout << GuessC;

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

    TypeString("\nGuess Sum: ", 20);
    Sleep(50);
    TypeStringSilent("... ", 100);
    std::cout << GuessSum;
    TypeString("\nGuess Product: ", 20);
    TypeStringSilent("... ", 100);
    std::cout << GuessProduct;

    if(GuessSum == CodeSum)
    { //If Sum is correct, tell the player!
        TypeString("\nCode Sum is correct!", 20);
        bSumCorrect = true;
    }
    else
    { //Otherwise, remind the player what the sum needs to equal.
        TypeString("\nCode Sum needs to equal: ", 20);
        std::cout << CodeSum;
        bSumCorrect = false;
    }

    if(GuessProduct == CodeProduct)
    { //If the Product is correct, tell the player!
        TypeString("\nCode Product is correct!", 20);
        bProductCorrect = true;
    }
    else
    { //Otherwise, remind the player what the product needs to equal.
        TypeString("\nCode Product needs to equal: ", 20);
        std::cout << CodeProduct;
        bProductCorrect = false;
    }

    if(bSumCorrect && bProductCorrect)
    { //If both are correct, the player wins!
        TypeString("\nACCESS GRANTED: MOVING TO NEXT SEQUENCE\nPress enter to continue...", 20);
        return true;
    }
    else
    { //Otherwise, the player loses!
        TypeString("\nACCESS DENIED!\nPress enter to continue...", 20);
        return false;
    }
}

int main()
{
    int LevelDifficulty = 1;
    PrintIntroduction();

    while(true)
    {
        bool bLevelComplete = PlayGame(LevelDifficulty);
        std::cin.clear();
        std::cin.ignore();

        if (bLevelComplete)
        {
            ++LevelDifficulty;
        }
        
    }

    return 0;
}
1 Like

Privacy & Terms