Structure of the app

  • Replies:1
  • OpenNot stickiedUnanswered
  • Forum posts: 1

Mar 5, 2016, 1:13:28 PM via Website

Hi guys,
this is actually my first post (and first app) :)
I'm working on a card game.
I finished the game logic and classes and tested it.
now I'm trying to build the interface.
After lots of tries I think I need some guidance!
how do I structure my code?
I want the app to start, deal cards, offer choices to the player (and wait for his response ) then offer and wait for the AI to do the same, continue this way until the game ends.
(the game logic is similar to uno game but a little bit more complex)

where should I go from here? I'm fining problems with waiting for response in the main UI thread and I don't know what to do!
should I use threads for game logic?

  • Forum posts: 12

Mar 10, 2016, 3:52:58 PM via Website

From your description it sounds like you are trying to built a turned based card game, is that right? If so I would stick to one thread only, the main UI thread and not have any separate threads for the game logic, since there is hardly performance to be gained, but rather to have to deal with all kinds of synchronization issues.

That being said, you can probably convert your existing logic into some form of state machine, where each time the user interacts with the app, you simply trigger the corresponding state change in the logic. Of course this only works as long as each change in the UI is the result of an direct interaction of the user.

For what its worth, here is a fairly small example of a Tetris game on GitHub. I can't post links yet, so you'll have to search for 'TeamBlocks' created by an organization called 'FauDroids'. Let me know if you have any questions about it.

Recommended by NextPit