To be honest with you, all the codes that i made were self taught, i had to advance myself to learn more stuff in C++ which my first challenge is to make a simple but clean made text based adventure game, but im at the wall atm. (don't judge me, i'm still a newbie to C++)

One is making choices, i tried doing "if" then "else if", on my last project, and it always reads the first "if", making the other two choices non-readable, so i had to force myself to make only one choice (hence making it a game that has alot of choices

Two is skipping text, i showed to my friends that im trying to advance learning on C++, but everytime they read the tutorial or the "instruction" part ( the first part ), they always ask me, "is there a way to skip it, like while the text is appearing, can i press enter to skip the text." took me awhile to figure that one out but so far is either remove the typewriter effect or just let it stay.

P.S If you ask about what was supposed to be the choices on my "if" part is that i want to inspect the bench and the metal rod, if i figure that one out i can make the story even longer.

#include <stdlib.h>
#include <time.h>
#include <windows.h>
#include <chrono>
#include <thread>
#include <iostream>
#include <string>
#include <MMSystem.h>
#pragma comment(lib,"winmm.lib")
using std::string;
using namespace std;
int main() {

    PlaySound(TEXT("C:\\Users\\Miguel Nicholas\\Desktop\\sounds\\souls.wav"), NULL, SND_FILENAME | SND_LOOP | SND_ASYNC);

    string hello = "Welcome to the Void.\n"
    "The Negligence of the Void!\n"
    "In this story, your choice matters to this world.\n"
    "For the story adapts to the choices you make.\n"
    "So choose carefully, one move will change the senario.\n"
    "There will be a senario that you have to choose. \n"
    "You will ask a choice that is inside of this example (answer).\n"
    "For every pause of the text, please press enter.\n"
    "With that in mind, game is on beta so be mindful and have fun.\n";

        int x = 0;
        while (hello[x] != '\0')
        {
            cout << hello[x];
            if (hello[x] != ' ' && hello[x] != '\n')
                Beep(950, 50);

            x++;
        };

    cin.get();
    cout << "" << endl;
    cout << "Let me tell you a tale of an ember, a power of balance, changed Yundr." << endl;
    cout << "In the age of the darkness, A land named Yundr was unformed, shrouded by fogs, filled with dark entities." << endl;
    cout << "But then there was fire, and with fire came disparity. Heat and cold, life and death, and of course, light and dark." << endl;
    cout << "Then from the dark, they came, and found the Souls of Lords within the flame." << endl;
    cout << "Gwyn, a noble warrior was the first one to withstand the flame, made it as his own." << endl;
    cout << "Eli, a witch in studies that was cable to withstand the flame." << endl;
    cout << "And Nero, the man who was survived the first onslaught of the darkness also withstand the flame." << endl;

    cin.get();
    cout << "" << endl;
    cout << "It was fortold that the ember is the only key of balancing between good and evil of the land of Yundr. " << endl;
    cout << "Gwyn sought out this great power and used it to cast light around the realm, but after that, the land changed." << endl;
    cout << "All entities that were once dead are now alive, some entities that supposed to be dead are now awakened. " << endl;
    cout << "They realized that the darkness was casted for a reason, to remain peace of the land, now awakened in destruction " << endl;
    cout << "Gwyn and the others used all of their power to defend Yundr, by creating a sanctum, which now called Londor. " << endl;
    cout << "Londor was the beacon of Yundr, making it as the safezone of all the land, but alas, it did not took long for the flame to extinguished." << endl;
    cout << "Gwyn grew tired of his sanctum and ventured the remaining dark lands of Yundr to claim more land of Yundr." << endl;
    cout << "Thus began the Age of Fire. But soon, the flames will fade, and only Dark will remain" << endl;
    cout << "Even now, there are only embers, and man sees not light, but only endless nights." << endl;
    cout << "And amongst the living are seen, carriers of the accursed Darksign." << endl;
    cout << "Yes, indeed. The Darksign brands the Undead and in this land, the Undead are corralled and led to the north," << endl;
    cout << "Are locked away, to await the end of the world. " << endl;
    cout << "This is your fate." << endl;
    cout << "" << endl;
    system("PAUSE");

    cout << "" << endl;
    cout << "You woke up in a deep slumber, what you see in the dark appears to be a prison cell" << endl;
    Sleep(1000);
    cout << "Not knowing who or what you are." << endl;
    Sleep(1000);
    cout << "You heard nothing but soothing echoes of a crisped, unwinding flames in the distance." << endl;
    Sleep(1000);
    cout << "Pondering of how you end up in here or purpose of being here" << endl;
    Sleep(1000);
    cout << "You looked around to find a way to escape this cell." << endl;
    Sleep(1000);
    cout << "So far you can only see a bucket, a wooden bench hanging from the wall with chains and a rusted metal rod." << endl;
    Sleep(1000);
    cout << "You noticed that the metal rod was rotten, one hit and it will break. " << endl;
    Sleep(1000);
    cout << "You sat down on the wonky bench, and noticed something shiny inside the bucket" << endl;
    Sleep(1000);
    cout << "Inspect (bucket) ? " << endl;
    string inspect;
    cin >> inspect;

    if (inspect == "bucket") {
        cout << "You inspected the bucket, you found some pieces of a makeshift lockpick.\n" << endl;
        cout << "You're wondering if this lockpick is stable enough to open the cell gate.\n" << endl;
        cout << "(use) lockpick /" << endl;
        string locka;
        cin >> locka;

        if (locka == "use") {
            cout << "You try to nudge carefully while using the makeshift lockpick.\n" << endl;
            cout << "You have successfuly opened the cell gate." << endl;
            system("PAUSE");
            return EXIT_SUCCESS;

        }

    }
}

I only ask for tips not for you to finish my work, this is just a side project (not school, well it is but i want to continue it even more)
THANK YOU IN ADVANCE :)

kidspointdotin commented: Awesome... +0

Recommended Answers

All 4 Replies

To skip the initial text, you can modify your loop as follows:

        int x = 0;
        bool beep = true;
        while (hello[x] != '\0')
        {
            cout << hello[x];
            if (beep && hello[x] != ' ' && hello[x] != '\n')
                Beep(950, 50);
            x++;
            if (GetAsyncKeyState(VK_ESCAPE))
                    beep = false; // stop the beeps if Escape key is pressed
        };

The if statement is straightforward, not sure why it would not work for you, e.g.:

  if (inspect == "bucket") {
        ...
    }
    else if (inspect == "cup") {
        ...
    }
commented: it worked thanks, though now i can skip it, i wanna skip the narration but making bunch of strings made alot of errors +0

You've made a strong start, but you've quickly come to realize the limitations of your approach. Each step in the journey has to deliberately programmed by you. Also consider that if you need to change something, you will probably need to change many other places as well.

For something like this, I would suggest using OOP(Object Oriented Programming). You will need classes for items, monsters, weapons, etc. as well as a structure to represent the places that the hero will travel to.

I only ask for tips not for you to finish my work, this is just a side project (see : https://pnrstatus.vip/ , https://textnow.vip/ , https://downloader.vip/vpn/) (not school, well it is but i want to continue it even more)
THANK YOU IN ADVANCE :)

Hi,
What I add to what our colleagues said is to move all these texts and resources to external files.
So you will have all the texts in one file that you load or every step's text in a separate file.
That will make the code a lot smaller and easier to read. It will be easier to write the story because it becomes independant from the code itself (and the cout and cin).

Can i use same for my Project in C++ for my assignment...
is it working fine??

commented: do your own homework, kiddo. And ask your own questions rather than hijacking other peoples' old ones. -4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.