Build a Text Adventure Challenge Project (C++)

Congratulations on completing your project!

Compare your project to our solution code and share your project below! Your solution might not look exactly like ours, and that’s okay! The most important thing right now is to get your code working as it should (you can always refactor more later). There are multiple ways to complete these projects and you should exercise your creative abilities in doing so.

This is a safe space for you to ask questions about any sample solution code and share your work with others! Simply reply to this thread to get the conversation started. Feedback is a vital component in getting better with coding and all ability levels are welcome here, so don’t be shy!

About community guidelines: This is a supportive and kind community of people learning and developing their skills. All comments here are expected to keep to our community guidelines


How do I share my own solutions?

  • If you completed the project off-platform, you can upload your project to your own GitHub and share the public link on the relevant project topic.
  • If you completed the project in the Codecademy learning environment, use the share code link at the bottom of your code editor to create a gist, and then share that link here.

Do I really need to get set up on GitHub?
Yes! Both of these sharing methods require you to get set up on GitHub, and trust us, it’s worth your time. Here’s why:

  1. Once you have your project in GitHub, you’ll be able to share proof of your work with potential employers, and link out to it on your CV.
  2. It’s a great opportunity to get your feet wet using a development tool that tech workers use on the job, every day.

Not sure how to get started? We’ve got you covered - read this article for the easiest way to get set up on GitHub.

Best practices for asking questions about the sample solution

  • Be specific! Reference exact line numbers and syntax so others are able to identify the area of the code you have questions about.
1 Like

First time on github not sure if im linking this correctly

1 Like

Got a bit carried away; made the whole thing modular for future development so made the Player and Locations Classes to practice.

Really proud of it as my third ever C++ program, still confused as to why I can’t seem to loop over an array of class objects and activate their methods but I will figure it out.

1 Like
1 Like
1 Like
1 Like

#include

int main(){

int choice,choice2,choice3,choice4;

std::cout<<"Welcome to the trip.\n You just exit your home. \n To which direction do you walk ? \n 1) Left \n 2) Right\n Answer= ";

std::cin >> choice;

if (choice==1){

std::cout<<"You have found your best friend on the way ! \n He proposes you to go to the cinema. Do you go with him ?\n 1)Yes\n 2) No\n Answer=";

std::cin>>choice2;

if (choice2==1){

  std::cout<<"Great! You stayed the whole day watching a film! \n The game has ended";

}

else if (choice2==2){

  std::cout<<"You failed ! \n You stay in the street and get eaten by dinausors. \n The game has ended";}

else {std::cout<<"You have given an invalid answer";}

}

else if (choice==2){

std::cout<<"You have found an Apple tree. \n What do you do ? \n 1) You eat an Apple \n 2) You don't eat an Apple\n Answer=";

std::cin>>choice2;

if (choice2==1){

  std::cout<<"A Mars citizen comes to meet you\n Do you choose to talk to him ? \n 1) Yes \n 2)No \n Answer=";

  std::cin>>choice3;

  if (choice3==1){

    std::cout<<"You go with him to march. Amazing ! \n The game has ended";}

  else if (choice3==2){

    std::cout<<"He leaves to Mars and you come back home. \n The game has ended";

  }

  }

else if (choice2==2){

std::cout<<"You have found your best friend on the way ! \n He proposes you to go to the cinema. Do you go with him ?\n 1)Yes\n 2) No\n Answer=";

std::cin>>choice4;

if (choice4==1){

  std::cout<<"Great! You stayed the whole day watching a film! \n The game has ended";

}

else if (choice4==2){

  std::cout<<"You failed !\nYou stay in the street and get eaten by dinausors. \n The game has ended";}

else {std::cout<<"You have given an invalid answer";}

}

else {

std::cout<<"You have given an invalid answer\n";

}

}

}

Check out this love story of you and a girl named Rachel. All over a bite of breakfast…

#include <iostream>

int main() {
    //variables
    int choice;
    char cont = 'y';

    //logic
    while (cont == 'y') {
        std::cout << "=========================\n";
        std::cout << "Choose Your Own Adventure\n";
        std::cout << "=========================\n\n\n";

        std::cout << "*Beep Beep Beep* Your alarm goes off. It's 6am. Time to get ready for school...\n";
        std::cout << "Do you 1) sleep in or 2) get ready for school: ";
        std::cin >> choice;

        if (choice % 2 == 0) {
            std::cout << "\n\n---\nYou wake up, put on clothes, brush your teeth, put on deoderant, and walk out to the kitchen...\n";
            std::cout << "Do you 1) skip breakfast or 2) make breakfast: ";
            std::cin >> choice;

            if (choice % 2 == 0) {
                std::cout << "\n\n---\nYou make a delicious breakfast. You make it to the bus stop and remember just in time you have an exam. Before you start to eat, you notice a girl named Rachel didn't eat anything...\n";
                std::cout << "Do you 1) give her your delicious breakfast or 2) don't make eye contact and eat it anyway: ";
                std::cin >> choice;

                if (choice % 2 == 0) {
                    std::cout << "\n\n---\nYou sucessfully avoid Rachel and she never sees you devour your food. Later, that day, you pass the test with the top score in the class. You kind of feel bad, however, when you notice Rachel only got a B. YOU WIN!!!\n";
                } else {
                    std::cout << "\n\n---\nYou awkwardly sidle up next to Rachel and offer her your food. She's starving and you can tell she doesn't want to take it. You hand it to her anyway. \"Thank you so much,\" she whispers. You had no idea her family couldn't afford food, but you always thought she was kind of cute so you gave it to her anyway. Now, she likes you too.";
                    std::cout << "\n\nLater that day, you look at the test scores and see Rachel at the top of her class, with you right underneath. She walks up next to you, \"Hey, you wanna go somewhere Friday?\" she asks. Life is good. YOU WIN!!!!\n";
                }
            } else {
                std::cout << "\n\nYou make it to school and realize you have an exam. Your brain isn't quite functioning right and the whole class is laughing about your rumbling stomach. Too bad you didn't eat breakfast. THE END.\n";
            }
        } else {
            std::cout << "\n\nYour mother is very dissapointed in you. THE END.\n";
        }

        std::cout << "\nPlay again? (y/n): ";
        std::cin >> cont;
        if (cont == 'n') {
            return 0;
        } else {
            continue;
        }
    }
}
1 Like

Here is a Game I called ‘Fortune Lost.’ Watched a little too much Longmire recently and it’s loosely based on the series. By loosely, I mean very loosely. It was a lot of fun writing and I kept going off and adding more features. We will see where it goes. Let me know what you think. You can download the file off Github here:

Fortune Lost - Git Hub

1 Like

This is the matrix Build Text Adventure Project. Enjoy.

I mean it’s a work in progress, but I’m happily learning…

Hello everyone. This is my first C++ program of any weight. I’m not sure if I could have built it better or not, but it seems to work the way it is. Please enjoy the game. It has aliens, Bonanza, toast, bowling, and combat.

The Great Big Adventure

1 Like

My text adventure.

Nothing complex, but this is the first proper coding I’ve done from the skeleton and I was proud of myself for being able to make it somewhat clean; but I’m still very much a rookie, so if anyone would like to give me tips, suggestions, etc, please do. :slight_smile:

Amazing. You are really creative.

Just something a bit silly. There’s only one way to win the game and not die.

Not sure if this is the proper space for this, but can someone point me in the right direction? I’ve tried writing this 5-6 different ways, and this while loop either will not activate or breaks the compiler (infinite I think).

Take a look at your while loop’s condition:

while(choice1 >= 0 && choice1 >= 3)

choice1 is set to 0 so it can’t possibly fulfill this condition. What operators should you use to check choice1's relationship to 0 and 3?

Another point is that the loop is not quiet infinite but the only way to terminate it is to enter an invalid answer twice. It may work better if the loop continues as long as the users input is invalid.