Sign in to follow this  
OddityOnParade

A game with a console interface and GUI

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
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[i].within(screen))
drawUnit(&game->units[i]);
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this