Suggestion Needed

This is a discussion on Suggestion Needed within the C++ Programming forums, part of the General Programming Boards category; Hey guys I am working on a small game. and I would like a design suggestion. At the moment I ...

  1. #1
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,479

    Suggestion Needed

    Hey guys

    I am working on a small game. and I would like a design suggestion.

    At the moment I am creating single Characters to represent the objects in a maze, then assigning them to the maze. So far I am doing it this way:

    Code:
    void createGoalList ( char Mz[][ 50 ] )
    {
       char cheese[] = "C";
       char key[] = "K";
       char exit[] = "E";
       char trap[] = "T";
       
       assignGoalsToMaze ( Mz, cheese, key, exit, trap );
    }
    
    // function to set the goals to the maze locations
    void assignGoalsToMaze ( char Mz[][ 50 ], char *pChse, char *pKey, char *pEx, char *pTp )
    {
       Mz[ 5 ][ 7 ] = *pChse;
    }
    Would it be more senisble to make an array of pointers here? Sort of:

    Code:
     char *pItems[  4 ] = { "C", "K", "E", "T" };
    Or is it more suitable to deploy the technique I have been using, which I am having no problems with thus far; compiling ok etc.

    Any suggestions appreiciated.
    I'm just trying to be a better person - My Name Is Earl

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,834
    Code:
    enum goals {
        G_Cheese,
        G_Key,
        G_Exit,
        G_Trap,
        G_MAX
    };
    
    void assignGoalsToMaze ( goals Mz[][ 50 ] )
    {
       Mz[ 5 ][ 7 ] = G_Cheese;
    }
    Then you're free to write now
    Code:
    void displayAsciiMaze ( goals Mz[][ 50 ] );
    And free to write later
    Code:
    void displayOpenGLMaze ( goals Mz[][ 50 ] );
    without having to rip apart whole chunks of your code which assumed far too much about the nature of the display.

    It also gets you out of the hole of what to do when all the good letters are gone, and you need something like "Q" for a sandwich.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,479
    Thanks Salem. Great suggestion Il give it a try.
    I'm just trying to be a better person - My Name Is Earl

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. free needed or not?
    By quantt in forum Linux Programming
    Replies: 3
    Last Post: 06-25-2009, 10:32 AM
  2. Some Direction Needed
    By Bidamin in forum C++ Programming
    Replies: 3
    Last Post: 04-22-2009, 11:15 AM
  3. C Programmers needed for Direct Hire positions
    By canefan in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 09-24-2008, 12:55 PM
  4. Replies: 12
    Last Post: 05-14-2003, 02:00 AM
  5. Any suggestion?
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 10-28-2001, 05:24 AM

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