Thread: Good Programming Practices

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    2

    Good Programming Practices

    OK, I've been reading a couple different c++ books and I started making a console based text adventure game for my kids. As I learn new things from the books I add/update my code, like when I learned about classes I made a class for the player, one for the monster, one for items you can get, etc.
    My program has gotten much bigger now and I would like to make sure that I am structuring it correctly.

    What are some good programming practices that I should follow in regards to where I should put various functions, etc. For example, I made a Player.h file where I declared my cPlayer class. Then I made a Player.cpp file where I defined all of it's members. I made a Chest.h file to create a class for chest armor, but I defined everything right where I declared it (string GetName(){return chestName;}), etc., no .cpp file for Chest.

    My main cpp file, where the main() function is located, has like 12 #include statements, a bunch of function prototypes, constant declarations, and class instance statements. Do people usually make a separate header file to hold all of the stuff before main() and then just include that just to keep things neat and tidy? I put most of my functions in this main cpp file below the main() function, but I did create a couple separate files for other functions, like I made a Wait.cpp file that pauses the game for a number of milliseconds.

    How do I know when I should put a function under the main() function or put it in it's own cpp file? What about classes?

    Also, I have a Location.cpp file where I can call functions in it from the main.cpp file, but I can't call main.cpp functions from the Location.cpp file, or I can't call the wait() function from within Locations.cpp. What do I need to add to do that?

    Thanks!
    Last edited by mark909; 01-17-2011 at 10:33 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In a game Engine...
    By Shamino in forum Game Programming
    Replies: 28
    Last Post: 02-19-2006, 11:30 AM
  2. Good books for learning WIN32 API
    By Junior89 in forum Windows Programming
    Replies: 6
    Last Post: 01-05-2006, 05:38 PM
  3. Good resources for maths and electronics
    By nickname_changed in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 12-22-2004, 04:23 PM
  4. what is good for gaphics in dos
    By datainjector in forum Game Programming
    Replies: 2
    Last Post: 07-15-2002, 03:48 PM
  5. i need links to good windows tuts...
    By Jackmar in forum Windows Programming
    Replies: 3
    Last Post: 05-18-2002, 11:16 PM