commit
b6a74b957e
Binary file not shown.
Binary file not shown.
|
|
@ -2,24 +2,26 @@ package de.mannheim.th.chess;
|
|||
|
||||
import de.mannheim.th.chess.ui.MainFrame;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
// import org.apache.logging.log4j.LogManager;
|
||||
// import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Eine einfache Schach App mithilfe von {@linkplain https://github.com/bhlangonijr/chesslib} entwickelt.
|
||||
* Eine einfache Schach App mithilfe von
|
||||
* {@linkplain https://github.com/bhlangonijr/chesslib} entwickelt.
|
||||
*
|
||||
* @author Matias Mas Viehl, Dominik Stuck und Marius Guendel
|
||||
* @version 0.0.1
|
||||
*/
|
||||
public class App {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(App.class);
|
||||
// private static final Logger logger = LogManager.getLogger(App.class);
|
||||
|
||||
private static MainFrame userinterface;
|
||||
/**
|
||||
* Main-Methode.
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
userinterface = new MainFrame();
|
||||
}
|
||||
/**
|
||||
* Main-Methode.
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
new MainFrame();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,41 +14,43 @@ import javax.swing.JOptionPane;
|
|||
|
||||
import de.mannheim.th.chess.ui.ModeSelectionFrame;
|
||||
|
||||
public class ButtonFileLoaderListener implements ActionListener{
|
||||
public class ButtonFileLoaderListener implements ActionListener {
|
||||
|
||||
private ModeSelectionFrame msf;
|
||||
private ModeSelectionFrame msf;
|
||||
|
||||
public ButtonFileLoaderListener(ModeSelectionFrame msf) {
|
||||
this.msf = msf;
|
||||
public ButtonFileLoaderListener(ModeSelectionFrame msf) {
|
||||
this.msf = msf;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
JFileChooser dateiWaehler = new JFileChooser();
|
||||
JFrame jfFile = new JFrame();
|
||||
int auswahl = dateiWaehler.showOpenDialog(jfFile);
|
||||
JFileChooser dateiWaehler = new JFileChooser();
|
||||
JFrame jfFile = new JFrame();
|
||||
int auswahl = dateiWaehler.showOpenDialog(jfFile);
|
||||
|
||||
if (auswahl == JFileChooser.APPROVE_OPTION) {
|
||||
File ausgewaehlteDatei = dateiWaehler.getSelectedFile();
|
||||
JOptionPane.showMessageDialog(jfFile, "Gewählte Datei:\n" + ausgewaehlteDatei.getAbsolutePath());
|
||||
if (auswahl == JFileChooser.APPROVE_OPTION) {
|
||||
File ausgewaehlteDatei = dateiWaehler.getSelectedFile();
|
||||
JOptionPane.showMessageDialog(jfFile, "Gewählte Datei:\n" + ausgewaehlteDatei.getAbsolutePath());
|
||||
|
||||
try {
|
||||
BufferedReader br = new BufferedReader(new FileReader(ausgewaehlteDatei));
|
||||
try {
|
||||
BufferedReader br = new BufferedReader(new FileReader(ausgewaehlteDatei));
|
||||
|
||||
msf.setFen(br.readLine());
|
||||
msf.setFen(br.readLine());
|
||||
|
||||
} catch (FileNotFoundException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
} catch (IOException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
br.close();
|
||||
|
||||
}
|
||||
} catch (FileNotFoundException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
} catch (IOException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import java.io.BufferedWriter;
|
|||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JFrame;
|
||||
|
|
@ -14,48 +13,46 @@ import javax.swing.JFrame;
|
|||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.github.bhlangonijr.chesslib.move.Move;
|
||||
|
||||
import de.mannheim.th.chess.App;
|
||||
import de.mannheim.th.chess.domain.Game;
|
||||
|
||||
public class ButtonFileSaverListener implements ActionListener{
|
||||
public class ButtonFileSaverListener implements ActionListener {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(App.class);
|
||||
private static final Logger logger = LogManager.getLogger(App.class);
|
||||
|
||||
private Game g;
|
||||
private JFrame sf;
|
||||
private Game g;
|
||||
private JFrame sf;
|
||||
|
||||
public ButtonFileSaverListener(JFrame sf, Game g) {
|
||||
this.sf = sf;
|
||||
this.g = g;
|
||||
}
|
||||
public ButtonFileSaverListener(JFrame sf, Game g) {
|
||||
this.sf = sf;
|
||||
this.g = g;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
logger.info("Spiel wird gespeichert.");
|
||||
logger.info("Spiel wird gespeichert.");
|
||||
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
chooser.setCurrentDirectory(new File(System.getProperty("user.home") + "/Documents"));
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
chooser.setCurrentDirectory(new File(System.getProperty("user.home") + "/Documents"));
|
||||
|
||||
chooser.setDialogTitle("Datei speichern");
|
||||
int userSelection = chooser.showSaveDialog(sf);
|
||||
chooser.setDialogTitle("Datei speichern");
|
||||
int userSelection = chooser.showSaveDialog(sf);
|
||||
|
||||
if (userSelection == JFileChooser.APPROVE_OPTION) {
|
||||
File fileToSave = chooser.getSelectedFile();
|
||||
if (userSelection == JFileChooser.APPROVE_OPTION) {
|
||||
File fileToSave = chooser.getSelectedFile();
|
||||
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(fileToSave))) {
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(fileToSave))) {
|
||||
|
||||
writer.write(g.getFen());
|
||||
writer.write(g.getFen());
|
||||
|
||||
logger.info(g.getFen());
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
logger.info("Speichern fehlgeschlagen.");
|
||||
}
|
||||
}
|
||||
logger.info(g.getFen());
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
logger.info("Speichern fehlgeschlagen.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package de.mannheim.th.chess.controller;
|
|||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import de.mannheim.th.chess.domain.Game;
|
||||
import de.mannheim.th.chess.ui.SpielFrame;
|
||||
import de.mannheim.th.chess.ui.SpielFrame.BoardMode;
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ public class Game {
|
|||
|
||||
private Board board;
|
||||
private Clock clock;
|
||||
private String modus;
|
||||
private boolean rotieren, zuruecknahme;
|
||||
|
||||
private MoveList movelist;
|
||||
|
|
@ -50,7 +49,6 @@ public class Game {
|
|||
}
|
||||
|
||||
public Game(String modus, boolean rotieren, boolean zuruecknahme, String fen) {
|
||||
this.modus = modus;
|
||||
this.rotieren = rotieren;
|
||||
this.zuruecknahme = zuruecknahme;
|
||||
|
||||
|
|
@ -96,10 +94,6 @@ public class Game {
|
|||
|
||||
this.movelist = new MoveList();
|
||||
this.startPosFen = this.board.getFen();
|
||||
// this.sp = new SpielFrame();
|
||||
|
||||
// this.clockPlayer1 = new Clock();
|
||||
// this.clockPlayer2 = new Clock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -169,6 +163,55 @@ public class Game {
|
|||
|
||||
}
|
||||
|
||||
public void doPromotionMove(int piece, Square origin, Square destination) {
|
||||
System.out.println(piece);
|
||||
Piece promotedTo;
|
||||
switch (piece) {
|
||||
case 7:
|
||||
promotedTo = Piece.BLACK_KNIGHT;
|
||||
break;
|
||||
case 4:
|
||||
promotedTo = Piece.BLACK_QUEEN;
|
||||
break;
|
||||
case 5:
|
||||
promotedTo = Piece.BLACK_ROOK;
|
||||
break;
|
||||
case 6:
|
||||
promotedTo = Piece.BLACK_BISHOP;
|
||||
break;
|
||||
case 3:
|
||||
promotedTo = Piece.WHITE_KNIGHT;
|
||||
break;
|
||||
case 0:
|
||||
promotedTo = Piece.WHITE_QUEEN;
|
||||
break;
|
||||
case 1:
|
||||
promotedTo = Piece.WHITE_ROOK;
|
||||
break;
|
||||
case 2:
|
||||
promotedTo = Piece.WHITE_BISHOP;
|
||||
break;
|
||||
default:
|
||||
promotedTo = Piece.WHITE_QUEEN;
|
||||
}
|
||||
Move promotionMove = new Move(origin, destination, promotedTo);
|
||||
playMove(promotionMove);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the current view
|
||||
*
|
||||
* @brief Creates a new gameboard from the start pos and playes moves until it
|
||||
* reaches the viewPointer
|
||||
*/
|
||||
public void loadView() {
|
||||
this.board = new Board();
|
||||
this.board.loadFromFen(this.startPosFen);
|
||||
for (int i = 0; i < this.viewPointer; i++) {
|
||||
this.board.doMove(this.movelist.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMate() {
|
||||
return board.isMated();
|
||||
}
|
||||
|
|
@ -228,45 +271,6 @@ public class Game {
|
|||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void doPromotionMove(int piece, Square origin, Square destination) {
|
||||
System.out.println(piece);
|
||||
Piece promotedTo;
|
||||
switch (piece) {
|
||||
case 7:
|
||||
promotedTo = Piece.BLACK_KNIGHT;
|
||||
break;
|
||||
case 4:
|
||||
promotedTo = Piece.BLACK_QUEEN;
|
||||
break;
|
||||
case 5:
|
||||
promotedTo = Piece.BLACK_ROOK;
|
||||
break;
|
||||
case 6:
|
||||
promotedTo = Piece.BLACK_BISHOP;
|
||||
break;
|
||||
case 3:
|
||||
promotedTo = Piece.WHITE_KNIGHT;
|
||||
break;
|
||||
case 0:
|
||||
promotedTo = Piece.WHITE_QUEEN;
|
||||
break;
|
||||
case 1:
|
||||
promotedTo = Piece.WHITE_ROOK;
|
||||
break;
|
||||
case 2:
|
||||
promotedTo = Piece.WHITE_BISHOP;
|
||||
break;
|
||||
default:
|
||||
promotedTo = Piece.WHITE_QUEEN;
|
||||
}
|
||||
Move promotionMove = new Move(origin, destination, promotedTo);
|
||||
playMove(promotionMove);
|
||||
}
|
||||
|
||||
public void setModus(String modus) {
|
||||
this.modus = modus;
|
||||
}
|
||||
|
||||
public Clock getClock() {
|
||||
return this.clock;
|
||||
}
|
||||
|
|
@ -296,7 +300,6 @@ public class Game {
|
|||
}
|
||||
|
||||
public Board getBoard() {
|
||||
// TODO Auto-generated method stub
|
||||
return this.board;
|
||||
}
|
||||
|
||||
|
|
@ -305,10 +308,6 @@ public class Game {
|
|||
return board.getFen();
|
||||
}
|
||||
|
||||
// public Square getSelectedSquare() {
|
||||
// return this.getSelectedSquare();
|
||||
// }
|
||||
|
||||
public String getUnicodeFromMove(Move move) {
|
||||
return board.getPiece(move.getTo()).getFanSymbol().toUpperCase();
|
||||
}
|
||||
|
|
@ -321,22 +320,8 @@ public class Game {
|
|||
return this.viewPointer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the current view
|
||||
*
|
||||
* @brief Creates a new gameboard from the start pos and playes moves until it
|
||||
* reaches the viewPointer
|
||||
*/
|
||||
public void loadView() {
|
||||
this.board = new Board();
|
||||
this.board.loadFromFen(this.startPosFen);
|
||||
for (int i = 0; i < this.viewPointer; i++) {
|
||||
this.board.doMove(this.movelist.get(i));
|
||||
}
|
||||
public boolean isRotieren() {
|
||||
return rotieren;
|
||||
}
|
||||
|
||||
public boolean isRotieren() {
|
||||
return rotieren;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
package de.mannheim.th.chess.domain;
|
||||
|
||||
/**
|
||||
* Ueberprueft, ob ein Zug gueltig ist.
|
||||
*/
|
||||
public class MoveChecker{
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
package de.mannheim.th.chess.domain;
|
||||
|
||||
/**
|
||||
* Liest einen Zug ein.
|
||||
*/
|
||||
public class MoveReader{
|
||||
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
package de.mannheim.th.chess.model;
|
||||
|
||||
/**
|
||||
* Speichert Spielstaende, bisher gespielte Spiele und weiteres in einem File.
|
||||
*/
|
||||
public class Database{
|
||||
|
||||
public Database() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
package de.mannheim.th.chess.ui;
|
||||
|
||||
import de.mannheim.th.chess.model.Database;
|
||||
|
||||
/**
|
||||
* ???
|
||||
*/
|
||||
public class Creator{
|
||||
|
||||
private Database database = new Database();
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package de.mannheim.th.chess.ui;
|
||||
|
||||
import de.mannheim.th.chess.domain.Game;
|
||||
|
||||
/**
|
||||
* Zeigt das Spielbrett mit den Stats rechts daneben an.
|
||||
*/
|
||||
public class GameWindow{
|
||||
|
||||
//private Game gamelogic = new Game();
|
||||
|
||||
public GameWindow() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -4,10 +4,10 @@ import javax.swing.JFrame;
|
|||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
// import org.apache.logging.log4j.LogManager;
|
||||
// import org.apache.logging.log4j.Logger;
|
||||
|
||||
import de.mannheim.th.chess.App;
|
||||
// import de.mannheim.th.chess.App;
|
||||
import de.mannheim.th.chess.domain.Game;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
|
|
@ -19,13 +19,12 @@ import javax.swing.Box;
|
|||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Font;
|
||||
import java.awt.Color;
|
||||
|
||||
public class MainFrame extends JFrame {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(App.class);
|
||||
// private static final Logger logger = LogManager.getLogger(App.class);
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JPanel contentPane;
|
||||
|
|
@ -40,7 +39,7 @@ public class MainFrame extends JFrame {
|
|||
setResizable(true);
|
||||
setAlwaysOnTop(true);
|
||||
setTitle("Schach");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 500, 500);
|
||||
|
||||
contentPane = new JPanel();
|
||||
|
|
@ -57,14 +56,14 @@ public class MainFrame extends JFrame {
|
|||
JLabel lblNewLabel = new JLabel("Schach");
|
||||
lblNewLabel.setForeground(Color.BLACK);
|
||||
lblNewLabel.setFont(new Font("Serif", Font.BOLD, 60));
|
||||
lblNewLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
lblNewLabel.setAlignmentX(CENTER_ALIGNMENT);
|
||||
contentPane.add(lblNewLabel);
|
||||
|
||||
contentPane.add(Box.createVerticalStrut(10));
|
||||
|
||||
JLabel lblNewLabel_1 = new JLabel("by Dominik, Marius und Matias");
|
||||
lblNewLabel_1.setFont(new Font("Calibri", Font.ITALIC, 24));
|
||||
lblNewLabel_1.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
lblNewLabel_1.setAlignmentX(CENTER_ALIGNMENT);
|
||||
contentPane.add(lblNewLabel_1);
|
||||
|
||||
contentPane.add(Box.createVerticalStrut(75));
|
||||
|
|
@ -74,7 +73,7 @@ public class MainFrame extends JFrame {
|
|||
btnNewButton.setBackground(Color.LIGHT_GRAY);
|
||||
btnNewButton.setForeground(Color.BLACK);
|
||||
btnNewButton.setFont(new Font("Tahoma", Font.BOLD, 16));
|
||||
btnNewButton.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
btnNewButton.setAlignmentX(CENTER_ALIGNMENT);
|
||||
btnNewButton.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
|
|
@ -98,7 +97,7 @@ public class MainFrame extends JFrame {
|
|||
btnNewButton_2.setBackground(Color.LIGHT_GRAY);
|
||||
btnNewButton_2.setForeground(Color.BLACK);
|
||||
btnNewButton_2.setFont(new Font("Tahoma", Font.BOLD, 16));
|
||||
btnNewButton_2.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
btnNewButton_2.setAlignmentX(CENTER_ALIGNMENT);
|
||||
btnNewButton_2.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
|
|
@ -118,7 +117,7 @@ public class MainFrame extends JFrame {
|
|||
public void startGame() {
|
||||
if (this.game != null) {
|
||||
this.game.stopClock();
|
||||
SpielFrame sf = new SpielFrame(this.game);
|
||||
new SpielFrame(this.game);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,29 +3,22 @@ package de.mannheim.th.chess.ui;
|
|||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
// import org.apache.logging.log4j.LogManager;
|
||||
// import org.apache.logging.log4j.Logger;
|
||||
|
||||
import de.mannheim.th.chess.App;
|
||||
// import de.mannheim.th.chess.App;
|
||||
import de.mannheim.th.chess.controller.ButtonFileLoaderListener;
|
||||
import de.mannheim.th.chess.domain.Game;
|
||||
|
||||
public class ModeSelectionFrame extends JFrame {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(App.class);
|
||||
// private static final Logger logger = LogManager.getLogger(App.class);
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final JPanel contentPane;
|
||||
private final ArrayList<Game> spiele = new ArrayList<>();
|
||||
private String fen;
|
||||
|
||||
public ModeSelectionFrame(MainFrame mf) {
|
||||
|
|
@ -47,7 +40,7 @@ public class ModeSelectionFrame extends JFrame {
|
|||
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);
|
||||
jl.setAlignmentX(CENTER_ALIGNMENT);
|
||||
contentPane.add(jl);
|
||||
contentPane.add(Box.createVerticalStrut(15));
|
||||
|
||||
|
|
@ -55,7 +48,7 @@ public class ModeSelectionFrame extends JFrame {
|
|||
String[] modi = { "Blitz", "Schnellschach", "Klassisch" };
|
||||
JComboBox<String> jcb1 = new JComboBox<>(modi);
|
||||
jcb1.setMaximumSize(new Dimension(150, 30));
|
||||
jcb1.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
jcb1.setAlignmentX(CENTER_ALIGNMENT);
|
||||
contentPane.add(jcb1);
|
||||
contentPane.add(Box.createVerticalStrut(15));
|
||||
|
||||
|
|
@ -63,14 +56,14 @@ public class ModeSelectionFrame extends JFrame {
|
|||
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);
|
||||
jl2.setAlignmentX(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.setAlignmentX(CENTER_ALIGNMENT);
|
||||
jb1.setMaximumSize(new Dimension(30, 30));
|
||||
contentPane.add(jb1);
|
||||
contentPane.add(Box.createVerticalStrut(15));
|
||||
|
|
@ -79,14 +72,14 @@ public class ModeSelectionFrame extends JFrame {
|
|||
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);
|
||||
jl3.setAlignmentX(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.setAlignmentX(CENTER_ALIGNMENT);
|
||||
jb2.setMaximumSize(new Dimension(30, 30));
|
||||
contentPane.add(jb2);
|
||||
|
||||
|
|
@ -97,7 +90,7 @@ public class ModeSelectionFrame extends JFrame {
|
|||
btnNewButton_1.setBackground(Color.LIGHT_GRAY);
|
||||
btnNewButton_1.setForeground(Color.BLACK);
|
||||
btnNewButton_1.setFont(new Font("Tahoma", Font.BOLD, 16));
|
||||
btnNewButton_1.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
btnNewButton_1.setAlignmentX(CENTER_ALIGNMENT);
|
||||
btnNewButton_1.addActionListener(new ButtonFileLoaderListener(this));
|
||||
|
||||
contentPane.add(btnNewButton_1);
|
||||
|
|
@ -109,7 +102,7 @@ public class ModeSelectionFrame extends JFrame {
|
|||
btnNewButton.setBackground(Color.LIGHT_GRAY);
|
||||
btnNewButton.setForeground(Color.BLACK);
|
||||
btnNewButton.setFont(new Font("Tahoma", Font.BOLD, 16));
|
||||
btnNewButton.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
btnNewButton.setAlignmentX(CENTER_ALIGNMENT);
|
||||
contentPane.add(btnNewButton);
|
||||
|
||||
// Button-Listener
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
package de.mannheim.th.chess.ui;
|
||||
|
||||
import java.util.List;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
|
||||
import javax.swing.BoxLayout;
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
package de.mannheim.th.chess.ui;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
// import org.apache.logging.log4j.LogManager;
|
||||
// import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.github.bhlangonijr.chesslib.Square;
|
||||
import com.github.bhlangonijr.chesslib.move.Move;
|
||||
import com.github.bhlangonijr.chesslib.move.MoveList;
|
||||
|
||||
import de.mannheim.th.chess.App;
|
||||
import de.mannheim.th.chess.domain.Game;
|
||||
import de.mannheim.th.chess.utl.Clock;
|
||||
import de.mannheim.th.chess.controller.ButtonAufgebenListener;
|
||||
|
|
@ -51,7 +50,7 @@ import java.awt.GridLayout;
|
|||
|
||||
public class SpielFrame extends JFrame {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(App.class);
|
||||
// private static final Logger logger = LogManager.getLogger(App.class);
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private ArrayList<JButton> buttons = new ArrayList<>();
|
||||
|
|
@ -82,7 +81,7 @@ public class SpielFrame extends JFrame {
|
|||
|
||||
mode = BoardMode.normal;
|
||||
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 1920, 1080);
|
||||
setTitle("Schach");
|
||||
setAlwaysOnTop(true);
|
||||
|
|
@ -137,8 +136,12 @@ public class SpielFrame extends JFrame {
|
|||
|
||||
}
|
||||
|
||||
private int mirrowedGrid(int i) {
|
||||
return 63 - (((i / 8) * 8) + (7 - i % 8));
|
||||
/**
|
||||
* Sets the to default buttons
|
||||
*/
|
||||
public void setDefaultButtons() {
|
||||
this.clearButtons();
|
||||
this.setDefaultBackground();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -186,87 +189,6 @@ public class SpielFrame extends JFrame {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the existing buttons from the button list, panellinks and fills them
|
||||
* with new blank ones.
|
||||
*/
|
||||
private void clearButtons() {
|
||||
|
||||
buttons.clear();
|
||||
panelLinks.removeAll();
|
||||
|
||||
for (int i = 0; i < 64; i++) {
|
||||
JButton b = new JButton();
|
||||
|
||||
b.setEnabled(false);
|
||||
|
||||
// style
|
||||
b.setFocusPainted(false);
|
||||
b.setFont(new Font("Arial", Font.PLAIN, 30));
|
||||
b.setForeground(Color.WHITE);
|
||||
b.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
b.setName(i + "");
|
||||
|
||||
buttons.add(b);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default background color for the buttons in the grid.
|
||||
*/
|
||||
private void setDefaultBackground() {
|
||||
int counter = 8;
|
||||
for (int i = 0; i < 64; i++) {
|
||||
JButton b = buttons.get(i);
|
||||
if ((i / 8 + i % 8) % 2 == 0) {
|
||||
// logger.info("Helles Feld erstellt." + i);
|
||||
b.setBackground(new Color(90, 90, 90));
|
||||
|
||||
} else {
|
||||
// logger.info("Dunkles Feld erstellt." + i);
|
||||
b.setBackground(new Color(65, 65, 65));
|
||||
}
|
||||
|
||||
if (i % 8 == 0) {
|
||||
b.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
b.setVerticalAlignment(SwingConstants.CENTER);
|
||||
|
||||
b.setHorizontalTextPosition(SwingConstants.LEFT); // Text rechts vom Icon
|
||||
b.setVerticalTextPosition(SwingConstants.BOTTOM);
|
||||
|
||||
b.setIconTextGap(5);
|
||||
|
||||
b.setText(String.valueOf(counter) + b.getText());
|
||||
counter--;
|
||||
}
|
||||
}
|
||||
|
||||
char buchstabe = 'a';
|
||||
for (int j = 0; j < 8; j++) {
|
||||
JButton button = buttons.get(mirrowedGrid(j));
|
||||
|
||||
button.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
button.setVerticalAlignment(SwingConstants.CENTER);
|
||||
|
||||
button.setHorizontalTextPosition(SwingConstants.RIGHT); // Text rechts vom Icon
|
||||
button.setVerticalTextPosition(SwingConstants.BOTTOM);
|
||||
|
||||
button.setIconTextGap(5);
|
||||
|
||||
button.setText(String.valueOf(buchstabe));
|
||||
buchstabe++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the to default buttons
|
||||
*/
|
||||
public void setDefaultButtons() {
|
||||
this.clearButtons();
|
||||
this.setDefaultBackground();
|
||||
}
|
||||
|
||||
/*
|
||||
* Switches the button actions depending on the boardmode
|
||||
*/
|
||||
|
|
@ -330,9 +252,29 @@ public class SpielFrame extends JFrame {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inverts the Enabled property of the controlpanelButtons
|
||||
*/
|
||||
public void enableControlPanelButtons() {
|
||||
for (Component c : this.controlPanel.getComponents()) {
|
||||
if (c instanceof JButton) {
|
||||
c.setEnabled(!c.isEnabled());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the buttons to the boardpanel
|
||||
*/
|
||||
public void applyBoardButtons() {
|
||||
for (JButton b : buttons) {
|
||||
panelLinks.add(b);
|
||||
}
|
||||
}
|
||||
|
||||
public void showWin(int player) {
|
||||
JFrame frame = new JFrame("Result");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
frame.setSize(300, 150);
|
||||
frame.setLayout(null);
|
||||
|
||||
|
|
@ -379,6 +321,66 @@ public class SpielFrame extends JFrame {
|
|||
return result[0];
|
||||
}
|
||||
|
||||
public HashMap<JButton, String> getBelegung() {
|
||||
return this.belegungen;
|
||||
}
|
||||
|
||||
public boolean isWechsel() {
|
||||
return wechsel;
|
||||
}
|
||||
|
||||
public JButton getUndo() {
|
||||
return undo;
|
||||
}
|
||||
|
||||
public JButton getUndo2() {
|
||||
return undo2;
|
||||
}
|
||||
|
||||
public BoardMode getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
public Clock getClock() {
|
||||
return clock;
|
||||
}
|
||||
|
||||
public JButton getAufgeben() {
|
||||
return aufgeben;
|
||||
}
|
||||
|
||||
public JButton getAufgeben2() {
|
||||
return aufgeben2;
|
||||
}
|
||||
|
||||
public void setMode(BoardMode mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
public void setBoardMode(BoardMode bm) {
|
||||
this.mode = bm;
|
||||
}
|
||||
|
||||
public void setSelectedSquare(Square sq) {
|
||||
this.selectedSquare = sq;
|
||||
}
|
||||
|
||||
public void setAufgeben(JButton aufgeben) {
|
||||
this.aufgeben = aufgeben;
|
||||
}
|
||||
|
||||
public void setAufgeben2(JButton aufgeben2) {
|
||||
this.aufgeben2 = aufgeben2;
|
||||
}
|
||||
|
||||
public void setWechsel(boolean wechsel) {
|
||||
this.wechsel = wechsel;
|
||||
}
|
||||
|
||||
private int mirrowedGrid(int i) {
|
||||
return 63 - (((i / 8) * 8) + (7 - i % 8));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the controlPanel and its Buttons
|
||||
*/
|
||||
|
|
@ -440,7 +442,7 @@ public class SpielFrame extends JFrame {
|
|||
pl2.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0));
|
||||
pl2.setFont(new Font("Calibri", Font.BOLD, 35));
|
||||
pl2.setForeground(Color.BLACK);
|
||||
pl2.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
pl2.setAlignmentX(CENTER_ALIGNMENT);
|
||||
playerTwo.add(pl2);
|
||||
|
||||
playerTwo.add(Box.createVerticalStrut(10));
|
||||
|
|
@ -460,7 +462,7 @@ public class SpielFrame extends JFrame {
|
|||
undo.setBackground(Color.LIGHT_GRAY);
|
||||
undo.setForeground(Color.BLACK);
|
||||
undo.setFont(new Font("Tahoma", Font.BOLD, 16));
|
||||
undo.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
undo.setAlignmentX(CENTER_ALIGNMENT);
|
||||
aufgebenUndo.add(undo);
|
||||
|
||||
// Button-Listener
|
||||
|
|
@ -473,7 +475,7 @@ public class SpielFrame extends JFrame {
|
|||
aufgeben2.setBackground(Color.LIGHT_GRAY);
|
||||
aufgeben2.setForeground(Color.BLACK);
|
||||
aufgeben2.setFont(new Font("Tahoma", Font.BOLD, 16));
|
||||
aufgeben2.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
aufgeben2.setAlignmentX(CENTER_ALIGNMENT);
|
||||
|
||||
aufgeben2.addActionListener(new ButtonAufgebenListener(this, this.game));
|
||||
aufgebenUndo.add(aufgeben2);
|
||||
|
|
@ -484,7 +486,7 @@ public class SpielFrame extends JFrame {
|
|||
safe.setBackground(Color.LIGHT_GRAY);
|
||||
safe.setForeground(Color.BLACK);
|
||||
safe.setFont(new Font("Tahoma", Font.BOLD, 16));
|
||||
safe.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
safe.setAlignmentX(CENTER_ALIGNMENT);
|
||||
aufgebenUndo.add(safe);
|
||||
|
||||
// Button-Listener
|
||||
|
|
@ -567,7 +569,7 @@ public class SpielFrame extends JFrame {
|
|||
undo2.setBackground(Color.LIGHT_GRAY);
|
||||
undo2.setForeground(Color.BLACK);
|
||||
undo2.setFont(new Font("Tahoma", Font.BOLD, 16));
|
||||
undo2.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
undo2.setAlignmentX(CENTER_ALIGNMENT);
|
||||
aufgebenUndo.add(undo2);
|
||||
|
||||
// Button-Listener
|
||||
|
|
@ -581,7 +583,7 @@ public class SpielFrame extends JFrame {
|
|||
aufgeben.setBackground(Color.LIGHT_GRAY);
|
||||
aufgeben.setForeground(Color.BLACK);
|
||||
aufgeben.setFont(new Font("Tahoma", Font.BOLD, 16));
|
||||
aufgeben.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
aufgeben.setAlignmentX(CENTER_ALIGNMENT);
|
||||
aufgeben.addActionListener(new ButtonAufgebenListener(this, this.game));
|
||||
|
||||
aufgebenUndo.add(aufgeben);
|
||||
|
|
@ -592,7 +594,7 @@ public class SpielFrame extends JFrame {
|
|||
safe.setBackground(Color.LIGHT_GRAY);
|
||||
safe.setForeground(Color.BLACK);
|
||||
safe.setFont(new Font("Tahoma", Font.BOLD, 16));
|
||||
safe.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
safe.setAlignmentX(CENTER_ALIGNMENT);
|
||||
aufgebenUndo.add(safe);
|
||||
|
||||
// Button-Listener
|
||||
|
|
@ -611,86 +613,83 @@ public class SpielFrame extends JFrame {
|
|||
pl2.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0));
|
||||
pl2.setFont(new Font("Calibri", Font.BOLD, 35));
|
||||
pl2.setForeground(Color.BLACK);
|
||||
pl2.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
pl2.setAlignmentX(CENTER_ALIGNMENT);
|
||||
playerOne.add(pl2);
|
||||
|
||||
return playerOne;
|
||||
}
|
||||
|
||||
public void setBoardMode(BoardMode bm) {
|
||||
this.mode = bm;
|
||||
}
|
||||
|
||||
public void setSelectedSquare(Square sq) {
|
||||
this.selectedSquare = sq;
|
||||
}
|
||||
|
||||
public HashMap<JButton, String> getBelegung() {
|
||||
return this.belegungen;
|
||||
}
|
||||
|
||||
public JButton getUndo() {
|
||||
return undo;
|
||||
}
|
||||
|
||||
public JButton getUndo2() {
|
||||
return undo2;
|
||||
}
|
||||
|
||||
public BoardMode getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
public Clock getClock() {
|
||||
return clock;
|
||||
}
|
||||
|
||||
public void setMode(BoardMode mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inverts the Enabled property of the controlpanelButtons
|
||||
* Sets the default background color for the buttons in the grid.
|
||||
*/
|
||||
public void enableControlPanelButtons() {
|
||||
for (Component c : this.controlPanel.getComponents()) {
|
||||
if (c instanceof JButton) {
|
||||
c.setEnabled(!c.isEnabled());
|
||||
private void setDefaultBackground() {
|
||||
int counter = 8;
|
||||
for (int i = 0; i < 64; i++) {
|
||||
JButton b = buttons.get(i);
|
||||
if ((i / 8 + i % 8) % 2 == 0) {
|
||||
// logger.info("Helles Feld erstellt." + i);
|
||||
b.setBackground(new Color(90, 90, 90));
|
||||
|
||||
} else {
|
||||
// logger.info("Dunkles Feld erstellt." + i);
|
||||
b.setBackground(new Color(65, 65, 65));
|
||||
}
|
||||
|
||||
if (i % 8 == 0) {
|
||||
b.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
b.setVerticalAlignment(SwingConstants.CENTER);
|
||||
|
||||
b.setHorizontalTextPosition(SwingConstants.LEFT); // Text rechts vom Icon
|
||||
b.setVerticalTextPosition(SwingConstants.BOTTOM);
|
||||
|
||||
b.setIconTextGap(5);
|
||||
|
||||
b.setText(String.valueOf(counter) + b.getText());
|
||||
counter--;
|
||||
}
|
||||
}
|
||||
|
||||
char buchstabe = 'a';
|
||||
for (int j = 0; j < 8; j++) {
|
||||
JButton button = buttons.get(mirrowedGrid(j));
|
||||
|
||||
button.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
button.setVerticalAlignment(SwingConstants.CENTER);
|
||||
|
||||
button.setHorizontalTextPosition(SwingConstants.RIGHT); // Text rechts vom Icon
|
||||
button.setVerticalTextPosition(SwingConstants.BOTTOM);
|
||||
|
||||
button.setIconTextGap(5);
|
||||
|
||||
button.setText(String.valueOf(buchstabe));
|
||||
buchstabe++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the buttons to the boardpanel
|
||||
* Clears the existing buttons from the button list, panellinks and fills them
|
||||
* with new blank ones.
|
||||
*/
|
||||
public void applyBoardButtons() {
|
||||
for (JButton b : buttons) {
|
||||
panelLinks.add(b);
|
||||
private void clearButtons() {
|
||||
|
||||
buttons.clear();
|
||||
panelLinks.removeAll();
|
||||
|
||||
for (int i = 0; i < 64; i++) {
|
||||
JButton b = new JButton();
|
||||
|
||||
b.setEnabled(false);
|
||||
|
||||
// style
|
||||
b.setFocusPainted(false);
|
||||
b.setFont(new Font("Arial", Font.PLAIN, 30));
|
||||
b.setForeground(Color.WHITE);
|
||||
b.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
b.setName(i + "");
|
||||
|
||||
buttons.add(b);
|
||||
}
|
||||
}
|
||||
|
||||
public JButton getAufgeben() {
|
||||
return aufgeben;
|
||||
}
|
||||
|
||||
public void setAufgeben(JButton aufgeben) {
|
||||
this.aufgeben = aufgeben;
|
||||
}
|
||||
|
||||
public JButton getAufgeben2() {
|
||||
return aufgeben2;
|
||||
}
|
||||
|
||||
public void setAufgeben2(JButton aufgeben2) {
|
||||
this.aufgeben2 = aufgeben2;
|
||||
}
|
||||
|
||||
public void setWechsel(boolean wechsel) {
|
||||
this.wechsel = wechsel;
|
||||
}
|
||||
|
||||
public boolean isWechsel() {
|
||||
return wechsel;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,157 +3,152 @@ package de.mannheim.th.chess.utl;
|
|||
/**
|
||||
* Zeigt die Zeitangabe während eines Spiels eines Spielers an.
|
||||
*/
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Font;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JSplitPane;
|
||||
import javax.swing.Timer;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import de.mannheim.th.chess.ui.SpielFrame;
|
||||
|
||||
public class Clock extends Thread implements Runnable {
|
||||
private volatile boolean whiteToMove = true;
|
||||
private volatile boolean gameHasFinished = false;
|
||||
private static final Logger clockLogger = LogManager.getLogger(Clock.class);
|
||||
private int minutes;
|
||||
private StringBuilder clockShower;
|
||||
private JLabel clock1, clock2;
|
||||
private volatile boolean whiteToMove = true;
|
||||
private volatile boolean gameHasFinished = false;
|
||||
private static final Logger clockLogger = LogManager.getLogger(Clock.class);
|
||||
private int minutes;
|
||||
private StringBuilder clockShower;
|
||||
private JLabel clock1, clock2;
|
||||
|
||||
public Clock(String mode) {
|
||||
public Clock(String mode) {
|
||||
|
||||
setMode(mode);
|
||||
}
|
||||
setMode(mode);
|
||||
}
|
||||
|
||||
public void pressClock() {
|
||||
whiteToMove = !whiteToMove;
|
||||
if (whiteToMove) {
|
||||
clockLogger.info("Weiß ist am Zug");
|
||||
} else {
|
||||
clockLogger.info("Schwarz ist am Zug");
|
||||
}
|
||||
}
|
||||
public void pressClock() {
|
||||
whiteToMove = !whiteToMove;
|
||||
if (whiteToMove) {
|
||||
clockLogger.info("Weiß ist am Zug");
|
||||
} else {
|
||||
clockLogger.info("Schwarz ist am Zug");
|
||||
}
|
||||
}
|
||||
|
||||
public void endGame() {
|
||||
gameHasFinished = true;
|
||||
}
|
||||
public void endGame() {
|
||||
gameHasFinished = true;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
// JFrame clockFrame = new JFrame("Clock");
|
||||
//
|
||||
// JPanel player1Panel = new JPanel();
|
||||
// player1Panel.setBackground(Color.BLACK);
|
||||
// JPanel player2Panel = new JPanel();
|
||||
// player2Panel.setBackground(Color.BLACK);
|
||||
// clockFrame.setBounds(1000, 500, 10000, 10000);
|
||||
// clockFrame.setLayout(new BorderLayout());
|
||||
clock1 = new JLabel("" + minutes + ":00 ");
|
||||
clock1.setBorder(BorderFactory.createEmptyBorder(0, 40, 0, 0));
|
||||
clock1.setForeground(Color.BLACK);
|
||||
clock1.setFont(new Font("Calibri", Font.BOLD, 40));
|
||||
clock1.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
public void run() {
|
||||
// JFrame clockFrame = new JFrame("Clock");
|
||||
//
|
||||
// JPanel player1Panel = new JPanel();
|
||||
// player1Panel.setBackground(Color.BLACK);
|
||||
// JPanel player2Panel = new JPanel();
|
||||
// player2Panel.setBackground(Color.BLACK);
|
||||
// clockFrame.setBounds(1000, 500, 10000, 10000);
|
||||
// clockFrame.setLayout(new BorderLayout());
|
||||
clock1 = new JLabel("" + minutes + ":00 ");
|
||||
clock1.setBorder(BorderFactory.createEmptyBorder(0, 40, 0, 0));
|
||||
clock1.setForeground(Color.BLACK);
|
||||
clock1.setFont(new Font("Calibri", Font.BOLD, 40));
|
||||
clock1.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
|
||||
clock2 = new JLabel("" + minutes + ":00 ");
|
||||
clock2.setBorder(BorderFactory.createEmptyBorder(0, 40, 0, 0));
|
||||
clock2.setForeground(Color.BLACK);
|
||||
clock2.setFont(new Font("Calibri", Font.BOLD, 40));
|
||||
clock2.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
// player1Panel.add(clock1);
|
||||
// player2Panel.add(clock2);
|
||||
// JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, player1Panel, player2Panel);
|
||||
// split.setFont(new Font("Arial", Font.BOLD, 50));
|
||||
// clockFrame.add(split);
|
||||
clock2 = new JLabel("" + minutes + ":00 ");
|
||||
clock2.setBorder(BorderFactory.createEmptyBorder(0, 40, 0, 0));
|
||||
clock2.setForeground(Color.BLACK);
|
||||
clock2.setFont(new Font("Calibri", Font.BOLD, 40));
|
||||
clock2.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
// player1Panel.add(clock1);
|
||||
// player2Panel.add(clock2);
|
||||
// JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, player1Panel,
|
||||
// player2Panel);
|
||||
// split.setFont(new Font("Arial", Font.BOLD, 50));
|
||||
// clockFrame.add(split);
|
||||
|
||||
var min1 = new AtomicInteger(minutes);
|
||||
var sec1 = new AtomicInteger(0);
|
||||
var min2 = new AtomicInteger(minutes);
|
||||
var sec2 = new AtomicInteger(0);
|
||||
var min1 = new AtomicInteger(minutes);
|
||||
var sec1 = new AtomicInteger(0);
|
||||
var min2 = new AtomicInteger(minutes);
|
||||
var sec2 = new AtomicInteger(0);
|
||||
|
||||
var t = new Timer(1000, (ae) -> {
|
||||
var t = new Timer(1000, (ae) -> {
|
||||
|
||||
if (!gameHasFinished) {
|
||||
if (!gameHasFinished) {
|
||||
|
||||
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());
|
||||
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 (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());
|
||||
}
|
||||
//sp.repaint();
|
||||
if ((sec1.intValue() == 0 && min1.intValue() == 0) || (sec2.intValue() == 0 && min2.intValue() == 0)) {
|
||||
endGame();
|
||||
}
|
||||
}
|
||||
});
|
||||
} 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());
|
||||
}
|
||||
// sp.repaint();
|
||||
if ((sec1.intValue() == 0 && min1.intValue() == 0) || (sec2.intValue() == 0 && min2.intValue() == 0)) {
|
||||
endGame();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
t.start();
|
||||
}
|
||||
t.start();
|
||||
}
|
||||
|
||||
private void setMode(String mode) {
|
||||
switch (mode.toLowerCase()) {
|
||||
case "blitz":
|
||||
minutes = 5;
|
||||
clockLogger.info("Neue Blitz-Uhr wurde erstellt");
|
||||
break;
|
||||
case "schnellschach":
|
||||
minutes = 10;
|
||||
clockLogger.info("Neue Schnellschach-Uhr wurde erstellt");
|
||||
break;
|
||||
case "klassisch":
|
||||
minutes = 120;
|
||||
clockLogger.info("Neue klassische Schachuhr wurde erstellt");
|
||||
break;
|
||||
}
|
||||
}
|
||||
private void setMode(String mode) {
|
||||
switch (mode.toLowerCase()) {
|
||||
case "blitz":
|
||||
minutes = 5;
|
||||
clockLogger.info("Neue Blitz-Uhr wurde erstellt");
|
||||
break;
|
||||
case "schnellschach":
|
||||
minutes = 10;
|
||||
clockLogger.info("Neue Schnellschach-Uhr wurde erstellt");
|
||||
break;
|
||||
case "klassisch":
|
||||
minutes = 120;
|
||||
clockLogger.info("Neue klassische Schachuhr wurde erstellt");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void switchClock() {
|
||||
whiteToMove = !whiteToMove;
|
||||
}
|
||||
public void switchClock() {
|
||||
whiteToMove = !whiteToMove;
|
||||
}
|
||||
|
||||
public JLabel getClock1() {
|
||||
public JLabel getClock1() {
|
||||
|
||||
return clock1;
|
||||
}
|
||||
return clock1;
|
||||
}
|
||||
|
||||
public JLabel getClock2() {
|
||||
public JLabel getClock2() {
|
||||
|
||||
return clock2;
|
||||
}
|
||||
return clock2;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
package de.mannheim.th.chess.utl;
|
||||
|
||||
import de.mannheim.th.chess.model.Database;
|
||||
|
||||
/**
|
||||
* Liest ein schon vordefinierten Spielstand ein.
|
||||
*/
|
||||
public class GameReader{
|
||||
|
||||
private Database database = new Database();
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue