Sign in to follow this  

text game

This topic is 4518 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

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
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

This topic is 4518 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.

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