Implemented color swapping
+ swapColor method in Board + Button for swapping colors in MainWindow
This commit is contained in:
parent
a6fcaee70e
commit
2b00116837
@ -7,7 +7,7 @@
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.8.0_212">
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
|
@ -109,5 +109,16 @@ public class Game {
|
||||
players.values().forEach(Player::disconnect);
|
||||
}
|
||||
|
||||
public void swapColors() {
|
||||
players.values().forEach(Player::cancelMove);
|
||||
Player white = players.get(Color.WHITE);
|
||||
Player black = players.get(Color.BLACK);
|
||||
white.setColor(Color.BLACK);
|
||||
black.setColor(Color.WHITE);
|
||||
players.put(Color.WHITE, black);
|
||||
players.put(Color.BLACK, white);
|
||||
players.get(board.getActiveColor()).requestMove();
|
||||
}
|
||||
|
||||
public Board getBoard() { return board; }
|
||||
}
|
||||
|
@ -67,7 +67,13 @@ public class MainWindow {
|
||||
|
||||
JButton btnRestart = new JButton("Restart");
|
||||
btnRestart.addActionListener((evt) -> { if (game != null) game.reset(); game.start(); });
|
||||
|
||||
JButton btnSwapColors = new JButton("Swap Colors");
|
||||
btnSwapColors.addActionListener((evt) -> game.swapColors());
|
||||
|
||||
toolPanel.add(btnRestart);
|
||||
toolPanel.add(btnSwapColors);
|
||||
|
||||
mframe.pack();
|
||||
mframe.setLocationRelativeTo(null);
|
||||
}
|
||||
|
@ -59,6 +59,7 @@ public class MenuBar extends JMenuBar {
|
||||
gameMenu.add(aiVsAiMenuItem);
|
||||
gameMenu.add(uciMenuItem);
|
||||
|
||||
|
||||
add(gameMenu);
|
||||
|
||||
// Start a game
|
||||
|
Reference in New Issue
Block a user