text game

Started by
11 comments, last by UnsilentStorm 18 years, 8 months ago
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?
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).
okay thanks and i would to see a little text game
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.
okay il try that thanks.
Moved to a more appropriate forum.
Dan Marchant - Business Development Consultant
www.obscure.co.uk
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.
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 ;)
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.
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}

This topic is closed to new replies.

Advertisement