Sign in to follow this  

thinking in OO

Recommended Posts

donjonson    271
Well I am gonig to now attempt to make a tetris clone using C++ and DirectX, my grav sim is not complete but I think I am going to leave it Whare it is. It works and it fulfills all of the criteria I orgionaly set for it. It just lacks polish. So now I am going to attempt a Tetris clone with my own little twist to it. But my question is: using C++, Should everything be a class? like menus, the game itself, the pieces, the board, the score board. for my grav sim, the only classes I had were some vectors and a class named chunk which is a mass bodie. for the game loop it was just an inline function that was called each time the windows message loop cycled. is there a better way to obtain a game loop in windows or is that it?

Share this post

Link to post
Share on other sites
Drew_Benton    1861
The way I see it, I am more of a 'what works best for me' kind of person. So I don't advocate trying to get that 100% OO methodology down in a program. When used correctly though, your OO design can help reduce your work load for a project. So to answer your first question, no, everything should not be a class.

A lot of criticism is given when people take something that could just be easily represented as one function to do something and implement it as a class. It all depends on the situation you are in. Your math code should be in classes more or less because classes allow you to take advantage of reusability. Now for your game specific code that won't be used again, there is no harm not wrapping everything up.

Now on to the actual game, menus I would setup in a class because you can easily make a menu class that you can work with freely once you have it done. I mean rather than hard code in first this menu, then that, etc... you can actually make it so you just develop a few, then add on later, making your game more versatile. Pieces and the board do make good candidates for classes simply because you can easily wrap up a lot of functionality inside to make life easier.

If you do your piece class right, you should be able to dynamically load in custom pieces and use those, thus allowing the player to make their own and use them. Now that may seem a little much for a first Tetris game, but the mindset of data driven design is one that I love and advocate. You can save a lot of time down the line if you make your programs data driven. Now it shouldn't be abused to the point that you need 100 different files to run a simple game either though.

Finally for your main loop, I usually just do stuff along the lines of update everything first, then draw. I mean you could set it up so you have a piece manager that goes though and updates all the pieces and stuff based on the last move, but that is up to you really. Now I have not ever made Tetris myself, so I'm not sure if the best approach to take. You could just have a Game.Run() then handle everything in there, but that might be a little too OO... Just start simply then work your way from there, expierment and see what you like and don't like [wink] Good luck!

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