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

  • Home
  • SEARCH
  • 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 6011907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:19:38+00:00 2026-05-23T02:19:38+00:00

I have a card game in which play passes automatically from player to play.

  • 0

I have a card game in which play passes automatically from player to play. There are 3 non-user players and play flows from one to the next without user intervention every number of seconds (as specified by the user).

I have 2 methods that control the flow:

  1. awaitTurn which is used to wait for the start of the turn
  2. doTurn when the actual turn starts

They are both within the same class.
Each player has their own instance of the class.

After the player has finished its turn it then invokes the “awaitTurn()” of the next player and so on.

After the 3 automated player makes its turn then control is sent to the “awaitTurn()” of the user which effectively does nothing and allows the user to make his/her turn.

In order to pause I wrote the following code:

public void awaitTurn()
{
    GameActivity.thisActivity.displayHideCont(View.VISIBLE);
    if (GameActivity.settings.getPauseTimeBetweenTurns() > 0){
        startNextPlayerTurn = new Runnable() {public void run() {doTurn();}};

        if (handler == null)
            handler = new Handler();
        else
            handler.removeCallbacks(startNextPlayerTurn);

        int extraDelay = GameActivity.settings.getCardAnimationTime();

        handler.postDelayed(startNextPlayerTurn, 
                            (GameActivity.settings.getPauseTimeBetweenTurns())*1000 + extraDelay);
    }

    return;
}

In doTurn I have:

public void doTurn() {    
        if (startNextPlayerTurn!=null)  // just in case we are still pausing
            handler.removeCallbacks(startNextPlayerTurn);
    ...
}

So, the big question is, whether I am building here an infinite depth of threads one from within the other or not.

  • 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-23T02:19:38+00:00Added an answer on May 23, 2026 at 2:19 am

    You do not create threads in your application. You run all functions in your main UI thread (assuming handler is created in UI thread).

    Here is what happens:

    1. The call to handler.postDelayed(runnableX, delayX) puts runnableX into UI queue and will be processed after delayX.
    2. When time comes, UI thread’s loop takes runnableX and runs it.

    If you call handler.removeCallbacks(runnableX), then all pending messages with runnableX are removed from queue (and will not run).

    If you do multiple calls to handler.postDelayes(runnableX, delayX), then your runnableX will be called multiple times. But each time it will be run on UI thread.

    Unfortunately there is no way to check whether your runnableX is already posted to queue.

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

Sidebar

Related Questions

There is a multiplayer card game which I had first programmed as a non-forking
I have a card game (screenshot below) in which I display player avatars. For
I am making a card game in ruby. I have the Game class, which
I have a card-game application which makes use of Single Table Inheritance. I have
I have a small card game for Google+ which needs the visitor's name, avatar,
So, i'm attempting simple card game. I have player class with draw function, and
I have a small card game at Facebook (and few Russian social networks), which
I have a Rails 2.3.5 app which is serving a card game. I've been
I have profile pages for users of my little card game, like this one
I have three canvases I'm using in a card game app I'm building. One

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.