So I have absolutely no clue why this doesn't work-- but the GUI doesn't respond to anything inside the getMove(GameState gameState)
method.
Even with a sleep to pause it after I make the move-- it simply does not show anything. Any help would be great. I'm so lost.
public class Engine extends Player {
private GameState copy;
public Engine(Color color, Direction direction) {
super(color, direction);
}
public Move getMove(GameState gameState) {
gameState.executeMove(new Move(4, 6, 4, 4));
try {
TimeUnit.SECONDS.sleep(1);
} catch (Exception e) {
e.printStackTrace();
}
return new Move(5, 6, 5, 4);
}
}
You're calling sleep
within a Swing GUI on its event thread, something that will block the event thread, preventing it from doing its necessary activities such as drawing the GUI and interacting with the user, and this will put the GUI to sleep making it non-responsive. The solution is to never do this but to use a Swing Timer instead.
Side issue: add a call to the super.paintComponent(g);
method within your override method, on its first line. This will allow your JPanel to do its house-keeping painting.