Sign in to follow this  

Questions about code structure.

This topic is 3316 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, I am Norgar, I'm from Spain and I will try to speak English the best that I can, sorry if my messages are confused. Hope that you can help me. I am writing a game, just for entertainment. The client connects to the server and they exchange data, like many games. I just have a log in menu that ask for user and password, and when you login, you see a list of characters and you choose one of the list. By now, all works perfectly, you can log-in in the system with your account and password and you see your own list of characters, you can create a new character too if you want. I use SDL and C++ (I think that this doesn't matter) and OOP. In the client, I have a class for the Graphics (Draws and set up SDL video), Map (Manage the map, but I don't use it yet), Player (Manage the HP and MP, I don't use it yet), Packet (Stores data sent by the server and data to send), Tiles (Stores images for the map), and the question, Interface and Network. The class Interface stores input boxes, buttons, etc, reads the keyboard and mouse to see if the user clicked in a button o wrote in a input box, reads the packets sent by the server to change the appearance of the interface and also stores the functions of each button, so when the user clicks on a button, the class executes those functions. The class Network just send and receive Packets, this class doesn't execute and do nothing. The problem it's that I think that Interface class does functions in my code that should not, but I don't know how to solve it. I know that I said that my code works perfectly but I think that I must to construct the code to avoid future problems and bugs. I thought to wrote another class to manage all the other classes in it, something like a "core" to manage all. What do you think? I should to leave everything as is? Or I must change the code? A big thread for a little "problem"...

Share this post


Link to post
Share on other sites
Look up "coupling OOB"

usually you want to achieve high cohesion and low coupling for your modules.

You should have some sort of window manager that holds all the buttons,
some network manager that sends and retrieves messages and directs them forward to either the window manager to process input buttons/edit fields
or to some kind of a command system that executes game commands.


For controlling a character you usually write a character controller which takes care about the camera, character position and velocity.

The command system retrieves the input from other input system and directs the commands e.g.: to the current player controller


Thats the way I design it

your commands and be some strings or lists of strings

e.g.: stringlist [0] =="somecommand" stringlist[1] = "parameter1" ...


Share this post


Link to post
Share on other sites

This topic is 3316 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.

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