Compare commits

..

No commits in common. "main" and "pgnReader" have entirely different histories.

24 changed files with 939 additions and 13295 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,5 +1,2 @@
JFileChoser in UI: (mit GPT) JFileChoser in UI: (mit GPT)
Prompt: "Wie kann ich in swing in java Files aus einem Explorer auswählen und speichern?". Prompt: "Wie kann ich in swing in java Files aus einem Explorer auswählen und speichern?".
JButton mit Text und Icon gleichzeitig belegen:
Pompt: "Kann ich einem button einen text und ein bild gleichzeigtig geben?".

View File

@ -1,32 +1,25 @@
package de.mannheim.th.chess; package de.mannheim.th.chess;
import java.io.IOException;
import de.mannheim.th.chess.ui.MainFrame; import de.mannheim.th.chess.ui.MainFrame;
import de.mannheim.th.chess.utl.OpeningRecognizer;
// import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
// import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
/** /**
* Eine einfache Schach App mithilfe von * Eine einfache Schach App mithilfe von {@linkplain https://github.com/bhlangonijr/chesslib} entwickelt.
* {@linkplain https://github.com/bhlangonijr/chesslib} entwickelt.
*
* @author Matias Mas Viehl, Dominik Stuck und Marius Guendel * @author Matias Mas Viehl, Dominik Stuck und Marius Guendel
* @version 0.0.1 * @version 0.0.1
*/ */
public class App { 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. * Main-Methode.
*
* @param args * @param args
* @throws IOException
*/ */
public static void main(String[] args) throws IOException { public static void main(String[] args) {
OpeningRecognizer.loadOpenings(); userinterface = new MainFrame();
new MainFrame();
} }
} }

View File

@ -5,51 +5,18 @@ import java.awt.event.ActionListener;
import javax.swing.JFrame; import javax.swing.JFrame;
import org.apache.logging.log4j.LogManager; public class ButtonAufgebenListener extends JFrame implements ActionListener{
import org.apache.logging.log4j.Logger;
import de.mannheim.th.chess.App;
import de.mannheim.th.chess.domain.Game;
import de.mannheim.th.chess.ui.SpielFrame;
import de.mannheim.th.chess.ui.SpielFrame.BoardMode;
public class ButtonAufgebenListener extends JFrame implements ActionListener {
private static final Logger logger = LogManager.getLogger(App.class);
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private SpielFrame sf;
private Game g;
public ButtonAufgebenListener(SpielFrame sf, Game g) { public ButtonAufgebenListener() {
this.sf = sf;
this.g = g;
} }
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
Object source = e.getSource();
g.stopClock();
// weil nur der aktive Spieler button drücken darf
if (source == sf.getAufgeben()) {
logger.info("Spieler 1 will aufgeben.");
sf.getAufgeben2().setEnabled(false);
sf.showResult("Spieler 2 hat gewonnen!");
} else if (source == sf.getAufgeben2()) {
logger.info("Spieler 2 will aufgeben.");
sf.getAufgeben().setEnabled(false);
sf.showResult("Spieler 1 hat gewonnen!");
}
this.sf.setBoardMode(BoardMode.finished);
this.sf.enableControlPanelButtons();
sf.setButtonsActions();
} }
} }

View File

@ -14,7 +14,7 @@ import javax.swing.JOptionPane;
import de.mannheim.th.chess.ui.ModeSelectionFrame; import de.mannheim.th.chess.ui.ModeSelectionFrame;
public class ButtonFileLoaderListener implements ActionListener { public class ButtonFileLoaderListener implements ActionListener{
private ModeSelectionFrame msf; private ModeSelectionFrame msf;
@ -40,8 +40,6 @@ public class ButtonFileLoaderListener implements ActionListener {
msf.setFen(br.readLine()); msf.setFen(br.readLine());
br.close();
} catch (FileNotFoundException e1) { } catch (FileNotFoundException e1) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e1.printStackTrace(); e1.printStackTrace();

View File

@ -6,6 +6,7 @@ import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.JFrame; import javax.swing.JFrame;
@ -13,10 +14,12 @@ import javax.swing.JFrame;
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 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;
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);

View File

@ -33,27 +33,22 @@ public class ButtonMovePieceListener implements ActionListener {
this.game.stopClock(); this.game.stopClock();
this.sf.setBoardMode(BoardMode.finished); this.sf.setBoardMode(BoardMode.finished);
this.sf.enableControlPanelButtons(); this.sf.enableControlPanelButtons();
this.sf.showResult("Unentschieden!"); this.sf.showDraw();
} else if (this.game.isMate()) { } else if (this.game.isMate()) {
this.game.stopClock(); this.game.stopClock();
this.sf.setBoardMode(BoardMode.finished); this.sf.setBoardMode(BoardMode.finished);
this.sf.enableControlPanelButtons(); this.sf.enableControlPanelButtons();
this.sf.showResult("Spieler " + game.getActivePlayer() + " hat gewonnen!"); this.sf.showWin(game.getActivePlayer());
} else { } else {
this.sf.setBoardMode(BoardMode.normal); this.sf.setBoardMode(BoardMode.normal);
if (game.getLastMove() != null) {
sf.aktualisiereAusgabe();
}
} }
this.sf.setCursor(null); this.sf.setCursor(null);
// hier rotieren markieren
if (game.isRotieren())
sf.setWechsel(!sf.isWechsel());
this.sf.erstelleBrett(); this.sf.erstelleBrett();
if (game.getLastMove() != null) {
sf.aktualisiereAusgabe();
}
} }
} }

View File

@ -3,6 +3,7 @@ package de.mannheim.th.chess.controller;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; 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;
import de.mannheim.th.chess.ui.SpielFrame.BoardMode; import de.mannheim.th.chess.ui.SpielFrame.BoardMode;

View File

@ -1,6 +1,5 @@
package de.mannheim.th.chess.domain; package de.mannheim.th.chess.domain;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -14,6 +13,7 @@ import com.github.bhlangonijr.chesslib.Side;
import com.github.bhlangonijr.chesslib.Square; import com.github.bhlangonijr.chesslib.Square;
import com.github.bhlangonijr.chesslib.move.Move; 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 de.mannheim.th.chess.App; import de.mannheim.th.chess.App;
import de.mannheim.th.chess.utl.Clock; import de.mannheim.th.chess.utl.Clock;
@ -28,10 +28,9 @@ public class Game {
private Board board; private Board board;
private Clock clock; private Clock clock;
private String modus;
private boolean rotieren, zuruecknahme; private boolean rotieren, zuruecknahme;
ArrayList<Piece> removedPieces;
private MoveList movelist; private MoveList movelist;
private int viewPointer; private int viewPointer;
@ -46,13 +45,13 @@ public class Game {
this.board = new Board(); this.board = new Board();
this.movelist = new MoveList(); this.movelist = new MoveList();
this.startPosFen = this.board.getFen(); this.startPosFen = this.board.getFen();
removedPieces = new ArrayList<>();
clock = new Clock("blitz"); clock = new Clock("blitz");
clock.start(); clock.start();
} }
public Game(String modus, boolean rotieren, boolean zuruecknahme, String fen) { public Game(String modus, boolean rotieren, boolean zuruecknahme, String fen) {
this.modus = modus;
this.rotieren = rotieren; this.rotieren = rotieren;
this.zuruecknahme = zuruecknahme; this.zuruecknahme = zuruecknahme;
@ -67,7 +66,6 @@ public class Game {
this.movelist = new MoveList(); this.movelist = new MoveList();
clock = new Clock(modus); clock = new Clock(modus);
removedPieces = new ArrayList<>();
} }
/** /**
@ -99,6 +97,10 @@ public class Game {
this.movelist = new MoveList(); this.movelist = new MoveList();
this.startPosFen = this.board.getFen(); this.startPosFen = this.board.getFen();
// this.sp = new SpielFrame();
// this.clockPlayer1 = new Clock();
// this.clockPlayer2 = new Clock();
} }
/** /**
@ -107,14 +109,6 @@ public class Game {
* @param move the move to be played * @param move the move to be played
*/ */
public void playMove(Move move) { public void playMove(Move move) {
Piece removedPiece = board.getPiece(move.getTo());
if (removedPiece != Piece.NONE) {
int removedPiecesCount = removedPieces.size();
removedPieces.add(removedPiece);
if (removedPiecesCount + 1 < removedPieces.size()) {
removedPieces.removeLast();
}
}
this.board.doMove(move); this.board.doMove(move);
this.movelist.add(move); this.movelist.add(move);
clock.pressClock(); clock.pressClock();
@ -129,11 +123,7 @@ public class Game {
public void undo() { public void undo() {
this.board.undoMove(); this.board.undoMove();
Move lastMove = this.movelist.removeLast(); this.movelist.removeLast();
Piece removedPiece = board.getPiece(lastMove.getTo());
if (removedPiece != Piece.NONE) {
removedPieces.remove(removedPiece);
}
} }
/** /**
@ -170,74 +160,16 @@ public class Game {
/** /**
* 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 which 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);
Piece removedPiece = board.getPiece(desination);
if (removedPiece != Piece.NONE) {
int removedPiecesCount = removedPieces.size();
removedPieces.add(removedPiece);
if (removedPieces.size() > removedPiecesCount + 1) {
removedPieces.removeLast();
}
}
this.board.doMove(move); this.board.doMove(move);
this.movelist.add(move); this.movelist.add(move);
clock.pressClock();
} }
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() { public boolean isMate() {
return board.isMated(); return board.isMated();
} }
@ -297,6 +229,45 @@ public class Game {
.collect(Collectors.toList()); .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() { public Clock getClock() {
return this.clock; return this.clock;
} }
@ -326,6 +297,7 @@ public class Game {
} }
public Board getBoard() { public Board getBoard() {
// TODO Auto-generated method stub
return this.board; return this.board;
} }
@ -334,6 +306,10 @@ public class Game {
return board.getFen(); return board.getFen();
} }
// public Square getSelectedSquare() {
// return this.getSelectedSquare();
// }
public String getUnicodeFromMove(Move move) { public String getUnicodeFromMove(Move move) {
return board.getPiece(move.getTo()).getFanSymbol().toUpperCase(); return board.getPiece(move.getTo()).getFanSymbol().toUpperCase();
} }
@ -346,12 +322,17 @@ public class Game {
return this.viewPointer; return this.viewPointer;
} }
public ArrayList<Piece> getRemovedPieces() { /**
return removedPieces; * 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;
} }
} }

View File

@ -0,0 +1,8 @@
package de.mannheim.th.chess.domain;
/**
* Ueberprueft, ob ein Zug gueltig ist.
*/
public class MoveChecker{
}

View File

@ -0,0 +1,8 @@
package de.mannheim.th.chess.domain;
/**
* Liest einen Zug ein.
*/
public class MoveReader{
}

View File

@ -0,0 +1,11 @@
package de.mannheim.th.chess.model;
/**
* Speichert Spielstaende, bisher gespielte Spiele und weiteres in einem File.
*/
public class Database{
public Database() {
}
}

View File

@ -0,0 +1,11 @@
package de.mannheim.th.chess.ui;
import de.mannheim.th.chess.model.Database;
/**
* ???
*/
public class Creator{
private Database database = new Database();
}

View File

@ -0,0 +1,16 @@
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() {
}
}

View File

@ -4,28 +4,28 @@ import javax.swing.JFrame;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.border.EmptyBorder; import javax.swing.border.EmptyBorder;
// 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.App; import de.mannheim.th.chess.App;
import de.mannheim.th.chess.domain.Game; import de.mannheim.th.chess.domain.Game;
import javax.swing.JLabel; import javax.swing.JLabel;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.Box; import javax.swing.Box;
import javax.swing.BoxLayout; import javax.swing.BoxLayout;
import javax.swing.JButton; import javax.swing.JButton;
import java.awt.Component;
import java.awt.Font; import java.awt.Font;
import java.awt.Color; import java.awt.Color;
public class MainFrame extends JFrame { 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 static final long serialVersionUID = 1L;
private JPanel contentPane; private JPanel contentPane;
@ -33,16 +33,14 @@ public class MainFrame extends JFrame {
/** /**
* Create the frame. * Create the frame.
* @throws IOException
*/ */
public MainFrame() { public MainFrame() {
setBackground(Color.LIGHT_GRAY); setBackground(Color.LIGHT_GRAY);
setResizable(true); setResizable(true);
setAlwaysOnTop(true); setAlwaysOnTop(true);
setTitle("Schach"); setTitle("Schach");
setDefaultCloseOperation(EXIT_ON_CLOSE); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 500, 500); setBounds(100, 100, 500, 500);
contentPane = new JPanel(); contentPane = new JPanel();
@ -59,14 +57,14 @@ public class MainFrame extends JFrame {
JLabel lblNewLabel = new JLabel("Schach"); JLabel lblNewLabel = new JLabel("Schach");
lblNewLabel.setForeground(Color.BLACK); lblNewLabel.setForeground(Color.BLACK);
lblNewLabel.setFont(new Font("Serif", Font.BOLD, 60)); lblNewLabel.setFont(new Font("Serif", Font.BOLD, 60));
lblNewLabel.setAlignmentX(CENTER_ALIGNMENT); lblNewLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
contentPane.add(lblNewLabel); contentPane.add(lblNewLabel);
contentPane.add(Box.createVerticalStrut(10)); contentPane.add(Box.createVerticalStrut(10));
JLabel lblNewLabel_1 = new JLabel("by Dominik, Marius und Matias"); JLabel lblNewLabel_1 = new JLabel("by Dominik, Marius und Matias");
lblNewLabel_1.setFont(new Font("Calibri", Font.ITALIC, 24)); lblNewLabel_1.setFont(new Font("Calibri", Font.ITALIC, 24));
lblNewLabel_1.setAlignmentX(CENTER_ALIGNMENT); lblNewLabel_1.setAlignmentX(Component.CENTER_ALIGNMENT);
contentPane.add(lblNewLabel_1); contentPane.add(lblNewLabel_1);
contentPane.add(Box.createVerticalStrut(75)); contentPane.add(Box.createVerticalStrut(75));
@ -76,7 +74,7 @@ public class MainFrame extends JFrame {
btnNewButton.setBackground(Color.LIGHT_GRAY); btnNewButton.setBackground(Color.LIGHT_GRAY);
btnNewButton.setForeground(Color.BLACK); btnNewButton.setForeground(Color.BLACK);
btnNewButton.setFont(new Font("Tahoma", Font.BOLD, 16)); btnNewButton.setFont(new Font("Tahoma", Font.BOLD, 16));
btnNewButton.setAlignmentX(CENTER_ALIGNMENT); btnNewButton.setAlignmentX(Component.CENTER_ALIGNMENT);
btnNewButton.addActionListener(new ActionListener() { btnNewButton.addActionListener(new ActionListener() {
@Override @Override
@ -90,10 +88,6 @@ public class MainFrame extends JFrame {
contentPane.add(Box.createVerticalStrut(15)); contentPane.add(Box.createVerticalStrut(15));
JButton pgnLoaderButton = new JButton("Lade aus PGN Datei"); JButton pgnLoaderButton = new JButton("Lade aus PGN Datei");
pgnLoaderButton.setBackground(Color.LIGHT_GRAY);
pgnLoaderButton.setForeground(Color.BLACK);
pgnLoaderButton.setFont(new Font("Tahoma", Font.BOLD, 16));
pgnLoaderButton.setAlignmentX(CENTER_ALIGNMENT);
pgnLoaderButton.addActionListener(e -> openPgnSelectFrame()); pgnLoaderButton.addActionListener(e -> openPgnSelectFrame());
contentPane.add(pgnLoaderButton); contentPane.add(pgnLoaderButton);
@ -104,7 +98,7 @@ public class MainFrame extends JFrame {
btnNewButton_2.setBackground(Color.LIGHT_GRAY); btnNewButton_2.setBackground(Color.LIGHT_GRAY);
btnNewButton_2.setForeground(Color.BLACK); btnNewButton_2.setForeground(Color.BLACK);
btnNewButton_2.setFont(new Font("Tahoma", Font.BOLD, 16)); btnNewButton_2.setFont(new Font("Tahoma", Font.BOLD, 16));
btnNewButton_2.setAlignmentX(CENTER_ALIGNMENT); btnNewButton_2.setAlignmentX(Component.CENTER_ALIGNMENT);
btnNewButton_2.addActionListener(new ActionListener() { btnNewButton_2.addActionListener(new ActionListener() {
@Override @Override
@ -120,12 +114,11 @@ public class MainFrame extends JFrame {
/** /**
* Starts the spielframe and game in playmode * Starts the spielframe and game in playmode
* @throws IOException
*/ */
public void startGame() { public void startGame() {
if (this.game != null) { if (this.game != null) {
//this.game.stopClock(); this.game.stopClock();
new SpielFrame(this.game); SpielFrame sf = new SpielFrame(this.game);
} }
} }

View File

@ -3,29 +3,36 @@ package de.mannheim.th.chess.ui;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; 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.*;
import javax.swing.border.EmptyBorder; import javax.swing.border.EmptyBorder;
// 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.App; import de.mannheim.th.chess.App;
import de.mannheim.th.chess.controller.ButtonFileLoaderListener; import de.mannheim.th.chess.controller.ButtonFileLoaderListener;
import de.mannheim.th.chess.domain.Game; import de.mannheim.th.chess.domain.Game;
public class ModeSelectionFrame extends JFrame { 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 static final long serialVersionUID = 1L;
private final JPanel contentPane; private final JPanel contentPane;
private final ArrayList<Game> spiele = new ArrayList<>();
private String fen; private String fen;
public ModeSelectionFrame(MainFrame mf) { public ModeSelectionFrame(MainFrame mf) {
// Frame-Eigenschaften // Frame-Eigenschaften
setTitle("Modusauswahl"); setTitle("Modusauswahl");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setBounds(100, 100, 600, 600); setBounds(100, 100, 500, 500);
setResizable(true); setResizable(true);
setAlwaysOnTop(true); setAlwaysOnTop(true);
@ -40,7 +47,7 @@ public class ModeSelectionFrame extends JFrame {
JLabel jl = new JLabel("Welchen Modus wollen Sie spielen?"); JLabel jl = new JLabel("Welchen Modus wollen Sie spielen?");
jl.setFont(new Font("Calibri", Font.BOLD, 20)); jl.setFont(new Font("Calibri", Font.BOLD, 20));
jl.setForeground(Color.BLACK); jl.setForeground(Color.BLACK);
jl.setAlignmentX(CENTER_ALIGNMENT); jl.setAlignmentX(Component.CENTER_ALIGNMENT);
contentPane.add(jl); contentPane.add(jl);
contentPane.add(Box.createVerticalStrut(15)); contentPane.add(Box.createVerticalStrut(15));
@ -48,7 +55,7 @@ public class ModeSelectionFrame extends JFrame {
String[] modi = { "Blitz", "Schnellschach", "Klassisch" }; String[] modi = { "Blitz", "Schnellschach", "Klassisch" };
JComboBox<String> jcb1 = new JComboBox<>(modi); JComboBox<String> jcb1 = new JComboBox<>(modi);
jcb1.setMaximumSize(new Dimension(150, 30)); jcb1.setMaximumSize(new Dimension(150, 30));
jcb1.setAlignmentX(CENTER_ALIGNMENT); jcb1.setAlignmentX(Component.CENTER_ALIGNMENT);
contentPane.add(jcb1); contentPane.add(jcb1);
contentPane.add(Box.createVerticalStrut(15)); contentPane.add(Box.createVerticalStrut(15));
@ -56,14 +63,14 @@ public class ModeSelectionFrame extends JFrame {
JLabel jl2 = new JLabel("Soll das Spielbrett nach jedem Zug gedreht werden?"); JLabel jl2 = new JLabel("Soll das Spielbrett nach jedem Zug gedreht werden?");
jl2.setFont(new Font("Calibri", Font.BOLD, 20)); jl2.setFont(new Font("Calibri", Font.BOLD, 20));
jl2.setForeground(Color.BLACK); jl2.setForeground(Color.BLACK);
jl2.setAlignmentX(CENTER_ALIGNMENT); jl2.setAlignmentX(Component.CENTER_ALIGNMENT);
contentPane.add(jl2); contentPane.add(jl2);
JCheckBox jb1 = new JCheckBox(); JCheckBox jb1 = new JCheckBox();
jb1.setOpaque(false); jb1.setOpaque(false);
jb1.setFocusPainted(false); jb1.setFocusPainted(false);
jb1.setForeground(Color.BLACK); jb1.setForeground(Color.BLACK);
jb1.setAlignmentX(CENTER_ALIGNMENT); jb1.setAlignmentX(Component.CENTER_ALIGNMENT);
jb1.setMaximumSize(new Dimension(30, 30)); jb1.setMaximumSize(new Dimension(30, 30));
contentPane.add(jb1); contentPane.add(jb1);
contentPane.add(Box.createVerticalStrut(15)); contentPane.add(Box.createVerticalStrut(15));
@ -72,14 +79,14 @@ public class ModeSelectionFrame extends JFrame {
JLabel jl3 = new JLabel("Sollen Zurücknahmen erlaubt sein?"); JLabel jl3 = new JLabel("Sollen Zurücknahmen erlaubt sein?");
jl3.setFont(new Font("Calibri", Font.BOLD, 20)); jl3.setFont(new Font("Calibri", Font.BOLD, 20));
jl3.setForeground(Color.BLACK); jl3.setForeground(Color.BLACK);
jl3.setAlignmentX(CENTER_ALIGNMENT); jl3.setAlignmentX(Component.CENTER_ALIGNMENT);
contentPane.add(jl3); contentPane.add(jl3);
JCheckBox jb2 = new JCheckBox(); JCheckBox jb2 = new JCheckBox();
jb2.setOpaque(false); jb2.setOpaque(false);
jb2.setFocusPainted(false); jb2.setFocusPainted(false);
jb2.setForeground(Color.BLACK); jb2.setForeground(Color.BLACK);
jb2.setAlignmentX(CENTER_ALIGNMENT); jb2.setAlignmentX(Component.CENTER_ALIGNMENT);
jb2.setMaximumSize(new Dimension(30, 30)); jb2.setMaximumSize(new Dimension(30, 30));
contentPane.add(jb2); contentPane.add(jb2);
@ -90,7 +97,7 @@ public class ModeSelectionFrame extends JFrame {
btnNewButton_1.setBackground(Color.LIGHT_GRAY); btnNewButton_1.setBackground(Color.LIGHT_GRAY);
btnNewButton_1.setForeground(Color.BLACK); btnNewButton_1.setForeground(Color.BLACK);
btnNewButton_1.setFont(new Font("Tahoma", Font.BOLD, 16)); btnNewButton_1.setFont(new Font("Tahoma", Font.BOLD, 16));
btnNewButton_1.setAlignmentX(CENTER_ALIGNMENT); btnNewButton_1.setAlignmentX(Component.CENTER_ALIGNMENT);
btnNewButton_1.addActionListener(new ButtonFileLoaderListener(this)); btnNewButton_1.addActionListener(new ButtonFileLoaderListener(this));
contentPane.add(btnNewButton_1); contentPane.add(btnNewButton_1);
@ -102,7 +109,7 @@ public class ModeSelectionFrame extends JFrame {
btnNewButton.setBackground(Color.LIGHT_GRAY); btnNewButton.setBackground(Color.LIGHT_GRAY);
btnNewButton.setForeground(Color.BLACK); btnNewButton.setForeground(Color.BLACK);
btnNewButton.setFont(new Font("Tahoma", Font.BOLD, 16)); btnNewButton.setFont(new Font("Tahoma", Font.BOLD, 16));
btnNewButton.setAlignmentX(CENTER_ALIGNMENT); btnNewButton.setAlignmentX(Component.CENTER_ALIGNMENT);
contentPane.add(btnNewButton); contentPane.add(btnNewButton);
// Button-Listener // Button-Listener

View File

@ -1,6 +1,8 @@
package de.mannheim.th.chess.ui; package de.mannheim.th.chess.ui;
import java.util.List; import java.util.List;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File; import java.io.File;
import javax.swing.BoxLayout; import javax.swing.BoxLayout;

File diff suppressed because it is too large Load Diff

View File

@ -3,18 +3,24 @@ package de.mannheim.th.chess.utl;
/** /**
* Zeigt die Zeitangabe während eines Spiels eines Spielers an. * Zeigt die Zeitangabe während eines Spiels eines Spielers an.
*/ */
import java.awt.BorderLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Font; import java.awt.Font;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.Timer; 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;
@ -42,14 +48,14 @@ public class Clock extends Thread implements Runnable {
} }
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());
clock1 = new JLabel("" + minutes + ":00 "); clock1 = new JLabel("" + minutes + ":00 ");
clock1.setBorder(BorderFactory.createEmptyBorder(0, 40, 0, 0)); clock1.setBorder(BorderFactory.createEmptyBorder(0, 40, 0, 0));
clock1.setForeground(Color.BLACK); clock1.setForeground(Color.BLACK);
@ -61,12 +67,11 @@ public class Clock extends Thread implements Runnable {
clock2.setForeground(Color.BLACK); clock2.setForeground(Color.BLACK);
clock2.setFont(new Font("Calibri", Font.BOLD, 40)); clock2.setFont(new Font("Calibri", Font.BOLD, 40));
clock2.setAlignmentX(Component.CENTER_ALIGNMENT); clock2.setAlignmentX(Component.CENTER_ALIGNMENT);
// player1Panel.add(clock1); // player1Panel.add(clock1);
// player2Panel.add(clock2); // player2Panel.add(clock2);
// JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, player1Panel, // JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, player1Panel, player2Panel);
// 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);
@ -110,7 +115,7 @@ public class Clock extends Thread implements Runnable {
clockShower.append(sec2.decrementAndGet()); clockShower.append(sec2.decrementAndGet());
clock2.setText(clockShower.toString()); clock2.setText(clockShower.toString());
} }
// sp.repaint(); //sp.repaint();
if ((sec1.intValue() == 0 && min1.intValue() == 0) || (sec2.intValue() == 0 && min2.intValue() == 0)) { if ((sec1.intValue() == 0 && min1.intValue() == 0) || (sec2.intValue() == 0 && min2.intValue() == 0)) {
endGame(); endGame();
} }

View File

@ -0,0 +1,12 @@
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();
}

View File

@ -1,64 +0,0 @@
package de.mannheim.th.chess.utl;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.github.bhlangonijr.chesslib.move.MoveList;
public class OpeningRecognizer {
private static class Opening {
String name;
String moves;
Opening(String name, String moves) {
this.name = name;
this.moves = moves;
}
}
private static List<Opening> openingList = new ArrayList<>();
public static void loadOpenings() throws IOException {
BufferedReader openingReader = new BufferedReader(new FileReader("src/main/resources/openings.pgn"));
StringBuilder openingName = new StringBuilder();
String moves = null;
String line;
while ((line = openingReader.readLine()) != null) {
if ((line.startsWith("[Site") && openingName.toString().equals("")) || line.equals("") ) {
continue;
}
if (line.startsWith("[Site")) {
openingList.add(new Opening(openingName.toString(), moves));
moves = null;
openingName.delete(0, openingName.length());
continue;
}
if (line.startsWith("[White")) {
openingName.append(line.split("\"")[1].trim());
continue;
}
if (line.startsWith("[Black")) {
openingName.append(":").append(line.split("\"")[1].trim());
continue;
}
moves = line;
}
openingReader.close();
}
public static String compareOpening(MoveList moves, String openingBefore) {
for (Opening o: openingList) {
if (o.moves.equals(moves.toSanWithMoveNumbers().trim())) {
return o.name;
}
}
return openingBefore;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,32 +0,0 @@
package de.mannheim.th.chess.utl;
import static org.junit.jupiter.api.Assertions.*;
import java.io.IOException;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import com.github.bhlangonijr.chesslib.Square;
import com.github.bhlangonijr.chesslib.move.Move;
import com.github.bhlangonijr.chesslib.move.MoveList;
class OpeningRecognizerTest {
@BeforeAll
static void prepareOpenings() throws IOException {
OpeningRecognizer.loadOpenings();
}
@Test
void test() {
Move m = new Move(Square.E2, Square.E4);
MoveList moves = new MoveList();
moves.add(m);
assertEquals(OpeningRecognizer.compareOpening(moves, "Unknown"), "King's pawn Opening");
}
}