Sign in to follow this  
theadamSGT

text game

Recommended Posts

Roboguy    794
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
SKATIN_HARD    175
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
krikkit    792
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
Ready4Dis    180
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
theadamSGT    100
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
Stephen R    721
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
stylin    758
Quote:
Original post by stro
How would you turn this into a switch statement for example:

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

Couldn't you do this? (haven't tested it - should work at least for boolean returns and ints)

switch( Function1() )
{
case 0:
switch( Function2() && Function3() )
{
case 0:
// stuff
break;
default:
// stuff
}
break;
default:
// stuff
}


:stylin:

Share this post


Link to post
Share on other sites
Stephen R    721
Well, you proved me wrong [smile]. I tested out your code and it compiles. But I hope to god I never see that actually used in real life.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this