• Advertisement
Sign in to follow this  

A game with a console interface and GUI

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone, I'm writing a small strategy game in C (not C++) and plan on implementing a console version (curses) for various systems, as well as a GUI version (SDL maybe). The problem is, I don't know exactly how to go about organizing my code. I know that I must separate the game's core code from the user interface code, but I don't know the best way to organize it all. I would also like to keep the code easily portable between systems as well. If anyone knows of a working example of such a program, or has some tips, I would be very grateful. Thank you for your time.

Share this post


Link to post
Share on other sites
Advertisement
What you could (should?) do is essentially design an interface of all the functions your console/SDL code will call. They dont need to know HOW it works, just THAT it works.

For instance, a move command for a unit would be completely defined in the unit (or game, or map or world class) but it would be accessible by the window/console in some way. For instance, pressing a move button and then a location would call the 'move(unit, location)' method which would handle everything.

Drawing stuff should be a factor of retrieving information from another class, not from within the interface class. For example:


for(int i = 0; i < game->units.size(); i++)
{
if(game->units.within(screen))
drawUnit(&game->units);
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement