Frage

When in my game, a player makes a move, its not visible until the AI move is computed. And then both the moves are shown together.

I want to show player's move and after that, AI move (after its computation). I tried Thread delay but no use. How to add this visibility using some kind of a pause, but that pause must not pause the execution of the program?

War es hilfreich?

Lösung

  1. Player made his selection, stop accepting player input, start animation for player movement in a Thread and start AI in another Thread.
  2. When AI is done, while animation for player movement is not done: wait(100). When animation for player movement is done start animation for AI movement.
  3. When animation for AI movement is done resume accepting player input.

    In step 2, if AI takes longer than the animation for player movement, show some waiting animation. This waiting animation should be stopped before start animation for AI movement.

Andere Tipps

You could always create a boolean check that only gets set to true if your player has completed their move.

public class ... 
{
    boolean playerMoveMade = false;

    ...

    public void gameCycle() 
    {
        ...

        if (playerMoveMade) 
        {
            playerMoveMade = false;
            // ... render AI move
        }
    }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top