EDIT: Bummer! I should have posted this on the Games forum. I apologize. If some moderator would be so kind...
It came the time I'm wanting my game to do something. Have been designing most of the core and testing the classes in isolation. Now I need to actually move the player charater, look at a room, get an object from the floor, etc... And do this by simply typing the command in the prompt.
The game is console based. For IO operations I'm wanting to use ncurses (PDCurses to be accurate) so that I can take advantage of colors in the console. The reason being I want to minimize any work in porting it to Linux and Mac.
What I'm thinking doing is designing two singletons CPrompt, CParse.
CPrompt - responsible for IO operations. It wraps ncurses functionality, accepts input from the user, sends to CParse and waits for results. Outputs results to screen.
CParse - Parses commands, returns error or sends to correct objects for processing.
Various objects - Receive processing requests (calls to their interface) and send results back to CPrompt for output.
Graphically this looks like the image provided bellow.
However, I'm not sure of this design on a few points:
- CPrompt is supposed to wrap ncurses functionality, but by having the various object communicate directly to it, I'll be forced to provide ncurses functionality on the objects themselves. Or probably complicate my code by sending to CPrompt also the output format requirements.
- CParse seems to be doing too much; parsing the input and deciding on which objects to call. Is it better to provide some form of messaging system between CParse and the objects? And how would this be implemented. Links to reading material (books or web) would be enough if you don't want to spend much time on this point.
- By making CPrompt and Cparse singletons I'm thinking on the need of having these two object in memory at all times. There is of course only one prompt. But CParse is less obvious as a good candidate for a singleton class. It's the fact that it will be staying in memory at all times that moves me into making it a singleton. However, should it be ever-present? Is it more logical to have it be destroyed after each parsing?
I would really love your help on this. Understanding the programming language is becoming less of a challenge as time moves on, but applying this knowledge is the real challenge.