Thread: Suggestion Needed

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

    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.
    Double Helix STL

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    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.

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Thanks Salem. Great suggestion Il give it a try.
    Double Helix STL

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, 09:32 AM
  2. Some Direction Needed
    By Bidamin in forum C++ Programming
    Replies: 3
    Last Post: 04-22-2009, 10: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, 11:55 AM
  4. Replies: 12
    Last Post: 05-14-2003, 01:00 AM
  5. Any suggestion?
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 10-28-2001, 05:24 AM