Jump to content
  • Advertisement
Sign in to follow this  
theadamSGT

text game

This topic is 4854 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

how do i make a text game in c++ like do i use the switch statement or something else? could someone post source codes for a tiny text game?

Share this post


Link to post
Share on other sites
Advertisement
That's a very generic question. Yes, a switch statement could be involved, but it doesn't have to be (all switch statements can be replaced by if statements, but not visa-versa).

Share this post


Link to post
Share on other sites
I text based game written in c++ wouldn't be too hard to implement. You could use <string.h> and vectors to take and get input. Threads about text based games have been around the forums a good bit. You could use the search function to try and locate said threads. I remember that one member posted mostly the full source for a text based game in the forums. You could also just google for "text game source code in c++" and see what comes up.

Share this post


Link to post
Share on other sites
Using switch cases would be hardcoding your entire game. Most text games have what is called a parser, something that is able to understand a simple language structure (Action verb) and then you would have seperate files containing your rooms data, item data, and extra text, so your game would load your room data, and then your parser would check what the person enters against the capabilities of the items and actions that are stored in your other data.

Ie, you wouldnt have
Switch case 1: "pick up hammer"
switch case 2: "pick up sandwich"

Instead, your room would be loaded, it contains a sandwich, which has the ability to be picked up by using the verb "pick up" in relation to itself.

Share this post


Link to post
Share on other sites
Quote:
Original post by Roboguy
That's a very generic question. Yes, a switch statement could be involved, but it doesn't have to be (all switch statements can be replaced by if statements, but not visa-versa).


I contend your statement about not visa-versa... of course you can do it both ways, it'd just be REALLY ugly with embedded switch statements ;)

Share this post


Link to post
Share on other sites
Quote:
Using switch cases would be hardcoding your entire game. Most text games have what is called a parser, something that is able to understand a simple language structure (Action verb) and then you would have seperate files containing your rooms data, item data, and extra text, so your game would load your room data, and then your parser would check what the person enters against the capabilities of the items and actions that are stored in your other data.

Ie, you wouldnt have
Switch case 1: "pick up hammer"
switch case 2: "pick up sandwich"

Instead, your room would be loaded, it contains a sandwich, which has the ability to be picked up by using the verb "pick up" in relation to itself.





how do i do that.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ready4Dis
Quote:
Original post by Roboguy
That's a very generic question. Yes, a switch statement could be involved, but it doesn't have to be (all switch statements can be replaced by if statements, but not visa-versa).


I contend your statement about not visa-versa... of course you can do it both ways, it'd just be REALLY ugly with embedded switch statements ;)


Roboguy is right. How would you turn this into a switch statement for example:

if (Function1()) {
//stuff
}
else if (Function2() && Function3()) {
//stuff
}
else {
//stuff
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!