Sign in to follow this  

New to Forum... some questions

This topic is 3730 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 All, I am new to this forum and so far it looks great; their is truly a wealth of information here and I look forward to attempting to digest it all. I just wanted to introduce myself and maybe get some advice. ______________________________________________________________________________ WARNING: Long post. CLIFF NOTES: I am a novice programmer. I am concerned about organization and efficient use of OOP. ______________________________________________________________________________ My background: I am a novice programmer. I started learning basic when I was about 10 yrs old. i convinced my mother to buy me turbo C++ shortly thereafter and attempted to learn C/C++. Fast forward 20 years: I have used assembly, C, C++, and Matlab over the years to write code to solve problems (engineering). Now I am just programming as a hobby using C++ and the SDL library to make a game that I have envisioned in my head. Current situation: I am starting with small steps. I have re-read my C++ manuals and have familiarized myself with programming once again. I am using the SDL library for easy graphic implementation. I am making a "tile-based" game: there is a board (for example, the squares on a chess board) and moving pieces that interact with the board and each other. Some questions: 1. I am trying to stay organized and write code that doesn't confuse the reader (me) and is modular (so that size and complexity issues can be resolved). What is the best way to modularize it? What I am currently doing is calling a function in the main program called gameloop. This function gameloop is the loop of the game. I then call my various game functions in this loop. Each function/class has a header file and a .cpp file associated with it. I then call whatever I need in the gameloop function. For example, in pseudo-code: start gameloop *generate world *move character *character interacts with world *update world do loop until quit each '*' would have its own .h and .cpp file associated with it. Is this a good way to organize? 2. I am new to OOP. I understand classes and use them, but I am wondering about practical implementations. Suppose I am trying to write a simple chess program (minus the complicated AI that good chess programs require). Could I organize the chess program in the following way: Create a class called Square with attributes that each chess square would logically require (i. e. location, and what, if any, piece it contains)? Then create the following classes: Pawn, Rook, etc. ??? I guess there are many ways to do this chess program, but what would be a simple and efficient implementation using OOP? Thanks for any feed back.

Share this post


Link to post
Share on other sites
Hi.

If you're the only person that's writing the code for the game you're making, do whatever makes sense to you in order to keep yourself organized. Doing the files in *.h and associated *.cpp files is the most accepted way of coding in C++, so I think you're on the right path in keeping compile times short and your code well organized. It helps to write out the pseudocode before you start typing out your code. You'd be surprised by how much it helps and keeps you organized.

As for OOP, again, do what makes sense to you. It does help to pick up a book or two on OOP design. IMO, the best way to implement objects for a chess program is to make only the pieces objects. Those classes would hold their type and position on the board. Just make the chess board a 2D array and when you want to move the peices around pass the array to the function that moves them and then check if any of the other pieces are in that position.

Share this post


Link to post
Share on other sites
Hi Drunken Monkey,


Thanks for the advice. Okay, I am sticking with the *.h and *.cpp style of organization. I guess the more "broken-up" the code is, the easier to understand and reuse. I think that you can anticipate such organizational concerns from a novice programmer =). Before this, all my programs only had one file with a main function. You can say that I am expanding my horizons in my old age.

Also, thanks for the OOP advice. Now that I have my bare-bones skeleton code down, I am going to test these ideas out. I will make a short simulation for my homework assignment for tonight.

I have always admired Conway's game of life. So, in Conway's honor, I will write a life-style simulation tonight while I drink my suds (I guess then in drunken monkey's honor as well).

The small simulation I am programming tonight has the following 'cells'. Randomly generated flies, and a toad that tries to eat the flies. So, the pieces will be flies and toads (ojects), and the board will be an array. This should keep me busy for a little bit.

thanks again, drunken monkey.

Share this post


Link to post
Share on other sites

This topic is 3730 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