Jump to content

  • Log In with Google      Sign In   
  • Create Account

Master thief

Member Since 01 Oct 2006
Offline Last Active Oct 03 2014 05:07 AM

Topics I've Started

Need advice for user input parser for text adventure

27 September 2014 - 03:29 AM

This isn't the first time I'm doing this, but the first time it was simpler than what I intend now. My goal is to add a little bit of depth. My concern is mostly with how to handle this in the code, although I'm also struggling a bit to find a good way to describe objects and items in an external file, as well (not which format to use, just what elements to consider (name, ID, what variables, etc). So I guess my problem is twofold. 
A few examples of the input I would want to allow: (I'm using parentesis to mark irrelevant commands and commas to mark actual object names. Doing this only for clarity, the user wouldn't type type the markers. Also using slashes to separate equivalent commands.)
lock east door / lock "front door"                     (assuming "front door" is the one at the east)
cover east window (with) sheets / use sheets (on) "big window"
combine key (with) clay / use key (on) clay
(the object names, by the way, is what I thought could be used to distinguish two doors that might be in the same room, for example, as well as allow the player to refer to them by the name they see in the descriptive text of the area they're in)
I'm curious to know how people would go about doing such a thing. The last time I did it I ended up with an gigantic function with a switch() with many switch()'s inside it. I used arrays to separate and store the commands by categories (specials (quit, help, save...), verbs, directions, etc) and their short versions if available in subsequent dimentions, like this,...
string specials[3][7] = {
    {"exit", "quit", "help", "back", "save", "load", "\0"},
    {"----", "qqq" , "h"   , "bk"  , "----", "----", "\0"},
    {"\0"  , "\0"  , "\0"  , "\0"  , "\0"  , "\0"  , "\0"}

...and when I received input I'd compare them to find in which array the command was, and in which column.The column would be the criteria I'd handle in the big switch(). But I never went any further than to accept one command, because, like now, I was struggling to find a way to do it that made sense. My vision was that it would require at least one more huge switch() like the one I already had.

Considering the ammount of combinations, my guess is that I'll have to reduce whatever I get to a set of main commands, (i.e., "cover" and "combine" would evaluate to "use", "walk" to "go", etc.). Being that the case, I wonder if an enum would be of any use. I also wonder if my intermediary method with the arrays couldn't be superseeded by something else more handy.
That's the kind of thing I'm trying to figure out: the tools that are reasonably adequate for the job. Not how to code it, but what to code it with. I may come to simplify/streamline my goals, but I'll have to see what I can do before I make those decisions. Inform games had a pretty neat system for input, I wish I could see a source code for such an engine, because most of the open source games I found on google used choice menus... :|
Any help/insights/advice would be really apreciated. Thanks. 

Needing some quick tips on how to organize my code

15 March 2014 - 04:37 PM

I've been learning C++ from a book lately and I've been making something of a console game/thingy, and a map editor for it... Whatever it is I'm just coding and it's being fun and interesting, but I've coded it all in one file, both because I wasn't expecting to get so far with it, and because I don't know any better. At some point I moved all the declarations into a header file to make it easier to tweak things without as much hassle, but it's still being a huge hassle, it's becoming too much to cope with. I'm well over 2000 lines of code (on the map editor alone, including comments and garbage), and I'm finding it too confusing. An example of a side effect I found was that I was assigning values to the same variable from three different functions during the initialization. But I'm finding it hard to detect and fix stuff like this in all of this mess.


So I need to separate my code into more files, but I haven't learned anything about classes or even header files yet. I "know" what they are and what they're for, but I can't make them on my own yet. So what I need is a quick (and maybe dirty) way to just break up the code and make it bearable, because if I stop working on it I'll eventually lose motivation to keep learning. It doesn't matter if it's a cheap thing to do, the project isn't important, it's just a way to get my hands dirty and learn from mistakes. Like my father said once, analogously, your first car is for you to break.


So if anyone could give me some hints or thoughts on how to go about separating the code into more .cpp or .h files I'd really appreciate it. My biggest problem is with avoiding calling the same header file from several files, I think. But I also feel confused on things like, should I just create header files, should I just create cpp files, should I create both as needed, and how do I determine if they're needed, and how exactly do I make the code from one file interact with the code from the other...


Any help is greatly appreciated. Thanks.

In what ways can a text adventure have combat?

10 December 2013 - 11:38 AM

I've been planning a text adventure for a long time now, and combat is the part that's been giving me some trouble. I'm trying to avoid "dice rolls" in my game, which makes matters worse, and I don't know if I can actually avoid it.


To give you a better idea of what I'm trying to achieve, this is not your ordinary text adventure but rather a more... graphical one, with actual buttons and maps, inventory, item icons, etc, and I'm even considering having some sort of NPC graphics for encounters and dialogues. Otherwise every feedback the player gets is text as usual.


In essence, my goal with the combat system would be, ideally, to provide the player with a chance to be skillful at it. But... again, I'm a bit at a loss on how to do such a thing in this type of game. So for now I'm trying to figure out in what ways can a text based game have combat, so that I can take as much into consideration as I can, and hopefully come up with something. Or if someone has any great ideas I'd be happy with that too. :)


Any help or insights would be greatly appreciated.

Trying to find an old DOS game, but don't know its name...

04 October 2013 - 05:32 PM

I've tried this in the past to find other games and it worked, so I thought I may as well try again.


Unfortunately I remember very little of the game, so what I'm about to describe won't be much and may be wrong or distorted memories, but maybe someone knew the game and remembers it by reading this.


To start off, the game was either a sort of an Adventure Game like Myst (but with many characters and dialogues) or Point&Click like Kings Quest 7 (I'm more inclined to the latter), quite low resolution, and somewhat colorful, I think. Might be a game from somewhere between 1991-94.


Now if I remember correctly, the game was a fable and it reminded me of Robin Hood children's fable version (and I think the main character was a fox too). I have a vague picture memory of a place that was either at the very beginning or very close to the it, and there were lots of characters. I'm not sure but I think it was some kind of party, I think it involved the King (even if indirectly and not with his presence) or some royal figures or authorities. The characters were all kinds of animals, but I do think it involved pigs. smile.png And I think it was in a forest. This may be far off, but nowadays when I think of that vague memory, it reminds me of that moment in the children's version of Robin Hood where he is in a bow and arrows competition with lots of people, some of them from the royal family.


Googling it didn't do much since the word fable just bombards me with... you know... Fable (II), and the descriptions don't really do much... If anyone recognizes anything like this, please throw in a name if you know it. Even if it's not exactly what is described, it may still be it (or it may be another great game worth reminding smile.png)



Do I (really) need openGL?

20 September 2013 - 06:44 AM

I was following some tutorials on C++ with SDL and openGL, and as I was listening to the guy he mentioned what may be a key point for me: "openGL is an interface to your video card, so you can do 3D things".


So I was wondering, is this entirely true? Would I ever need openGL for 2D games?


I'm not planning on doing anything 3D and I guess I won't be for quite some time. So if this is true I may just skip openGL learning for now and focus on what I actually need.