# text game

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

## Recommended Posts

I think i know what i need to know to make a text game. i use c++ devcpp and im on windows i wanna make a text game or evene possible an online text game but where do i start or how do i start

##### Share on other sites
Hey bro, Devcpp is cool but i just want to spread some luv, and give you a good link.

• Hey bro, Devcpp is cool but i just want to spread some luv, and give you a good link.

VC8

Its only free for a limited time....

I guess i would suggest just doing a text game offline since you dont know where to start, i dont what to say besides thats the most easiest thing a coder can do(i think) Where you should start? Its a text based game, you can start anywhere really, start on the classes that hold your items, or weapons and armor, and character info. I dont know anybody who actually writes everything out on as a rough draft, unless they're doing a MUD(Something really big) A text based adventure doesnt sound too much fun to code, i ve done one myself, and the way i did it was:

*
1.) Created my Classes , with just writing a few variables within them..
i.e. Items, Weapons Armor, Charcters, NPC's, Relics, Messages.

*
2.) Started the story
i.e
Welcome to EpicDragons
Enter your name blah blah blah

You are in the middle of the Asrhobi Shrine, where you see 2 faires, a Scroll hanging on a fountain glittering of Gold and many colors, Pouring out water as clear as an opaque puke covered windshield!!(LOL)

Input Selection Player
1 - Talk to faire 1 2- Talk to faire 2 3 - read scroll 4 - puke on faire
5 - Walk south 6 - Walk north 7 - Attack Fairie 8 - Open Treasure chest

*
3.)Then i would goto my classes and add in an item to put in the treasure chest

So you see just go along and fill in the blanks i hope thathelps.....
I f ya need anyhelp just let me know im actually willing to revise what i know!!!

##### Share on other sites
Quote:
 Original post by BluseedIts only free for a limited time....

No, it's not. [edit: Err, the link was "Visual Studio Express Editions are Free Forever!", the article isn't very clear on that, the FAQ is clearer]

##### Share on other sites
o ok correction!! lol even better...

##### Share on other sites
I'll just say that I use Bloodshed's Dev-C++ and I also have the "free" Visual C++ Express Elite Uber-Lite Edition...

I'll stick with Bloodshed.

On that note, creating a text adventure is fairly easy, usually these work along the lines of the old "Choose Your Adventure" books where you'd read to a point and then be given a choice that would have you either "Turn to Page 28 if you're secretly evil" or "Turn to page 162 if you're the paradigm of angelic perfection".

This is basically what happens in a text-adventure game. So what you'll need first are some classes as Bluseed mentioned, off the top of my head, I'd say you need a class that will represent items, characters and perhaps weapons if you want to get into an actual combat system which may be a bit too complicated at this point, if you're going for the most bare-bones implementation you can.

Your player would be a character and would probably contain a variable to say which "room"(read part of the plotline) he is in and some manner of container (vector, array, doesn't really matter much) to hold all the objects in his inventory.

When we start the game, we display the first "room" object to the player, which is a class/struct that has something like a "Description" string variable that will comprise the bulk of our game. This could be something like Bluseed suggested but I'll expand on it just a bit.

Quote:
 Walking through the dank entryway you find yourself in a large cavern. A huge treasure chest stands along the eastern wall surrounded by a group of pixies twinkling with laughter. Gaping black holes in the souther and western walls lead to tunnels heading deeper into the heart of the fortress.

This would of course be the room's "description" probably a generic string for the sake of allowing them to be longer or shorter dynamically. After this description is shown to the player, we present them with a list of possible "paths" that they can follow, for example:

Quote:
 1. Approach the pixies and attempt to make conversation. 2. Sneak past the pixies and down the southern tunnel. 3. Attack the pixies!What do you do? /*get player input here*/

The function for this choice can be as simple as a switch statement along the lines of:

int decision = 0;cin >> decision;switch(decision){    case 1:        do this;    case 2:        do this instead;    case 3:        do something else;    default:        cout << That's not a valid option! << endl;}

Depending on the path that the player chooses we flash them the next update of text or "room" if you will, even though their imaginary physical presence in our made up fortress may not have moved. We continue this process until the player reaches a termination point in the "game" that is a specific place that we have decided either they will succeed or fail.

Using my shoddy psuedo-code/psuedo-writing above, you could most likely make the entire game without ever needing anything more than #include <iostream> and #include<string>.

Of course, you could always circumvent the string header/usage entirely and just use string literals, but I always like to think towards future expansion and storing things as string variables will allow greater flexibility in the long run.

My two cents, something to chew on,

Vopisk

##### Share on other sites
Just like Vopisk said:

Quote:
 Of course, you could always circumvent the string header/usage entirely and just use string literals, but I always like to think towards future expansion and storing things as string variables will allow greater flexibility in the long run.

As ur going through your text based adventure game, think of, and create things that kinda go further then just a text based game, really challenge the language and use it to your advantage...
i.e when you come to a scene in your gam, like when the army starts rushing into Narshe(Final Fantasy3/6 village), as the player is typing in the input have the text shake like an earthquake to give the player a feeling of being in Narshe. I know thats a challenge, lol, but your learning how to do things within the C++ enviroment.

##### Share on other sites
Quote:
Original post by Bluseed
Just like Vopisk said:

Quote:
 Of course, you could always circumvent the string header/usage entirely and just use string literals, but I always like to think towards future expansion and storing things as string variables will allow greater flexibility in the long run.

As ur going through your text based adventure game, think of, and create things that kinda go further then just a text based game, really challenge the language and use it to your advantage...
i.e when you come to a scene in your gam, like when the army starts rushing into Narshe(Final Fantasy3/6 village), as the player is typing in the input have the text shake like an earthquake to give the player a feeling of being in Narshe. I know thats a challenge, lol, but your learning how to do things within the C++ enviroment.

(S)He only THINKS he has the necessary knowledge to make a simple text-based game and you want font-shaking?! Haha! Remind me never to work for you :p

I'm pretty sure there's no way to actually do that in the console... pretty sure... and that's where the 99th percentile of your text-based adventures will fall into, to give us that good ol' DOS feeling :) Unless of course we want to create a custom GUI with spiffy graphics and whatnot, but that might be overkill for a text game :)

##### Share on other sites
Personally have always found the MUD-like games, not in scale, but in mechanic ,where instead of reading, and choosing between x number of possible options for advancement, you instead type things like 'pick up the lantern', and are presented with a ascii map with descriptions of where you are. I did one of these, and found it to be an absolutely invaluable experience in learning parsing and parsing methods, along with state machines and crude AI.

Also gave me huge experience when i wanted the player in my more advanced games to be able to talk to NPC's by typing, and have them actually respond to what the player typed, which sure beats the pants off of a number of other methods, like listing chat options, or click-to-open-a-shop-window options, and allows your NPC's to fill multiple roles.

Its a hard task if you take this route, and if you're looking for choose-your-own-adventure kind of things then you'll have a much easier time of things.[which is good to get your feet wet, and for learning how to make your games data-driven, and force your to organize your data well, which is absolutely required in larger games]

##### Share on other sites
I'd agree with you there Peachy, a mud-type interface is the next logical step up from a choose your own adventure style game. However, I like the choose-your-own-adventure style game because it provides the basis of collecting input from the user, using it in someway to affect the next set of output from the game and as you mentioned data and program management, since we also threw a couple of classes in there for extra confusion and good measure.

I've come more and more to believe in the practice of taking the simplest steps first, even if it seems like you can breeze right through them with whatever rudimentary knowledge you have, because nothing substitutes for real-world experience and it's better to figure out the smaller problems that can be resolved with these simpler excercises so as to avoid the headache of finally trying to figure out manipulating player input and classes on the larger scale of a mud-type interface.

##### Share on other sites
Quote:
 (S)He only THINKS he has the necessary knowledge to make a simple text-based game and you want font-shaking?! Haha! Remind me never to work for you :p

LOL yah its too much for a text based game but I was only givn an example(bad example, ok lol), yes that is far out there and overkill.

##### Share on other sites
It's probably also impossible unless you wrote your own console... Hmmmmm.

That gives me an idea.

##### Share on other sites
If you allowed the shaking to mean 'move the entire block of letters over one character space' then it should be possible with the right functions. Eg:
 Screen1     Screen2     Screen3     Screen4+-------+   +-------+   +-------+   +-------+| Hello |   |       |   |  Hello|   |Hello  ||       |-->|  Hello|-->|       |-->|       ||       |   |       |   |       |   |       |+-------+   +-------+   +-------+   +-------+

And just time it correctly. Also you can, instead of writing onto the screen, write to a buffer and then 'flip' the buffer to the screen directly. You could also write blitting functions to more easily display 2D ASCII designs. There's quite a bit you can do with creative ASCII usage.

##### Share on other sites
can 1 of u guys give me some a code to a text game u guys have made so i can look at it and like follow it a bit not copy but just see what i need in it you know as a guide

##### Share on other sites
I would stick with DevC++ if you are just starting, it is easier in my opinon, and you dont have to worry about extra stuff with options as you would in MVC++.
I have MVC++ .NET and to tell you the truth, I like Bloodsheds lovely gem compiler ( which is also free like MVC++ 8 and unlike MVC++ .NET (unless you are a pirating bastard)); anyway , almost as much!!

##### Share on other sites
I'll give you some code from a text game.

void Server::PlayerInput(const std::string& text, Database::ObjectPointer player){	assert(State::empty() && "[PLAYERINPUT] State stack was not empty");	assert(!text.empty() && "[PLAYERINPUT] Text was empty");	assert(player && "[PLAYERINPUT] Bad player objectpointer");	State st;	State::sender() = player;	std::list<std::string> words;	SU::Tokenize(text,words);	if (words.empty()) 	{		player->send("Don't do that.\n");		return;	}	std::string cmd = boost::algorithm::to_upper_copy(words.front());	words.pop_front();	std::string script;	std::string func;	jisp::type_list pi;	if (!search_command_set(cmd,words,cmds,player,player,script,func,pi))	{		if (!player->location || !search_command_set(cmd,words,														player->location->commands,														player,														player->location,														script,func,pi))		{			player->send("I don't recognize that command.\n");			return;		}	}	ScriptInterface::ContextWrapper ctx;	int func_id = ScriptInterface::FetchFunction(script,		std::string("void ")+func+"(type_list)");	if (func_id < 0) 	{		player->send("[Command definition error]\n");		return;	}	ctx->Prepare(func_id);	ctx->SetArgObject(0,&pi);	ctx->Execute();	return;}

Oh, wait, that wasn't helpful at all.

##### Share on other sites
I'll have to dredge up one of my old text games. Of course, now that I know about the wonderful world of std::string I could probably build a better one.

Maybe I'll do that.

##### Share on other sites
I should get working on my mud again. Looking at that terrible code really made me miss it. It parsed natural english. It just had a very limited vocabulary...

##### Share on other sites
so any 1 got a one of their text games code i can use as a guide

##### Share on other sites
I think text game is fine to start, and can be a very good kind of pratice . Just do it like a real project and not like if if was "only" a small not-fun project .
Build a script engine, some AI and maybe a small level editor .
[ script engine will be your main focus IMHO ]
Good luck .

##### Share on other sites
First of all, please forgive my bad english...I'm not a native english speaker, so have mercy.

As I came across this post a few days ago, I thought, that this would make a good weekend project, so I spent my weekend on it.
It's far away from being finished and also from being good (especially the readme), but you can download the code and have a look at it.
By now it's like a 'cat' with an inputloop, inventory, 'links' in pseudo-script and a save/load function. You can make up the entire 'game' by filling out the *.txt files...no need for recompiling once you get it up and running.
There is no AI, font shaking, character- or battlesystem , so don't expect too much.

Since I'm running Debian GNU/Linux on all of my computers, I have no idea if this code works on other OSes...but I'm not using any specific commands (syscalls or external progs), it's purely c++, so I think it should work.

You can get the latest version (by now this is 0.02) from this folder:

http://tech-9.netcay.ch/tbge/

If you like to contact me, you'll find my email at the end of the README.txt.