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 7406881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:37:27+00:00 2026-05-29T05:37:27+00:00

In a simple card game (human vs. CPU) the logic works, but I want

  • 0

In a simple card game (human vs. CPU) the logic works, but I want to delay the computer’s turn.

I have tried using Thread.sleep(int milliseconds) which works, but it messes up the order images are displayed. I’m not using a game loop, I am just dynamically updating ImageViews whenever cards are changed. The problem with Thread.sleep is all the images only update after Thread.sleep, there is no displaying only the human card before Thread.sleep. The human’s card and computer’s card display after Thread.sleep.

I’ve used Thread.sleep like so:

playPlayerCard(player); // Human first
displayPile(); // Display card pile (ImageView's)

player = nextPlayer(player); // Get's next player in Player mPlayers List<Player>

// Wait for computer to 'Think'
Thread.sleep(500);

playPlayerCard(player); //Computer's turn
displayPile(); // Display card pile (ImageView's)

Am I using Thread.sleep() wrong? Is there a better/correct way? I’ve searched online and tried using new Thread(), using handler.postDelayed(Runnable r, long milliseconds) and also CountDownTimer but none work since my variables: playPlayerCard(player); aren’t final variables.

I’ve always had problems delaying actions and the images appearing at the correct times. Any suggestions? Thanks in advance.

  • 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-29T05:37:28+00:00Added an answer on May 29, 2026 at 5:37 am

    I used the solution from @Jakar and changed my variables to class-scope in order to use the Handler and Runnable correctly. This worked, the delay works correctly using

    Runnable r = new Runnable() {
        public void run() {
             playPlayerCard();
        }
    };
    
    mHandler.postDelayed(r, 500);
    

    To clarify the solution, I had to take out the arguments from playPlayerCard(Player player) and use a class-scope Player mPlayer; variable in playPlayerCard() instead.

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

Sidebar

Related Questions

I have a simple card game (using 52 cards - no jokers) that I
So, i'm attempting simple card game. I have player class with draw function, and
I'm making a simple card game server in Java using eclipse. I'm now trying
I'm writing a simple card game in JavaScript, and I'd like to have a
I am brand new to Cocos2d and have begun making a simple card game.
I have three canvases I'm using in a card game app I'm building. One
I'm writing the simple card game War for homework and now that the game
I'm writing a simple card game and now I'd like to make the card
I'm trying to implement a fairly simple card game in Python so that two
I am looking to make a card game in Flash CS4 using AS3 and

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.