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

#5183263 Need advice for user input parser for text adventure

Posted by Master thief on 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. 



#5141292 Needing some quick tips on how to organize my code

Posted by Master thief on 22 March 2014 - 02:53 PM

One question, from what I understand from what I've been reading, vectors are great to be used for, say, a player or a room's inventory. Would they be just as good for maps? Considering that the maps as I'm using them, are just an array of ints, I suppose at first they might be, but then the maps are sort of constant (the number of elements never changes in a map, an index's value can change (i.e, closed door (visible)/open door (not visible), but that's about it).

If so then I wonder if I have any use for arrays at all for what I'm doing.


#5139674 Is Adobe Flash any good?

Posted by Master thief on 17 March 2014 - 04:26 AM

You definitely can (I don't know about steam and mobiles though), but I don't know if it's the best option. I've coded a lot in actionscript 2 a few years ago, and it was quite limited (and cpu intensive). Its limitations weren't so much of a problem if your goal was to release games on Kongregate or something, but they kind of turned me off since I was thinking of expanding myself.

AS3 seems much better in many ways, but for the same purposes you could maybe delve into HaXe/openFL (or maybe Flixel or HaxePunk). I find HaXe's documentation a bit lacking, but openFL is basically 99% AS3 only with another name and less limitations and HaXe's functionalities alongside, and AS3's documentation is said to be really useful for it. Papers Please, though different from your goal, was developed in NME (which is the former name for openFL).

I find HaXe/openFL to be quite tempting, to be honest. But some people pointed out some other options here that I've been hearing good things about too. I'm not at all knowledged in any of them, so I can't really comment on them.

That said, I wouldn't say you shouldn't go for flash. It's still a good option in many ways, I find. Even if it's in decline.


#5139661 Needing some quick tips on how to organize my code

Posted by Master thief on 17 March 2014 - 03:05 AM

I read (vaguely) something about complexity somewhere but I can't recall where... Not sure if it was in the book I'm reading. Which is C++ Primer, by the way.

My only fear at this point - 5 chapters away from classes and not yet much more versed in anything that I wasn't before - would actually be to end up repeating myself, even if I was trying not to, since if I delve into another project the only things I'll do better right now are maybe just to make use of a few more I/O functions and a few tricks I learned about strings.

Or maybe, since the map editor is pretty much finished (except for one slightly important functionality that I couldn't implement due to the messy code (and loading maps)), I might get back to the game itself and start applying whatever else I learn in the next days.

But maybe I'm getting ahead of myself in my thinking. I'll do some reading as you suggested. Thanks.


#5139594 Needing some quick tips on how to organize my code

Posted by Master thief on 16 March 2014 - 08:21 PM

No APIs, just pure c++ and the console. I'm not sure if it matters much but since I'm making it purely on the windows console, the "rendering" may be a little different. Still, I'm doing something comparable to double buffering, where I'm drawing everything to an array, clear the screen, and then draw the whole array on the screen. That's why I named that function blit(), it was just the first thing that came to mind when I needed a name for it. Same with one I have called doThingsWithInput(). smile.png

 

Here's the source code, by the way. If it matters.

 

The way I'm "rendering" it has it's caveats, is kind of slow and forced me to use system calls (for CLS - and this is because I didn't want to have the whole history of the console above, and also because the scrolling seemed worse to watch) for lack of better options. I made a post on TIG about it but no one seemed to have any better solutions that didn't involve external libraries. Still, I'm not really worried about that, I'm more worried about progressing. I'll do something better with SDL one of these days. I'm also enjoying the challenge of getting around the limitations of the console.

 

So, I don't know, since everything that needs to be drawn is drawn on that array before it gets drawn on the screen, either everything draws in it, or everything tells the class what to draw in it... I suppose those are the options, but I'm not sure which to choose. But if I choose the latter, I'm not sure how to make that class grasp every other class's needs.

 

So the first option, which is basically what you're saying, seems easier.




#5139546 Needing some quick tips on how to organize my code

Posted by Master thief on 16 March 2014 - 03:13 PM

I started placing stuff into a new file just to see if I could make sense of it. This is what I could gather so far, but I have conflicting ideas here:
 
I don't know if I should ask the GraphicsM class to draw the map on the buffer, or if that class should allow other classes to draw on it. Or maybe I'm missing something else that might solve my dilema. Or maybe I'm simply doing it all wrong. smile.png

class GraphicsManager
{
	private:
		char tempBuffer[18][35]; 

	public:
		void drawOnBuffer();   // draw something on the buffer?
		void blit();
		void clearBuffer();
		void paintBackground(int symbol);    // paints background with the specified ascii symbol
};
class Map
{
	private:
		int map[18][35];  // the object is given a map from an output source (file), or from user interface (map editing)
		int tileset[2][7];  // class stores active tileset here

	public:
		drawMap();  // draw the map to the buffer?   // or maybe ask the graphics manager to do it instead?
		drawTileset(); // draw the tileset to the buffer?
};

I still haven't read about constructors and such, so don't mind the lack of anything that may be lacking. This is not even the real thing, it's just me trying to understand how to put it together from the code I already have and from what I already learned (which isn't much).




#5139448 Needing some quick tips on how to organize my code

Posted by Master thief on 16 March 2014 - 09:09 AM

@dejaime, from reading that article, which I noticed is quite class heavy (which I guess was to be expected), I think I have to admit that separating code and creating classes seem to be two things that don't really go too well without each other. But classes are 6 chapters away in the book.... I guess I'll make a detour and see what I can manage to do.

 

I kind of noticed CB had themes, but I didn't feel like losing time with it. I may still try some sometime. One thing I noticed about CB is that it allows you to create a list of "user keywords", which probably helps if I want to make it look more similar to ST. But this is something I don't want to get distracted with right now. It's been two days since I last messed up with my code, and it was always distractions that made me end up stopping in the past...

 

@tanzanite7, sublime text isn't a "proper IDE", it's just a proper generalized text editor with lots of potential to be a decent coding environment. Much like TextMate (I think) and Vim and another one I can't remember. But of course it never reaches the same level of functionalities of an IDE that's made specifically for a language. I will probably want to use the debugger at some point.




#5139355 Needing some quick tips on how to organize my code

Posted by Master thief on 15 March 2014 - 07:21 PM

Thanks everyone for the responses. It's being quite insightful. I'm going to try some stuff tomorrow.

I've also just found an article that may also be helpful, though not today. smile.png

 

@Vortez, about the classes, I have... some degree of awareness on how to make them and how to use them, since I was starting to use them in actionscript 2 a few years ago before I stopped coding then. But there's two problems: 1-  I always just create a bunch of files and end up staring at them indecisively, due to not quite having an idea where to put what, and 2- I'm not yet familiar with c++'s syntax for classes and their baggage. I skipped a bit in the book I'm reading to quickly get to pointers, but I'm intending to get back to what I skipped (structs, enums, and more on strings). I don't want to rush it.

 

@dejaime, well... I'm extremely (really) picky when it comes to colors. I can't stand writing code in a white background, and I like to just get my hands dirty when I'm learning something. All the IDEs I tried (well, CB, VC and DC, don't know any others), kind of got in the way of it. There's always something that needs to be set or some intricacy that needs to be understood (i.e., project templates, MS's main() arguments), or otherwise something that doesn't work for very specific reasons. I've been away from C++ for years because of this. Also, they clutter my hard drive with project folders (VS is particularly unorganized, it mixes projects from all apps in one folder by default) when all I want at this point is a source file to experiment with. When learning the basics, I need a basic setup to get right down to it and keep me focused and without obstacles.

 

To that end I'm using Sublime Text for now, which seems to work well so far, though I see times where an IDE would be beneficial. But I find that those apps aren't much good at replicating the level of customization from ST, sadly. ST is great in it's keyword highlighting and dark background, it makes me feel extremely comfortable. So, at least for now I'm stuck with it. That said, I'm still using CB to, for example, compile tutorials I'm following on SDL. I code them in ST and compile them in CB. I still think it's too early for me to be delving into their distractions. I rather be reading the book instead of losing time with the IDEs.

 

 

EDIT: By the way, should, or could, variable declarations go on (non-class) header files too?




#5139321 Needing some quick tips on how to organize my code

Posted by Master thief on 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.




#5116662 In what ways can a text adventure have combat?

Posted by Master thief on 13 December 2013 - 05:30 AM

reference material
http://dwarffortresswiki.org/index.php/DF2010:Combat#Mechanics

Quite surprising stuff. Also quite a bit... overkill. smile.png

My goal is something simple yet versatile. Though I guess that isn't saying much.

One thing that occurred to me yesterday: Are there any sort of combat mini-games out there that I could take a look at too? I feel like some elements from other genres like adventure games and dungeon crawlers can easily adapt to what I'm trying to achieve. In fact, some things I planned are very much like dungeon crawlers in a way, now that I notice it. But combat in DC's isn't usualy something I find too interesting. I like them, but I feel they're a bit lacking...
 

What kind of  "dice rolls" are you trying to avoid?

I was refering mostly to the typical ones found in most RPGs such as the old Baldur's Gates and Arcanum/Fallout, and even on Bethesda games (mostly on thievery).

The type of dice roll that tells you you have X% chance to fail to pickpocket or hide in shadows or to miss a sword swing, which I always found a bit obnoxious. There are situations in which I don't really mind them, but... And I'm not entirely against them, they just detract me from immersion a bit in those games. If I can't avoid them, so be it. But I always found that, for example, I had more fun being a thief in the Thief series than on any RPGs.


PARTNERS