Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 424329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:16:09+00:00 2026-05-12T19:16:09+00:00

I’ve been programming in c++ for a bit now and Im very familiar with

  • 0

I’ve been programming in c++ for a bit now and Im very familiar with the syntax. I’m trying to use Allegro to make a card game. I understand everything I need to do for the game logic and what not. What puzzles me is how to drive the game. I’m sort of new to loop based applications. I got used to event based programming in VB .Net. I’m just not sure the proper way of for example switching players and raising “events” without having lots of ifs and bools. Also right now I have an array of bool to check which card is in play. And my game iterates through the whole bool array every time and it seems messy to me. Also, if I want to go from my menu loop to my settings loop, how is that done without a big bool?
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T19:16:09+00:00Added an answer on May 12, 2026 at 7:16 pm

    Most gaming frameworks provide two methods you need to implement (both of them are called in a loop):

    • Update
    • Draw

    The Update is where you should put all that stuff, which should check for User input, state changes, intervalled actions etc. Examples would be Physics, ButtonPressed, etc. Nothing prevents you from working with events here (have a look at BoostLibrary Signals).

    void Game::update() {
       if(pushedButton) {
           this->cardsOnTable->add(this->hand->remove(0));
           this->activePlayer = nextPlayer();
       }
    }
    

    The Draw should just render the current, underlying state to the screen. So you have to make sure your underlying state/model is easy to access.

    void Game::render() {
      this->table->render();
      this->cardsOnTable->render();
      this->hand->render();
      // ...
      flipBuffers();
    }
    

    You can solve your Menu/SettingsMenu issue with Scenes and a SceneManager (which can be a Stack). So instead of putting the logic into the Game directly, you put it into Scenes. And you can push/pop scenes to/from the Manager.

    void Game::update() {
      this->sceneManager->activeScene->update();
    }
    
    void MenuScene::update() {
      if(settingsMenuItemSelected) {
        game->sceneManager->push(new SettingsMenuScene));
        // now the next time Game::update() is called
        // the active scene of the SceneManager will be
        // the settings menu. And once it is closed/cancelled
        // it will pop itself from the manager and we are back
        // in the regular menu
      }
    }
    

    If you want to start with more advanced stuff, you could try to store “events” into a huge list and fire all events when you enter the Game::update method – this is how VB makes sure that you can’t modify controls from another thread than the UI thread – but I don’t think that this is something you would do using C++.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.