Thread: Is there really a better of the two options I have?

  1. #1
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968

    Is there really a better of the two options I have?

    Okay, So I'm thinking I could either pass a list of strings or objects as a parameter, or I could have a linked list of those same objects that perform the same function.

    I could go

    IO.update(list of objects)

    Or

    linkedlist.update()

    The linked list could update recursively with points and such, all causing output to be pushed inton the output queue.

    Or I could literally just push a list of strings into the output queue, I'm not sure which one is really preferable?
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    It depends. One rule of thumb is to prefer non-member non-friend functions. So, if possible, you would prefer:
    Code:
    update(IO, linkedlist);
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    So like an inline function update? Where should update be really?
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    I think you need to elaborate more on your class design, what it is supposed to model, and the problem you are trying to solve.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    Alright, I can do that, let me explain myself.

    I have a game loop and I have a function controlling that game loop. I want to do this loop in a uniform manner, all the time.

    1. Clear output on screen.
    2. Update output.
    3. Display output.
    4. Get input.
    5. Do stuff (right now it returns a 1 or 0 to see if the loop ends)

    The thing is, I do not want the function to control the game loop, because if the function closes out the loop then I would need to call items 1-4 again.

    Instead I want the function to control whether or not it will be called again. Here is what I have now:

    Code:
    void Card_Game::play_game()
    {
    	//shuffle the deck first
    	deck.shuffle_deck();
    	//draw cards for players
    	players[0].draw(deck, 1);
    	players[1].draw(deck, 2);
    	int gameloop = 1;
    	int result = 0;
    	while (gameloop != 0)
    	{
    		IO::instance().clear_screen();
    		IO::instance().insert_output(players[0].show_hand());
    		IO::instance().insert_output(players[1].show_hand());
    		IO::instance().display_output();
    		result = IO::instance().get_input();
    		gameloop = blackjack(result); 
    	}
    }
    Instead of 1 update function call for each update, I want a linked list or a list of string objects that I create during runtime, and update in 1 uniform update call. The blackjack function will result in updating more output, but if blackjack updates output and then the loop ends we don't get another chance to update the output queue, clear the screen, or even display the result.

    This will lead to my game loop being very manageable, with a few simple function calls that will always happen. If I use a linked list I can just add to that list during the blackjack function and it will get updated in the 1 universal call that I want to have, so everything works nicely .

    What do you think the best method is to accomplish this task?
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  6. #6
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968

    Lightbulb

    Do I need to elaborate more? Hehe
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Doxygen failing
    By Elysia in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 04-16-2008, 01:24 PM
  2. What's the best way to handle many program options?
    By stickmangumby in forum C Programming
    Replies: 19
    Last Post: 06-06-2007, 04:06 PM
  3. Explorer options
    By Magos in forum Windows Programming
    Replies: 1
    Last Post: 04-02-2005, 09:23 AM
  4. Disabling the main frame menu options
    By MPC_Engr in forum Windows Programming
    Replies: 2
    Last Post: 01-22-2003, 09:04 AM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM