design

Newbie Spellweaver
Joined
Dec 17, 2004
Messages
47
Reaction score
0
well i have an idea for a tottaly text based game.
my question is-do i have another option for keeping the text lines for the game, instead of using 9,000,000 var of string that each one of them contains a line.

any ideas?
 
You have several options.

First one would be, of course, to use those 9,000,000 strings at programming time.

Then, you could make an array of strings, but you'll end up using arraysize*stringlength of memory, half of it wasted as your strings most likely aren't of the same length anyway. This is a lot better already design-wise. Plus side over linked list is that you can refer to each line with line[n] instead of searching through them every time.

Then we have linked lists, which allocate memory at run time and only the amount needed. I don't know which programming language you're using, but for example in VC++ you can simply use CList class for this. If you have thousands of lines you might consider holding a pointer to each line in an array to eliminate searching.

The above 3 are basically different ways to hold the data, now you'll need to consider how to read it. Basically if the game contains more than say 20 lines you should load them off a separate file, which you can lookup for each line, one at a time and only hold in memory the one at use. However, the bigger the game gets, the slower this method becomes, besides I don't like the idea of straining HD like that.

I'd probably use a linked list with an array of pointers, reading all the data at once from a file, or if your storyline allows it, a chapter at once or so. The advantage with linked list is that you can use a list of structures too, using a variable or two to define "rules" per line for the game.



Btw, when I was a kid I wrote a text game "reader" in QBasic, which read a file line by line, interpreted commands and showed texts. Basically the approach was that the executable could be used with any file, thus making several games and never touching the actual program, as long as the file to use follows the format I defined.
A few lines might have been something like this:

...
2ndchapter|$h=100|t:Beginning of Chapter 2.|g:line2|
line2|$h-5|!h<10:line4|t:You're hit by a rock and lose 5 hp. You have $h left. Take a turn left or right?|k1:L,line2|k2:R,line3|
line3|$g+500|t:You avoid the traps and get out of the dungeon.|end|
line4|t:You're hit by a rock and pass out. Story continues...|
...

Actually I'm quite proud I did something like that when I was like 10+, it allowed use of variables and everything. Shame I don't have it anymore :(
 
Last edited:
Actually I really wouldnt be to concerned about it, even if you use an actual ammount of 9mill strings (lets say each string holds a max of 20characters) 9mill x 20 = 180mill bytes or 175-180 ish MBs. Yeah, its still a hell of a lot for a text game, but do you really think your going to use 9million? :P. Using a text file for your "9mill strings" would be a bit too much however, the hd is to slow for constantly reading through that text file all the time. It would be more of an issue on how to organize and track each string for the game. Use arrays, and have a string array for each type of thing in the game. Can you explain breifly what it is about? This should help your design question you asked...

on a side note =P, 175MB of your RAM for a text based game compensates for a modern games texture/model in take =P.. however, its still alot for just text.. I really hope you where just exadurating..
 
Last edited:
ok first thanks to all for your advices.
i am planing to use c++ but i do not want the game to take much memory or space, in other words i need it to be perfect and affective as i can.

about the number of lines (: yeah i was exadurating it will be something like close to 1000 different lines but thats just the start if all goes well, i will add more and more story.

negata i didnt quite understood how am i supposed to use link list...

basically im am writing a game prrity similair to the example negata gave, with a liitle more options like quests (i could be wrong and u had them too :P)places u can buy and store equipmant ( i mean like houses) exploring the sea buy commending your own ship etc.
 
Well quests and equipment are nothing but numbers to the program..

Tbh, if you want to make an exploration game you might be better off doing it with graphics cause in text only you'll get confused with too many if-elses.

Just use an array of CString's instead of linked lists in your program. If you want to know more about linked lists, there was a nice demonstration on en.wikipedia.org, for CList class details check msdn.
 
i need to learn to walk before i run (:
step by step, first text based game then as ill get the hang of it ill add graphics and so on.

escuse me but... msdn??.... :|
 
Actually what Negata said about using gfx instead, is not that bad of an idea for the type of game you want to create. I do recommend you get the text one going though, but maybe later try and do some graphical peices for it, using Direct X, and since your using c++, its perfect for that. The microsoft website including alot of others, should have basic/advanced tutorials for direct x use anyway, good stuff to learn ;). If you do eventually get around to graphical games, the only problem you will face is who will do the art, but there are alot of hungry people out there willing to help out for free to improve their own skills too, so possibly get a group on it too. Good Luck.
 
Back