95 lines
2.8 KiB
Java
95 lines
2.8 KiB
Java
package dev.kske.chess.ui;
|
|
|
|
import java.awt.FlowLayout;
|
|
import java.awt.event.WindowAdapter;
|
|
import java.awt.event.WindowEvent;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
import javax.swing.JButton;
|
|
import javax.swing.JDialog;
|
|
|
|
import dev.kske.chess.board.Board;
|
|
import dev.kske.chess.board.Piece.Color;
|
|
import dev.kske.chess.game.Game;
|
|
import dev.kske.chess.game.NaturalPlayer;
|
|
import dev.kske.chess.game.Player;
|
|
import dev.kske.chess.game.ai.AIPlayer;
|
|
|
|
/**
|
|
* Project: <strong>Chess</strong><br>
|
|
* File: <strong>GameModeDialog.java</strong><br>
|
|
* Created: <strong>06.07.2019</strong><br>
|
|
* Author: <strong>Kai S. K. Engelbart</strong>
|
|
*/
|
|
public class GameModeDialog extends JDialog {
|
|
|
|
private static final long serialVersionUID = 5470026233924735607L;
|
|
|
|
private final MainWindow parent;
|
|
private final Board board;
|
|
private final OverlayComponent overlayComponent;
|
|
private final BoardComponent boardComponent;
|
|
private final Map<Color, Player> players;
|
|
|
|
/**
|
|
* Create the dialog.
|
|
*/
|
|
public GameModeDialog(MainWindow parent, BoardPane boardPane) {
|
|
super();
|
|
setModal(true);
|
|
setTitle("Game Mode Selection");
|
|
setBounds(100, 100, 231, 133);
|
|
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
|
getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
|
|
|
|
// Exit application when the close button is pressed
|
|
addWindowListener(new WindowAdapter() {
|
|
|
|
@Override
|
|
public void windowClosing(WindowEvent evt) {
|
|
System.exit(0);
|
|
}
|
|
});
|
|
|
|
this.parent = parent;
|
|
boardComponent = boardPane.getBoardComponent();
|
|
overlayComponent = boardPane.getOverlayComponent();
|
|
board = boardComponent.getBoard();
|
|
players = new HashMap<>();
|
|
|
|
JButton btnNatural = new JButton("Game against natural opponent");
|
|
btnNatural.addActionListener((evt) -> {
|
|
players.put(Color.WHITE, new NaturalPlayer(board, Color.WHITE, overlayComponent));
|
|
players.put(Color.BLACK, new NaturalPlayer(board, Color.BLACK, overlayComponent));
|
|
startGame();
|
|
});
|
|
getContentPane().add(btnNatural);
|
|
|
|
JButton btnAI = new JButton("Game against AI");
|
|
btnAI.addActionListener((evt) -> {
|
|
players.put(Color.WHITE, new NaturalPlayer(board, Color.WHITE, overlayComponent));
|
|
players.put(Color.BLACK, new AIPlayer(board, Color.BLACK, 5));
|
|
startGame();
|
|
});
|
|
getContentPane().add(btnAI);
|
|
|
|
JButton btnAI2 = new JButton("AI against AI");
|
|
btnAI2.addActionListener((evt) -> {
|
|
players.put(Color.WHITE, new AIPlayer(board, Color.WHITE, 5));
|
|
players.put(Color.BLACK, new AIPlayer(board, Color.BLACK, 4));
|
|
startGame();
|
|
});
|
|
getContentPane().add(btnAI2);
|
|
|
|
setLocationRelativeTo(null);
|
|
}
|
|
|
|
private void startGame() {
|
|
Game game = new Game(players, boardComponent);
|
|
parent.setGame(game);
|
|
game.start();
|
|
dispose();
|
|
}
|
|
}
|