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?