Fixed game state related bugs

This commit is contained in:
Kai S. K. Engelbart 2019-07-16 18:24:48 +02:00
parent ec86d598a2
commit 7a4266d4a7
3 changed files with 8 additions and 8 deletions

View File

@ -46,10 +46,9 @@ public class Game {
System.out.printf("%s in check!%n", player.color.opposite());
default:
boardComponent.repaint();
overlayComponent.displayArrow(move);
players.get(player.color.opposite()).requestMove();
}
overlayComponent.displayArrow(move);
} else player.requestMove();
}
@ -57,12 +56,11 @@ public class Game {
players.get(Color.WHITE).requestMove();
}
public void restart() {
public void reset() {
players.forEach((k, v) -> v.cancelMove());
board.initializeDefaultPositions();
boardComponent.repaint();
overlayComponent.clearDots();
overlayComponent.clearArrow();
start();
}
}

View File

@ -65,7 +65,7 @@ public class MainWindow {
mframe.getContentPane().add(toolPanel, BorderLayout.NORTH);
JButton btnRestart = new JButton("Restart");
btnRestart.addActionListener((evt) -> { if (game != null) game.restart(); });
btnRestart.addActionListener((evt) -> { if (game != null) game.reset(); game.start(); });
toolPanel.add(btnRestart);
mframe.pack();
mframe.setLocationRelativeTo(null);

View File

@ -80,9 +80,11 @@ public class MenuBar extends JMenuBar {
}
private void startGame() {
// TODO: Re-init board and overlay component
Game game = new Game(players, boardPane);
mainWindow.setGame(game);
// Update board and board component
game.reset();
game.start();
}
}