Clock in SpielFrame ergänzt und ModeSelection integriert
parent
6c2ef85556
commit
593b0e9fbe
|
|
@ -10,6 +10,7 @@ import com.github.bhlangonijr.chesslib.move.Move;
|
||||||
import com.github.bhlangonijr.chesslib.move.MoveList;
|
import com.github.bhlangonijr.chesslib.move.MoveList;
|
||||||
import com.github.bhlangonijr.chesslib.pgn.PgnHolder;
|
import com.github.bhlangonijr.chesslib.pgn.PgnHolder;
|
||||||
|
|
||||||
|
import de.mannheim.th.chess.ui.SpielFrame;
|
||||||
import de.mannheim.th.chess.utl.Clock;
|
import de.mannheim.th.chess.utl.Clock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -18,142 +19,155 @@ import de.mannheim.th.chess.utl.Clock;
|
||||||
*/
|
*/
|
||||||
public class Game {
|
public class Game {
|
||||||
|
|
||||||
private Board board;
|
private Board board;
|
||||||
private Clock clock;
|
private Clock clock;
|
||||||
|
private SpielFrame sp;
|
||||||
|
private String modus;
|
||||||
|
private boolean rotieren, zuruecknahme;
|
||||||
|
|
||||||
private MoveList movelist;
|
private MoveList movelist;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Conststructs a new standard GameBoard.
|
* Conststructs a new standard GameBoard.
|
||||||
*/
|
*/
|
||||||
public Game() {
|
public Game(String modus, boolean rotieren, boolean zuruecknahme) {
|
||||||
this.board = new Board();
|
this.modus = modus;
|
||||||
|
this.rotieren = rotieren;
|
||||||
|
this.zuruecknahme = zuruecknahme;
|
||||||
|
|
||||||
|
|
||||||
|
this.board = new Board();
|
||||||
|
|
||||||
this.movelist = new MoveList();
|
this.movelist = new MoveList();
|
||||||
|
|
||||||
|
clock = new Clock(modus);
|
||||||
|
|
||||||
|
sp = new SpielFrame(this);
|
||||||
|
|
||||||
clock = new Clock("blitz");
|
|
||||||
clock.start();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new standard GameBoard and applies the provides moves.
|
* Constructs a new standard GameBoard and applies the provides moves.
|
||||||
*
|
*
|
||||||
* @param movelist The list of moves that get played.
|
* @param movelist The list of moves that get played.
|
||||||
*/
|
*/
|
||||||
public Game(MoveList movelist) {
|
public Game(MoveList movelist) {
|
||||||
this.board = new Board();
|
this.board = new Board();
|
||||||
|
|
||||||
this.movelist = movelist;
|
this.movelist = movelist;
|
||||||
|
|
||||||
for (Move move : movelist) {
|
for (Move move : movelist) {
|
||||||
this.board.doMove(move);
|
this.board.doMove(move);
|
||||||
}
|
}
|
||||||
|
|
||||||
// this.clockPlayer1 = new Clock();
|
// this.clockPlayer1 = new Clock();
|
||||||
// this.clockPlayer2 = new Clock();
|
// this.clockPlayer2 = new Clock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new GameBoard with the provided fen String as the positions.
|
* Constructs a new GameBoard with the provided fen String as the positions.
|
||||||
*
|
*
|
||||||
* @param fen The fen String that provides the customs formation.
|
* @param fen The fen String that provides the customs formation.
|
||||||
*/
|
*/
|
||||||
public Game(String fen) {
|
public Game(String fen) {
|
||||||
this.board = new Board();
|
this.board = new Board();
|
||||||
this.board.loadFromFen(fen);
|
this.board.loadFromFen(fen);
|
||||||
|
|
||||||
this.movelist = new MoveList();
|
this.movelist = new MoveList();
|
||||||
|
//this.sp = new SpielFrame();
|
||||||
|
|
||||||
// this.clockPlayer1 = new Clock();
|
// this.clockPlayer1 = new Clock();
|
||||||
// this.clockPlayer2 = new Clock();
|
// this.clockPlayer2 = new Clock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plays the move on the board and adds it to the movelist
|
* Plays the move on the board and adds it to the movelist
|
||||||
*
|
*
|
||||||
* @param move the move to be played
|
* @param move the move to be played
|
||||||
*/
|
*/
|
||||||
public void playMove(Move move) {
|
public void playMove(Move move) {
|
||||||
this.board.doMove(move);
|
this.board.doMove(move);
|
||||||
this.movelist.add(move);
|
this.movelist.add(move);
|
||||||
clock.pressClock();
|
clock.pressClock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plays the move on the board and adds it to the movelist
|
* Plays the move on the board and adds it to the movelist
|
||||||
*
|
*
|
||||||
* @param origin The square from wich it moves from.
|
* @param origin The square from wich it moves from.
|
||||||
* @param desination The square where it will move to.
|
* @param desination The square where it will move to.
|
||||||
*/
|
*/
|
||||||
public void playMove(Square origin, Square desination) {
|
public void playMove(Square origin, Square desination) {
|
||||||
Move move = new Move(origin, desination);
|
Move move = new Move(origin, desination);
|
||||||
this.board.doMove(move);
|
this.board.doMove(move);
|
||||||
this.movelist.add(move);
|
this.movelist.add(move);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isMate() {
|
|
||||||
return board.isMated();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDraw() {
|
|
||||||
return board.isDraw();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getActivePlayer() {
|
|
||||||
if (board.getSideToMove() == Side.WHITE) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
}
|
||||||
* Retrieves a list of legal moves originating from the specified square.
|
|
||||||
*
|
|
||||||
* @param square The square from which to retrieve legal moves.
|
|
||||||
*
|
|
||||||
* @return A list of legal moves that originate from the specified square.
|
|
||||||
*/
|
|
||||||
public List<Move> getLegalMoves(Square square) {
|
|
||||||
return this.board.legalMoves().stream()
|
|
||||||
.filter(move -> move.getFrom() == square)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
}
|
public boolean isMate() {
|
||||||
|
return board.isMated();
|
||||||
public void stopClock() {
|
}
|
||||||
clock.endGame();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public boolean isDraw() {
|
||||||
* Retrieves a list of all legal moveable squares from the current board state.
|
return board.isDraw();
|
||||||
*
|
}
|
||||||
* @return a List of Square objects representing all legal moveable squares.
|
|
||||||
*/
|
|
||||||
public List<Square> getAllLegalMoveableSquares() {
|
|
||||||
return this.board.legalMoves().stream()
|
|
||||||
.map(move -> move.getFrom())
|
|
||||||
.distinct()
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public int getActivePlayer() {
|
||||||
* Retrieves a list of legal moveable squares for a given square.
|
if (board.getSideToMove() == Side.WHITE) {
|
||||||
*
|
return 1;
|
||||||
* @param square the Square from which to retrieve legal moveable squares
|
}
|
||||||
* @return a List of Square objects representing the legal moveable squares
|
return 2;
|
||||||
* from the specified square.
|
}
|
||||||
*/
|
|
||||||
public List<Square> getLegalMoveableSquares(Square square) {
|
|
||||||
return this.board.legalMoves().stream()
|
|
||||||
.filter(move -> move.getFrom() == square)
|
|
||||||
.map(move -> move.getTo())
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toFEN() {
|
/**
|
||||||
board.toString();
|
* Retrieves a list of legal moves originating from the specified square.
|
||||||
return board.getFen();
|
*
|
||||||
}
|
* @param square The square from which to retrieve legal moves.
|
||||||
|
*
|
||||||
|
* @return A list of legal moves that originate from the specified square.
|
||||||
|
*/
|
||||||
|
public List<Move> getLegalMoves(Square square) {
|
||||||
|
return this.board.legalMoves().stream().filter(move -> move.getFrom() == square).collect(Collectors.toList());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopClock() {
|
||||||
|
clock.endGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a list of all legal moveable squares from the current board state.
|
||||||
|
*
|
||||||
|
* @return a List of Square objects representing all legal moveable squares.
|
||||||
|
*/
|
||||||
|
public List<Square> getAllLegalMoveableSquares() {
|
||||||
|
return this.board.legalMoves().stream().map(move -> move.getFrom()).distinct().collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a list of legal moveable squares for a given square.
|
||||||
|
*
|
||||||
|
* @param square the Square from which to retrieve legal moveable squares
|
||||||
|
* @return a List of Square objects representing the legal moveable squares from
|
||||||
|
* the specified square.
|
||||||
|
*/
|
||||||
|
public List<Square> getLegalMoveableSquares(Square square) {
|
||||||
|
return this.board.legalMoves().stream().filter(move -> move.getFrom() == square).map(move -> move.getTo())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toFEN() {
|
||||||
|
board.toString();
|
||||||
|
return board.getFen();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModus(String modus) {
|
||||||
|
this.modus = modus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Clock getClock() {
|
||||||
|
return this.clock;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,6 @@ import java.awt.Color;
|
||||||
|
|
||||||
public class MainFrame extends JFrame {
|
public class MainFrame extends JFrame {
|
||||||
|
|
||||||
private ArrayList<SpielFrame> spiele = new ArrayList<>();
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private JPanel contentPane;
|
private JPanel contentPane;
|
||||||
|
|
||||||
|
|
@ -76,8 +74,7 @@ public class MainFrame extends JFrame {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
||||||
SpielFrame sp = new SpielFrame();
|
ModeSelectionFrame ms = new ModeSelectionFrame();
|
||||||
spiele.add(sp);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,7 +112,7 @@ public class MainFrame extends JFrame {
|
||||||
|
|
||||||
contentPane.add(Box.createVerticalStrut(15));
|
contentPane.add(Box.createVerticalStrut(15));
|
||||||
|
|
||||||
JButton btnNewButton_2 = new JButton("Spiel beenden");
|
JButton btnNewButton_2 = new JButton("App beenden");
|
||||||
|
|
||||||
btnNewButton_2.setBackground(Color.LIGHT_GRAY);
|
btnNewButton_2.setBackground(Color.LIGHT_GRAY);
|
||||||
btnNewButton_2.setForeground(Color.BLACK);
|
btnNewButton_2.setForeground(Color.BLACK);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,107 @@
|
||||||
|
package de.mannheim.th.chess.ui;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
|
|
||||||
|
import de.mannheim.th.chess.domain.Game;
|
||||||
|
|
||||||
|
public class ModeSelectionFrame extends JFrame {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private final JPanel contentPane;
|
||||||
|
private final ArrayList<Game> spiele = new ArrayList<>();
|
||||||
|
|
||||||
|
public ModeSelectionFrame() {
|
||||||
|
// Frame-Eigenschaften
|
||||||
|
setTitle("Modusauswahl");
|
||||||
|
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
|
setBounds(100, 100, 500, 500);
|
||||||
|
setResizable(true);
|
||||||
|
setAlwaysOnTop(true);
|
||||||
|
|
||||||
|
// Panel konfigurieren
|
||||||
|
contentPane = new JPanel();
|
||||||
|
contentPane.setBackground(new Color(90, 90, 90));
|
||||||
|
contentPane.setBorder(new EmptyBorder(20, 20, 20, 20));
|
||||||
|
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
|
||||||
|
setContentPane(contentPane);
|
||||||
|
|
||||||
|
// Überschrift
|
||||||
|
JLabel jl = new JLabel("Welchen Modus wollen Sie spielen?");
|
||||||
|
jl.setFont(new Font("Calibri", Font.BOLD, 20));
|
||||||
|
jl.setForeground(Color.BLACK);
|
||||||
|
jl.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
contentPane.add(jl);
|
||||||
|
contentPane.add(Box.createVerticalStrut(15));
|
||||||
|
|
||||||
|
// Modusauswahl
|
||||||
|
String[] modi = {"Blitz", "Schnellschach", "Klassisch"};
|
||||||
|
JComboBox<String> jcb1 = new JComboBox<>(modi);
|
||||||
|
jcb1 .setMaximumSize(new Dimension(150, 30));
|
||||||
|
jcb1 .setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
contentPane.add(jcb1 );
|
||||||
|
contentPane.add(Box.createVerticalStrut(15));
|
||||||
|
|
||||||
|
// Spielbrettdrehen
|
||||||
|
JLabel jl2 = new JLabel("Soll das Spielbrett nach jedem Zug gedreht werden?");
|
||||||
|
jl2 .setFont(new Font("Calibri", Font.BOLD, 20));
|
||||||
|
jl2 .setForeground(Color.BLACK);
|
||||||
|
jl2 .setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
contentPane.add(jl2 );
|
||||||
|
|
||||||
|
JCheckBox jb1 = new JCheckBox();
|
||||||
|
jb1.setOpaque(false);
|
||||||
|
jb1.setFocusPainted(false);
|
||||||
|
jb1.setForeground(Color.BLACK);
|
||||||
|
jb1 .setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
jb1 .setMaximumSize(new Dimension(30, 30));
|
||||||
|
contentPane.add(jb1 );
|
||||||
|
contentPane.add(Box.createVerticalStrut(15));
|
||||||
|
|
||||||
|
// Zurücknahmeoption
|
||||||
|
JLabel jl3 = new JLabel("Sollen Zurücknahmen erlaubt sein?");
|
||||||
|
jl3.setFont(new Font("Calibri", Font.BOLD, 20));
|
||||||
|
jl3.setForeground(Color.BLACK);
|
||||||
|
jl3.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
contentPane.add(jl3);
|
||||||
|
|
||||||
|
JCheckBox jb2 = new JCheckBox();
|
||||||
|
jb2.setOpaque(false);
|
||||||
|
jb2.setFocusPainted(false);
|
||||||
|
jb2.setForeground(Color.BLACK);
|
||||||
|
jb2.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
jb2.setMaximumSize(new Dimension(30, 30));
|
||||||
|
contentPane.add(jb2);
|
||||||
|
contentPane.add(Box.createVerticalStrut(25));
|
||||||
|
|
||||||
|
// Spiel starten Button
|
||||||
|
JButton btnNewButton = new JButton("Spiel starten");
|
||||||
|
btnNewButton .setBackground(Color.LIGHT_GRAY);
|
||||||
|
btnNewButton .setForeground(Color.BLACK);
|
||||||
|
btnNewButton .setFont(new Font("Tahoma", Font.BOLD, 16));
|
||||||
|
btnNewButton .setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
contentPane.add(btnNewButton );
|
||||||
|
|
||||||
|
// Button-Listener
|
||||||
|
btnNewButton .addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
String modus = (String) jcb1.getSelectedItem();
|
||||||
|
boolean rotieren = jb1.isSelected();
|
||||||
|
boolean zuruecknahme = jb2.isSelected();
|
||||||
|
|
||||||
|
Game game = new Game(modus, rotieren, zuruecknahme);
|
||||||
|
|
||||||
|
spiele.add(game);
|
||||||
|
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,14 +8,16 @@ import com.github.bhlangonijr.chesslib.move.Move;
|
||||||
|
|
||||||
import de.mannheim.th.chess.App;
|
import de.mannheim.th.chess.App;
|
||||||
import de.mannheim.th.chess.domain.Game;
|
import de.mannheim.th.chess.domain.Game;
|
||||||
|
import de.mannheim.th.chess.utl.Clock;
|
||||||
import de.mannheim.th.chess.controller.ButtonMovePieceListener;
|
import de.mannheim.th.chess.controller.ButtonMovePieceListener;
|
||||||
import de.mannheim.th.chess.controller.ButtonSelectPieceListener;
|
import de.mannheim.th.chess.controller.ButtonSelectPieceListener;
|
||||||
import de.mannheim.th.chess.controller.ButtonToNormalListener;
|
import de.mannheim.th.chess.controller.ButtonToNormalListener;
|
||||||
|
|
||||||
import java.awt.EventQueue;
|
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
|
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
|
import javax.swing.Box;
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
|
@ -25,6 +27,7 @@ import javax.swing.JSplitPane;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.Component;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -39,6 +42,7 @@ public class SpielFrame extends JFrame {
|
||||||
private HashMap<JButton, String> belegungen = new HashMap<>();
|
private HashMap<JButton, String> belegungen = new HashMap<>();
|
||||||
private JPanel panelLinks, panelRechts, contentPane;
|
private JPanel panelLinks, panelRechts, contentPane;
|
||||||
private Game game;
|
private Game game;
|
||||||
|
private Clock clock;
|
||||||
|
|
||||||
private BoardMode mode;
|
private BoardMode mode;
|
||||||
private Square selectedSquare;
|
private Square selectedSquare;
|
||||||
|
|
@ -50,12 +54,15 @@ public class SpielFrame extends JFrame {
|
||||||
/**
|
/**
|
||||||
* Create the frame.
|
* Create the frame.
|
||||||
*/
|
*/
|
||||||
public SpielFrame() {
|
public SpielFrame(Game game) {
|
||||||
|
|
||||||
game = new Game();
|
this.game = game;
|
||||||
|
this.clock = game.getClock();
|
||||||
|
this.clock.start();
|
||||||
|
|
||||||
mode = BoardMode.normal;
|
mode = BoardMode.normal;
|
||||||
|
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
setBounds(100, 100, 1920, 1080);
|
setBounds(100, 100, 1920, 1080);
|
||||||
setTitle("Schach");
|
setTitle("Schach");
|
||||||
setAlwaysOnTop(true);
|
setAlwaysOnTop(true);
|
||||||
|
|
@ -71,15 +78,43 @@ public class SpielFrame extends JFrame {
|
||||||
|
|
||||||
// Rechtes Panel für Steuerung oder zusätzliche Eingaben
|
// Rechtes Panel für Steuerung oder zusätzliche Eingaben
|
||||||
panelRechts = new JPanel();
|
panelRechts = new JPanel();
|
||||||
panelRechts.setBackground(Color.LIGHT_GRAY);
|
panelRechts.setBackground(new Color(90,90,90));
|
||||||
|
panelRechts.setLayout(new BoxLayout(panelRechts, BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
|
|
||||||
|
JLabel pl1 = new JLabel("Player 1:");
|
||||||
|
pl1.setFont(new Font("Calibri", Font.BOLD, 35));
|
||||||
|
pl1.setForeground(Color.BLACK);
|
||||||
|
pl1.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||||
|
panelRechts.add(pl1);
|
||||||
|
|
||||||
|
contentPane.add(Box.createVerticalStrut(15));
|
||||||
|
|
||||||
|
//Zeitangabe Player1
|
||||||
|
JLabel clock1 = clock.getClock2();
|
||||||
|
panelRechts.add(clock1);
|
||||||
|
|
||||||
|
contentPane.add(Box.createVerticalStrut(15));
|
||||||
|
|
||||||
|
JLabel pl2 = new JLabel("Player 2:");
|
||||||
|
pl2.setFont(new Font("Calibri", Font.BOLD, 35));
|
||||||
|
pl2.setForeground(Color.BLACK);
|
||||||
|
pl2.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||||
|
panelRechts.add(pl2);
|
||||||
|
|
||||||
|
//Zeitangabe Player2
|
||||||
|
JLabel clock2 = clock.getClock1();
|
||||||
|
panelRechts.add(clock2);
|
||||||
|
|
||||||
// JSplitPane horizontal (linke und rechte Hälfte)
|
// JSplitPane horizontal (linke und rechte Hälfte)
|
||||||
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panelLinks, panelRechts);
|
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panelLinks, panelRechts);
|
||||||
splitPane.setResizeWeight(0.70);
|
splitPane.setResizeWeight(0.65);
|
||||||
splitPane.setDividerSize(5);
|
splitPane.setBackground(Color.BLACK);
|
||||||
|
splitPane.setDividerSize(0);
|
||||||
splitPane.setEnabled(false);
|
splitPane.setEnabled(false);
|
||||||
|
|
||||||
contentPane.add(splitPane, BorderLayout.CENTER);
|
contentPane.add(splitPane, BorderLayout.CENTER);
|
||||||
|
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -109,32 +144,6 @@ public class SpielFrame extends JFrame {
|
||||||
panelLinks.revalidate();
|
panelLinks.revalidate();
|
||||||
panelLinks.repaint();
|
panelLinks.repaint();
|
||||||
|
|
||||||
// // Bild laden und Cursor im gesamten Frame setzen
|
|
||||||
// Image image = Toolkit.getDefaultToolkit().getImage(pfad);
|
|
||||||
// Image scaled = image.getScaledInstance(32, 32, Image.SCALE_SMOOTH);
|
|
||||||
// Cursor figurCursor = Toolkit.getDefaultToolkit().createCustomCursor(scaled,
|
|
||||||
// new Point(0, 0),
|
|
||||||
// "figurCursor");
|
|
||||||
// setCursor(figurCursor);
|
|
||||||
|
|
||||||
// }else
|
|
||||||
// {
|
|
||||||
//
|
|
||||||
// // wenn gerade Figur ausgewählt wird...
|
|
||||||
// buttonChoosed = (JButton) e.getSource();
|
|
||||||
// symbolChoosed = belegungen.get(buttonChoosed);
|
|
||||||
// // System.out.println(symbolChoosed+" wurde gewählt.");
|
|
||||||
// // setzt cursor auf spielfigur für die animation
|
|
||||||
// String pfad = "src/main/resources/" + (int) symbolChoosed.toCharArray()[2] +
|
|
||||||
// ".png";
|
|
||||||
//
|
|
||||||
// // Bild laden und Cursor im gesamten Frame setzen
|
|
||||||
// Image image = Toolkit.getDefaultToolkit().getImage(pfad);
|
|
||||||
// Image scaled = image.getScaledInstance(32, 32, Image.SCALE_SMOOTH);
|
|
||||||
// Cursor figurCursor = Toolkit.getDefaultToolkit().createCustomCursor(scaled,
|
|
||||||
// new Point(0, 0),
|
|
||||||
// "figurCursor");
|
|
||||||
// setCursor(figurCursor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int mirrowedGrid(int i) {
|
private int mirrowedGrid(int i) {
|
||||||
|
|
@ -205,10 +214,10 @@ public class SpielFrame extends JFrame {
|
||||||
for (int i = 0; i < 64; i++) {
|
for (int i = 0; i < 64; i++) {
|
||||||
JButton b = buttons.get(i);
|
JButton b = buttons.get(i);
|
||||||
if ((i / 8 + i % 8) % 2 == 0) {
|
if ((i / 8 + i % 8) % 2 == 0) {
|
||||||
logger.info("Helles Feld erstellt." + i);
|
//logger.info("Helles Feld erstellt." + i);
|
||||||
b.setBackground(new Color(90, 90, 90));
|
b.setBackground(new Color(90, 90, 90));
|
||||||
} else {
|
} else {
|
||||||
logger.info("Dunkles Feld erstellt." + i);
|
//logger.info("Dunkles Feld erstellt." + i);
|
||||||
b.setBackground(new Color(65, 65, 65));
|
b.setBackground(new Color(65, 65, 65));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,17 +17,21 @@ import javax.swing.Timer;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import de.mannheim.th.chess.ui.SpielFrame;
|
||||||
|
|
||||||
public class Clock extends Thread implements Runnable {
|
public class Clock extends Thread implements Runnable {
|
||||||
private volatile boolean whiteToMove = true;
|
private volatile boolean whiteToMove = true;
|
||||||
private volatile boolean gameHasFinished = false;
|
private volatile boolean gameHasFinished = false;
|
||||||
private static final Logger clockLogger = LogManager.getLogger(Clock.class);
|
private static final Logger clockLogger = LogManager.getLogger(Clock.class);
|
||||||
private int minutes;
|
private int minutes;
|
||||||
|
private StringBuilder clockShower;
|
||||||
|
private JLabel clock1, clock2;
|
||||||
|
|
||||||
public Clock(String mode) {
|
public Clock(String mode) {
|
||||||
|
|
||||||
setMode(mode);
|
setMode(mode);
|
||||||
//run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pressClock() {
|
public void pressClock() {
|
||||||
whiteToMove = !whiteToMove;
|
whiteToMove = !whiteToMove;
|
||||||
if (whiteToMove) {
|
if (whiteToMove) {
|
||||||
|
|
@ -36,105 +40,109 @@ public class Clock extends Thread implements Runnable {
|
||||||
clockLogger.info("Schwarz ist am Zug");
|
clockLogger.info("Schwarz ist am Zug");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void endGame() {
|
public void endGame() {
|
||||||
gameHasFinished = true;
|
gameHasFinished = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
JFrame clockFrame = new JFrame("Clock");
|
// JFrame clockFrame = new JFrame("Clock");
|
||||||
|
//
|
||||||
JPanel player1Panel = new JPanel();
|
// JPanel player1Panel = new JPanel();
|
||||||
player1Panel.setBackground(Color.BLACK);
|
// player1Panel.setBackground(Color.BLACK);
|
||||||
JPanel player2Panel = new JPanel();
|
// JPanel player2Panel = new JPanel();
|
||||||
player2Panel.setBackground(Color.BLACK);
|
// player2Panel.setBackground(Color.BLACK);
|
||||||
clockFrame.setBounds(1000, 500, 10000, 10000);
|
// clockFrame.setBounds(1000, 500, 10000, 10000);
|
||||||
clockFrame.setLayout(new BorderLayout());
|
// clockFrame.setLayout(new BorderLayout());
|
||||||
JLabel clock1 = new JLabel(" " + minutes + ":00 ");
|
clock1 = new JLabel(" " + minutes + ":00 ");
|
||||||
clock1.setForeground(Color.WHITE);
|
clock1.setForeground(Color.BLACK);
|
||||||
clock1.setFont(new Font("Arial", Font.BOLD, 50));
|
clock1.setFont(new Font("Calibri", Font.BOLD, 35));
|
||||||
JLabel clock2 = new JLabel(" " + minutes + ":00 ");
|
clock2 = new JLabel(" " + minutes + ":00 ");
|
||||||
clock2.setForeground(Color.WHITE);
|
clock2.setForeground(Color.BLACK);
|
||||||
clock2.setFont(new Font("Arial", Font.BOLD, 50));
|
clock2.setFont(new Font("Calibri", Font.BOLD, 35));
|
||||||
player1Panel.add(clock1);
|
// player1Panel.add(clock1);
|
||||||
player2Panel.add(clock2);
|
// player2Panel.add(clock2);
|
||||||
JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, player1Panel, player2Panel);
|
// JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, player1Panel, player2Panel);
|
||||||
split.setFont(new Font("Arial", Font.BOLD, 50));
|
// split.setFont(new Font("Arial", Font.BOLD, 50));
|
||||||
clockFrame.add(split);
|
// clockFrame.add(split);
|
||||||
|
|
||||||
var min1 = new AtomicInteger(minutes);
|
var min1 = new AtomicInteger(minutes);
|
||||||
var sec1 = new AtomicInteger(0);
|
var sec1 = new AtomicInteger(0);
|
||||||
var min2 = new AtomicInteger(minutes);
|
var min2 = new AtomicInteger(minutes);
|
||||||
var sec2 = new AtomicInteger(0);
|
var sec2 = new AtomicInteger(0);
|
||||||
clockFrame.pack();
|
|
||||||
clockFrame.setVisible(true);
|
|
||||||
|
|
||||||
var t = new Timer(1000, (ae) -> {
|
var t = new Timer(1000, (ae) -> {
|
||||||
|
|
||||||
if (!gameHasFinished) {
|
|
||||||
|
|
||||||
StringBuilder clockShower = new StringBuilder();
|
|
||||||
if (whiteToMove) {
|
|
||||||
if (sec1.intValue() == 00) {
|
|
||||||
sec1.set(60);
|
|
||||||
min1.decrementAndGet();
|
|
||||||
}
|
|
||||||
if (min1.intValue() < 10) {
|
|
||||||
clockShower.append("0");
|
|
||||||
}
|
|
||||||
clockShower.append(min1.get());
|
|
||||||
clockShower.append(":");
|
|
||||||
if (sec1.intValue() < 10) {
|
|
||||||
clockShower.append("0");
|
|
||||||
}
|
|
||||||
clockShower.append(sec1.decrementAndGet());
|
|
||||||
clock1.setText(clockShower.toString());
|
|
||||||
|
|
||||||
} else {
|
if (!gameHasFinished) {
|
||||||
if (sec2.intValue() == 00) {
|
|
||||||
sec2.set(60);
|
clockShower = new StringBuilder();
|
||||||
min2.decrementAndGet();
|
if (whiteToMove) {
|
||||||
|
if (sec1.intValue() == 00) {
|
||||||
|
sec1.set(60);
|
||||||
|
min1.decrementAndGet();
|
||||||
|
}
|
||||||
|
if (min1.intValue() < 10) {
|
||||||
|
clockShower.append("0");
|
||||||
|
}
|
||||||
|
clockShower.append(min1.get());
|
||||||
|
clockShower.append(":");
|
||||||
|
if (sec1.intValue() < 10) {
|
||||||
|
clockShower.append("0");
|
||||||
|
}
|
||||||
|
clockShower.append(sec1.decrementAndGet());
|
||||||
|
clock1.setText(clockShower.toString());
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (sec2.intValue() == 00) {
|
||||||
|
sec2.set(60);
|
||||||
|
min2.decrementAndGet();
|
||||||
|
}
|
||||||
|
if (min2.intValue() < 10) {
|
||||||
|
clockShower.append("0");
|
||||||
|
}
|
||||||
|
clockShower.append(min2.get());
|
||||||
|
clockShower.append(":");
|
||||||
|
if (sec2.intValue() < 10) {
|
||||||
|
clockShower.append("0");
|
||||||
|
}
|
||||||
|
clockShower.append(sec2.decrementAndGet());
|
||||||
|
clock2.setText(clockShower.toString());
|
||||||
}
|
}
|
||||||
if (min2.intValue() < 10) {
|
//sp.repaint();
|
||||||
clockShower.append("0");
|
if ((sec1.intValue() == 0 && min1.intValue() == 0) || (sec2.intValue() == 0 && min2.intValue() == 0)) {
|
||||||
|
endGame();
|
||||||
}
|
}
|
||||||
clockShower.append(min2.get());
|
|
||||||
clockShower.append(":");
|
|
||||||
if (sec2.intValue() < 10) {
|
|
||||||
clockShower.append("0");
|
|
||||||
}
|
|
||||||
clockShower.append(sec2.decrementAndGet());
|
|
||||||
clock2.setText(clockShower.toString());
|
|
||||||
}
|
}
|
||||||
clockFrame.repaint();
|
});
|
||||||
if ((sec1.intValue() == 0 && min1.intValue() == 0) || (sec2.intValue() == 0 && min2.intValue() == 0)) {
|
|
||||||
endGame();
|
|
||||||
}
|
|
||||||
} });
|
|
||||||
|
|
||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
public static void main(String[] args) throws InterruptedException {
|
|
||||||
Clock st = new Clock("classic");
|
|
||||||
st.start();
|
|
||||||
st.pressClock();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setMode(String mode) {
|
private void setMode(String mode) {
|
||||||
switch(mode) {
|
switch (mode.toLowerCase()) {
|
||||||
case "blitz":
|
case "blitz":
|
||||||
minutes = 5;
|
minutes = 5;
|
||||||
clockLogger.info("Neue Blitz-Uhr wurde erstellt");
|
clockLogger.info("Neue Blitz-Uhr wurde erstellt");
|
||||||
break;
|
break;
|
||||||
case "rapid":
|
case "schnellschach":
|
||||||
minutes = 10;
|
minutes = 10;
|
||||||
clockLogger.info("Neue Schnellschach-Uhr wurde erstellt");
|
clockLogger.info("Neue Schnellschach-Uhr wurde erstellt");
|
||||||
break;
|
break;
|
||||||
case "classic":
|
case "klassisch":
|
||||||
minutes = 120;
|
minutes = 120;
|
||||||
clockLogger.info("Neue klassische Schachuhr wurde erstellt");
|
clockLogger.info("Neue klassische Schachuhr wurde erstellt");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JLabel getClock1() {
|
||||||
|
|
||||||
|
return clock1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JLabel getClock2() {
|
||||||
|
|
||||||
|
return clock2;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue