A rather broad code design question

This is a discussion on A rather broad code design question within the C++ Programming forums, part of the General Programming Boards category; Hi, I apologise if this is too broad or if it sounds like "how do you make a game?". I ...

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    10

    A rather broad code design question

    Hi, I apologise if this is too broad or if it sounds like "how do you make a game?".

    I have made several mini games, mostly not utilising OOP concepts, although I have done a few with atleast a few classes. I am now looking to undertake a bit more of a major project, specifically a turn based (hotseat) strategy game, so no AI or networking for now.

    I like to thoroughly plan my code before I write it, but with a project this size I really struggle through this stage, so obviously I can't start coding it just yet.

    I am looking for any pointers, tips or examples on game code structuring, it is essential that these are in c++ and contain extensive use of c++ features, they don't have to be games but it would be preferred. I have looked at source code for many games and they are usually coded only in C and generally seem to be quite a mess, this is something I want to avoid as I would like to be able to continue to work on this project and maintain it. I do have Battle for Wesnoth lined up for a download on my off-peak though.

    My basic idea of the "correct" way to do it would be to have a header/source pair for each class, but that's about as far as my certainty goes. I have also been introduced to the idea of having a base game class, which contains all game elements, minus things like rendering and object creation. Is that a good way to go? Opinions? Tips?

    Sorry for such a long, rambling post. Any help will be greatly appreciated.

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,403

    Base class

    I recently completed a game using virtual base class as a state manager, after some teething troubles with new concept and implementation it is a great way to organise your program, once organised you can add new functionality to your game hassle free

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,159
    Sounds like you've reached the point where you've figured out that, in order to go on a trip, you must first stand up.

    Designing entire systems from scratch is something that must be learned through practice. At this phase of your experience, it's probably better to take an iterative approach of designing a small sub-part, then implementing it, designing another sub-part, implementing it, etc... You may find that the pieces don't fit together elegantly, or at all. That's just something which comes with experience.

    The point is to actually do something instead of getting mired in the design. Unless you actually write code you won't be able to learn what works and what doesn't.

    Paraphrased from Fred Brook's book The Mythical Man Month: plan to throw the first one away -- you will anyhow.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Quote Originally Posted by brewbuck View Post
    Sounds like you've reached the point where you've figured out that, in order to go on a trip, you must first stand up.

    Paraphrased from Fred Brook's book The Mythical Man Month: plan to throw the first one away -- you will anyhow.
    Side question: The above is how I used to approach systems where I did not have clear ideas on hard requirements and code structure...then over the years I have sort of adopted the test-driven development method which assures no extra code is written while at the same time you code everything you need. IOW you know when you are "done". Query: is this inappropriate for younger/less experienced coders would you say?
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  5. #5
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,159
    Quote Originally Posted by jeffcobb View Post
    Side question: The above is how I used to approach systems where I did not have clear ideas on hard requirements and code structure...then over the years I have sort of adopted the test-driven development method which assures no extra code is written while at the same time you code everything you need. IOW you know when you are "done". Query: is this inappropriate for younger/less experienced coders would you say?
    No, as long as it doesn't get in the way of writing code. It's never bad to learn how things are done in practice. But it's not beneficial if you deadlock yourself and don't end up doing ANYTHING.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  6. #6
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Interesting. To me, this starts me writing code earlier than long drawn-out attempts to pre-document a system that I don't fully understand. Basically, writing an app to test a system I don't know helps sort out what functionality goes where plus what data structure needs what to work. Then when I have that, writing code to do what the test requires is simple and I know I am not missing anything.

    And then I am done. ^__^.

    Sorry did not mean to hijack the thread.
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  7. #7
    Registered User
    Join Date
    Jan 2010
    Posts
    10
    I guess I'll go and dive in then and see how I go. I thought someone might tell me to just try and start coding.

    Cheers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked List Tutorial sample code question
    By Kalleos in forum C Programming
    Replies: 2
    Last Post: 01-16-2009, 11:20 AM
  2. Linked List question from a newb(Need code Critique)
    By Gatt9 in forum C++ Programming
    Replies: 2
    Last Post: 01-08-2006, 02:11 AM
  3. End of Code Loop Question
    By JuanSverige in forum C++ Programming
    Replies: 1
    Last Post: 04-08-2003, 10:35 AM
  4. Replies: 4
    Last Post: 11-19-2002, 08:18 PM
  5. OO design question
    By PJYelton in forum C++ Programming
    Replies: 8
    Last Post: 10-10-2002, 12:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21