Compare commits
No commits in common. "main" and "gamelogic" have entirely different histories.
17
.classpath
|
|
@ -36,22 +36,5 @@
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="src" path="target/generated-sources/annotations">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="optional" value="true"/>
|
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
|
||||||
<attribute name="ignore_optional_problems" value="true"/>
|
|
||||||
<attribute name="m2e-apt" value="true"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="optional" value="true"/>
|
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
|
||||||
<attribute name="ignore_optional_problems" value="true"/>
|
|
||||||
<attribute name="m2e-apt" value="true"/>
|
|
||||||
<attribute name="test" value="true"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
||||||
13
.project
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<projectDescription>
|
<projectDescription>
|
||||||
<name>SchachMVN</name>
|
<name>Schach</name>
|
||||||
<comment></comment>
|
<comment></comment>
|
||||||
<projects>
|
<projects>
|
||||||
</projects>
|
</projects>
|
||||||
|
|
@ -20,15 +20,4 @@
|
||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||||
</natures>
|
</natures>
|
||||||
<filteredResources>
|
|
||||||
<filter>
|
|
||||||
<id>1750157105125</id>
|
|
||||||
<name></name>
|
|
||||||
<type>30</type>
|
|
||||||
<matcher>
|
|
||||||
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
|
||||||
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
|
||||||
</matcher>
|
|
||||||
</filter>
|
|
||||||
</filteredResources>
|
|
||||||
</projectDescription>
|
</projectDescription>
|
||||||
|
|
|
||||||
5
quellen
|
|
@ -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?".
|
||||||
|
|
||||||
JButton mit Text und Icon gleichzeitig belegen:
|
|
||||||
Pompt: "Kann ich einem button einen text und ein bild gleichzeigtig geben?".
|
|
||||||
33
scrum
|
|
@ -11,37 +11,4 @@ Was werden wir diese Woche machen:
|
||||||
|
|
||||||
Ziel: stehende Grundstruktur mit möglicher Ausführungsmöglichkeit (kleiner Prototyp wie ein einfaches Schachbrett)
|
Ziel: stehende Grundstruktur mit möglicher Ausführungsmöglichkeit (kleiner Prototyp wie ein einfaches Schachbrett)
|
||||||
|
|
||||||
---
|
|
||||||
Scrum von 11.06.25
|
|
||||||
|
|
||||||
Was haben wir bisher gemacht:
|
|
||||||
- Schachbrett mit Figuren / Curser anzeige angelegt
|
|
||||||
- simple clock mit ui
|
|
||||||
- einfach SPiellogikschnittstelle
|
|
||||||
|
|
||||||
|
|
||||||
Was werden wir diese Woche machen:
|
|
||||||
- Bewegbare Schachfiguren
|
|
||||||
- Anzeige welche Züge möglich sind
|
|
||||||
- Clock einfügen
|
|
||||||
- Spieleinlese planen
|
|
||||||
|
|
||||||
Ziel: Singleplayer Spielbarer Zustand
|
|
||||||
|
|
||||||
|
|
||||||
---
|
|
||||||
Scrum von 17.06.25
|
|
||||||
|
|
||||||
Was haben wir bisher gemacht:
|
|
||||||
- legal moves anzeige auf gui
|
|
||||||
- clock ist funktionsfähig
|
|
||||||
|
|
||||||
|
|
||||||
Was werden wir diese Woche machen:
|
|
||||||
- ziehbare spielfiguren | ui refactor / Dominik
|
|
||||||
- win conditions | promotion / Marius
|
|
||||||
- spiel ui statistic ausgaben | history / Matias
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Ziel: Singleplayer Spielbarer Zustand + statistic Anzeige
|
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,20 @@
|
||||||
package de.mannheim.th.chess;
|
package de.mannheim.th.chess;
|
||||||
|
|
||||||
import java.io.IOException;
|
import de.mannheim.th.chess.ui.Ui;
|
||||||
|
|
||||||
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.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 Ui userinterface = new Ui();
|
||||||
|
/**
|
||||||
/**
|
* Main-Methode.
|
||||||
* Main-Methode.
|
* @param args
|
||||||
*
|
*/
|
||||||
* @param args
|
public static void main(String[] args) {
|
||||||
* @throws IOException
|
System.out.println("Hello World!");
|
||||||
*/
|
}
|
||||||
public static void main(String[] args) throws IOException {
|
|
||||||
OpeningRecognizer.loadOpenings();
|
|
||||||
new MainFrame();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,55 +0,0 @@
|
||||||
package de.mannheim.th.chess.controller;
|
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
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 SpielFrame sf;
|
|
||||||
private Game g;
|
|
||||||
|
|
||||||
public ButtonAufgebenListener(SpielFrame sf, Game g) {
|
|
||||||
this.sf = sf;
|
|
||||||
this.g = g;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
// 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();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,56 +0,0 @@
|
||||||
package de.mannheim.th.chess.controller;
|
|
||||||
|
|
||||||
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 javax.swing.JFileChooser;
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
|
|
||||||
import de.mannheim.th.chess.ui.ModeSelectionFrame;
|
|
||||||
|
|
||||||
public class ButtonFileLoaderListener implements ActionListener {
|
|
||||||
|
|
||||||
private ModeSelectionFrame msf;
|
|
||||||
|
|
||||||
public ButtonFileLoaderListener(ModeSelectionFrame msf) {
|
|
||||||
this.msf = msf;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
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());
|
|
||||||
|
|
||||||
try {
|
|
||||||
BufferedReader br = new BufferedReader(new FileReader(ausgewaehlteDatei));
|
|
||||||
|
|
||||||
msf.setFen(br.readLine());
|
|
||||||
|
|
||||||
br.close();
|
|
||||||
|
|
||||||
} catch (FileNotFoundException e1) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e1.printStackTrace();
|
|
||||||
} catch (IOException e1) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,58 +0,0 @@
|
||||||
package de.mannheim.th.chess.controller;
|
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import javax.swing.JFileChooser;
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
import de.mannheim.th.chess.App;
|
|
||||||
import de.mannheim.th.chess.domain.Game;
|
|
||||||
|
|
||||||
public class ButtonFileSaverListener implements ActionListener {
|
|
||||||
|
|
||||||
private static final Logger logger = LogManager.getLogger(App.class);
|
|
||||||
|
|
||||||
private Game g;
|
|
||||||
private JFrame sf;
|
|
||||||
|
|
||||||
public ButtonFileSaverListener(JFrame sf, Game g) {
|
|
||||||
this.sf = sf;
|
|
||||||
this.g = g;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
|
|
||||||
logger.info("Spiel wird gespeichert.");
|
|
||||||
|
|
||||||
JFileChooser chooser = new JFileChooser();
|
|
||||||
chooser.setCurrentDirectory(new File(System.getProperty("user.home") + "/Documents"));
|
|
||||||
|
|
||||||
chooser.setDialogTitle("Datei speichern");
|
|
||||||
int userSelection = chooser.showSaveDialog(sf);
|
|
||||||
|
|
||||||
if (userSelection == JFileChooser.APPROVE_OPTION) {
|
|
||||||
File fileToSave = chooser.getSelectedFile();
|
|
||||||
|
|
||||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(fileToSave))) {
|
|
||||||
|
|
||||||
writer.write(g.getFen());
|
|
||||||
|
|
||||||
logger.info(g.getFen());
|
|
||||||
} catch (IOException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
logger.info("Speichern fehlgeschlagen.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,59 +0,0 @@
|
||||||
package de.mannheim.th.chess.controller;
|
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
import com.github.bhlangonijr.chesslib.move.Move;
|
|
||||||
|
|
||||||
import de.mannheim.th.chess.domain.Game;
|
|
||||||
import de.mannheim.th.chess.ui.SpielFrame;
|
|
||||||
import de.mannheim.th.chess.ui.SpielFrame.BoardMode;
|
|
||||||
|
|
||||||
public class ButtonMovePieceListener implements ActionListener {
|
|
||||||
private SpielFrame sf;
|
|
||||||
private Game game;
|
|
||||||
private Move mv;
|
|
||||||
|
|
||||||
public ButtonMovePieceListener(SpielFrame sf, Game game, Move mv) {
|
|
||||||
this.sf = sf;
|
|
||||||
this.game = game;
|
|
||||||
this.mv = mv;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
if (game.isPromotionMove(this.mv))
|
|
||||||
game.doPromotionMove(this.sf.showPromotion(), mv.getFrom(), mv.getTo());
|
|
||||||
else
|
|
||||||
this.game.playMove(this.mv);
|
|
||||||
|
|
||||||
this.game.setViewPointer(this.game.getMoveList().size() - 1);
|
|
||||||
|
|
||||||
if (this.game.isDraw()) {
|
|
||||||
this.game.stopClock();
|
|
||||||
this.sf.setBoardMode(BoardMode.finished);
|
|
||||||
this.sf.enableControlPanelButtons();
|
|
||||||
this.sf.showResult("Unentschieden!");
|
|
||||||
} else if (this.game.isMate()) {
|
|
||||||
this.game.stopClock();
|
|
||||||
this.sf.setBoardMode(BoardMode.finished);
|
|
||||||
this.sf.enableControlPanelButtons();
|
|
||||||
this.sf.showResult("Spieler " + game.getActivePlayer() + " hat gewonnen!");
|
|
||||||
} else {
|
|
||||||
this.sf.setBoardMode(BoardMode.normal);
|
|
||||||
if (game.getLastMove() != null) {
|
|
||||||
sf.aktualisiereAusgabe();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.sf.setCursor(null);
|
|
||||||
|
|
||||||
// hier rotieren markieren
|
|
||||||
|
|
||||||
if (game.isRotieren())
|
|
||||||
sf.setWechsel(!sf.isWechsel());
|
|
||||||
|
|
||||||
this.sf.erstelleBrett();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
package de.mannheim.th.chess.controller;
|
|
||||||
|
|
||||||
import java.awt.Cursor;
|
|
||||||
import java.awt.Image;
|
|
||||||
import java.awt.Point;
|
|
||||||
import java.awt.Toolkit;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
import com.github.bhlangonijr.chesslib.Square;
|
|
||||||
|
|
||||||
import de.mannheim.th.chess.ui.SpielFrame;
|
|
||||||
|
|
||||||
public class ButtonSelectPieceListener implements ActionListener {
|
|
||||||
private SpielFrame sf;
|
|
||||||
private Square selectedSquare;
|
|
||||||
|
|
||||||
public ButtonSelectPieceListener(SpielFrame sf, Square sq) {
|
|
||||||
this.sf = sf;
|
|
||||||
this.selectedSquare = sq;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
sf.setBoardMode(SpielFrame.BoardMode.pieceSelected);
|
|
||||||
sf.setSelectedSquare(this.selectedSquare);
|
|
||||||
|
|
||||||
String symbolChoosed = sf.getBelegung().get(e.getSource());
|
|
||||||
|
|
||||||
// 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");
|
|
||||||
sf.setCursor(figurCursor);
|
|
||||||
|
|
||||||
sf.erstelleBrett();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
package de.mannheim.th.chess.controller;
|
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
import de.mannheim.th.chess.ui.SpielFrame;
|
|
||||||
import de.mannheim.th.chess.ui.SpielFrame.BoardMode;
|
|
||||||
|
|
||||||
public class ButtonToNormalListener implements ActionListener {
|
|
||||||
private SpielFrame sf;
|
|
||||||
|
|
||||||
public ButtonToNormalListener(SpielFrame sf) {
|
|
||||||
this.sf = sf;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
this.sf.setBoardMode(BoardMode.normal);
|
|
||||||
this.sf.setSelectedSquare(null);
|
|
||||||
this.sf.setCursor(null);
|
|
||||||
this.sf.erstelleBrett();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,70 +0,0 @@
|
||||||
package de.mannheim.th.chess.controller;
|
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
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 ButtonUndoMoveListener implements ActionListener {
|
|
||||||
|
|
||||||
private static final Logger logger = LogManager.getLogger(App.class);
|
|
||||||
|
|
||||||
private SpielFrame sf;
|
|
||||||
private Game game;
|
|
||||||
|
|
||||||
public ButtonUndoMoveListener(SpielFrame sf, Game game) {
|
|
||||||
this.sf = sf;
|
|
||||||
this.game = game;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
Object source = e.getSource();
|
|
||||||
|
|
||||||
if (sf.getMode() != BoardMode.normal || !game.movesNotNull()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (source == sf.getUndo()) { // Spieler 2 drückt seinen Button
|
|
||||||
if (sf.getUndo().getText().equals("Zug zurücknehmen") && game.getActivePlayer() == 1) {
|
|
||||||
sf.getUndo2().setText("Zurücknahme genehmigen?");
|
|
||||||
sf.getUndo2().setEnabled(true);
|
|
||||||
logger.info("Spieler 2 hat zurücknahme angefordert.");
|
|
||||||
} else if (sf.getUndo().getText().equals("Zurücknahme genehmigen?")) {
|
|
||||||
logger.info("Zug zurücknehmen wurde von Spieler 2 genehmigt.");
|
|
||||||
sf.getUndo().setText("Zug zurücknehmen");
|
|
||||||
sf.getUndo2().setText("Zug zurücknehmen");
|
|
||||||
sf.getUndo2().setEnabled(false);
|
|
||||||
game.undo();
|
|
||||||
sf.getClock().switchClock();
|
|
||||||
sf.deleteLastAusgabe();
|
|
||||||
sf.erstelleBrett();
|
|
||||||
}
|
|
||||||
} else if (source == sf.getUndo2()) { // Spieler 1 drückt seinen Button
|
|
||||||
if (sf.getUndo2().getText().equals("Zug zurücknehmen") && game.getActivePlayer() == 2) {
|
|
||||||
sf.getUndo().setText("Zurücknahme genehmigen?");
|
|
||||||
sf.getUndo().setEnabled(true);
|
|
||||||
logger.info("Spieler 1 hat zurücknahme angefordert.");
|
|
||||||
} else if (sf.getUndo2().getText().equals("Zurücknahme genehmigen?")) {
|
|
||||||
logger.info("Zug zurücknehmen wurde von Spieler 1 genehmigt.");
|
|
||||||
sf.getUndo2().setText("Zug zurücknehmen");
|
|
||||||
sf.getUndo().setText("Zug zurücknehmen");
|
|
||||||
sf.getUndo().setEnabled(false);
|
|
||||||
game.undo();
|
|
||||||
sf.getClock().switchClock();
|
|
||||||
sf.deleteLastAusgabe();
|
|
||||||
sf.erstelleBrett();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
package de.mannheim.th.chess.controller.controlPanel;
|
|
||||||
|
|
||||||
import de.mannheim.th.chess.ui.SpielFrame;
|
|
||||||
import de.mannheim.th.chess.domain.Game;
|
|
||||||
|
|
||||||
public abstract class BaseButtonViewListener {
|
|
||||||
protected SpielFrame sf;
|
|
||||||
protected Game game;
|
|
||||||
|
|
||||||
public BaseButtonViewListener(Game game, SpielFrame sf) {
|
|
||||||
this.sf = sf;
|
|
||||||
this.game = game;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads the gamestate and renders the board
|
|
||||||
*/
|
|
||||||
protected void updateView() {
|
|
||||||
this.game.loadView();
|
|
||||||
this.sf.setDefaultButtons();
|
|
||||||
this.sf.applyBoardButtons();
|
|
||||||
this.sf.ladeBrett();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
package de.mannheim.th.chess.controller.controlPanel;
|
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
import de.mannheim.th.chess.domain.Game;
|
|
||||||
import de.mannheim.th.chess.ui.SpielFrame;
|
|
||||||
|
|
||||||
public class ButtonQuickloadListener implements ActionListener {
|
|
||||||
private Game game;
|
|
||||||
private SpielFrame sf;
|
|
||||||
|
|
||||||
public ButtonQuickloadListener(Game game, SpielFrame sf) {
|
|
||||||
this.game = game;
|
|
||||||
this.sf = sf;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
this.game.quickload();
|
|
||||||
this.sf.erstelleBrett();
|
|
||||||
this.sf.aktualisiereAusgabe();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
package de.mannheim.th.chess.controller.controlPanel;
|
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
import de.mannheim.th.chess.domain.Game;
|
|
||||||
|
|
||||||
public class ButtonQuicksaveListener implements ActionListener {
|
|
||||||
private Game game;
|
|
||||||
|
|
||||||
public ButtonQuicksaveListener(Game game) {
|
|
||||||
this.game = game;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
this.game.quicksave();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
package de.mannheim.th.chess.controller.controlPanel;
|
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
import de.mannheim.th.chess.domain.Game;
|
|
||||||
import de.mannheim.th.chess.ui.SpielFrame;
|
|
||||||
|
|
||||||
public class ButtonViewBackListener extends BaseButtonViewListener implements ActionListener {
|
|
||||||
|
|
||||||
public ButtonViewBackListener(Game game, SpielFrame sf) {
|
|
||||||
super(game, sf);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
if (this.game.getViewPointer() > 0) {
|
|
||||||
this.game.setViewPointer(this.game.getViewPointer() - 1);
|
|
||||||
updateView();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
package de.mannheim.th.chess.controller.controlPanel;
|
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
import de.mannheim.th.chess.domain.Game;
|
|
||||||
import de.mannheim.th.chess.ui.SpielFrame;
|
|
||||||
|
|
||||||
public class ButtonViewFirstListener extends BaseButtonViewListener implements ActionListener {
|
|
||||||
|
|
||||||
public ButtonViewFirstListener(Game game, SpielFrame sf) {
|
|
||||||
super(game, sf);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
this.game.setViewPointer(0);
|
|
||||||
updateView();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
package de.mannheim.th.chess.controller.controlPanel;
|
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
import de.mannheim.th.chess.domain.Game;
|
|
||||||
import de.mannheim.th.chess.ui.SpielFrame;
|
|
||||||
|
|
||||||
public class ButtonViewForwardListener extends BaseButtonViewListener implements ActionListener {
|
|
||||||
|
|
||||||
public ButtonViewForwardListener(Game game, SpielFrame sf) {
|
|
||||||
super(game, sf);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
if (this.game.getMoveList().size() > this.game.getViewPointer()) {
|
|
||||||
this.game.setViewPointer(this.game.getViewPointer() + 1);
|
|
||||||
updateView();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
|
|
||||||
package de.mannheim.th.chess.controller.controlPanel;
|
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
import de.mannheim.th.chess.domain.Game;
|
|
||||||
import de.mannheim.th.chess.ui.SpielFrame;
|
|
||||||
|
|
||||||
public class ButtonViewLastListener extends BaseButtonViewListener implements ActionListener {
|
|
||||||
|
|
||||||
public ButtonViewLastListener(Game game, SpielFrame sf) {
|
|
||||||
super(game, sf);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
this.game.setViewPointer(this.game.getMoveList().size());
|
|
||||||
updateView();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,21 +1,13 @@
|
||||||
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;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
import com.github.bhlangonijr.chesslib.Board;
|
import com.github.bhlangonijr.chesslib.Board;
|
||||||
import com.github.bhlangonijr.chesslib.Piece;
|
|
||||||
import com.github.bhlangonijr.chesslib.Rank;
|
|
||||||
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 de.mannheim.th.chess.App;
|
|
||||||
import de.mannheim.th.chess.utl.Clock;
|
import de.mannheim.th.chess.utl.Clock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -24,50 +16,23 @@ import de.mannheim.th.chess.utl.Clock;
|
||||||
*/
|
*/
|
||||||
public class Game {
|
public class Game {
|
||||||
|
|
||||||
private static final Logger logger = LogManager.getLogger(App.class);
|
|
||||||
|
|
||||||
private Board board;
|
private Board board;
|
||||||
private Clock clock;
|
private Clock clockPlayer1;
|
||||||
private boolean rotieren, zuruecknahme;
|
private Clock clockPlayer2;
|
||||||
|
|
||||||
ArrayList<Piece> removedPieces;
|
|
||||||
|
|
||||||
private MoveList movelist;
|
private MoveList movelist;
|
||||||
private int viewPointer;
|
|
||||||
|
|
||||||
private MoveList savestate;
|
|
||||||
private String startPosFen;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Conststructs a new standard GameBoard.
|
* Conststructs a new standard GameBoard.
|
||||||
*/
|
*/
|
||||||
public Game() {
|
public Game() {
|
||||||
|
|
||||||
this.board = new Board();
|
|
||||||
this.movelist = new MoveList();
|
|
||||||
this.startPosFen = this.board.getFen();
|
|
||||||
removedPieces = new ArrayList<>();
|
|
||||||
|
|
||||||
clock = new Clock("blitz");
|
|
||||||
clock.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Game(String modus, boolean rotieren, boolean zuruecknahme, String fen) {
|
|
||||||
this.rotieren = rotieren;
|
|
||||||
this.zuruecknahme = zuruecknahme;
|
|
||||||
|
|
||||||
this.board = new Board();
|
this.board = new Board();
|
||||||
|
|
||||||
if (fen == null)
|
|
||||||
fen = board.getFen();
|
|
||||||
|
|
||||||
this.board.loadFromFen(fen);
|
|
||||||
|
|
||||||
this.startPosFen = this.board.getFen();
|
|
||||||
this.movelist = new MoveList();
|
this.movelist = new MoveList();
|
||||||
|
|
||||||
clock = new Clock(modus);
|
this.clockPlayer1 = new Clock();
|
||||||
removedPieces = new ArrayList<>();
|
this.clockPlayer2 = new Clock();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -78,14 +43,14 @@ public class Game {
|
||||||
public Game(MoveList movelist) {
|
public Game(MoveList movelist) {
|
||||||
this.board = new Board();
|
this.board = new Board();
|
||||||
|
|
||||||
this.startPosFen = this.board.getFen();
|
|
||||||
this.movelist = movelist;
|
this.movelist = movelist;
|
||||||
|
|
||||||
for (Move move : movelist) {
|
for (Move move : movelist) {
|
||||||
this.board.doMove(move);
|
this.board.doMove(move);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.clock = new Clock("blitz");
|
this.clockPlayer1 = new Clock();
|
||||||
|
this.clockPlayer2 = new Clock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -98,7 +63,9 @@ public class Game {
|
||||||
this.board.loadFromFen(fen);
|
this.board.loadFromFen(fen);
|
||||||
|
|
||||||
this.movelist = new MoveList();
|
this.movelist = new MoveList();
|
||||||
this.startPosFen = this.board.getFen();
|
|
||||||
|
this.clockPlayer1 = new Clock();
|
||||||
|
this.clockPlayer2 = new Clock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -107,17 +74,8 @@ 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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -126,131 +84,10 @@ public class Game {
|
||||||
* @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 undo() {
|
|
||||||
this.board.undoMove();
|
|
||||||
Move lastMove = this.movelist.removeLast();
|
|
||||||
Piece removedPiece = board.getPiece(lastMove.getTo());
|
|
||||||
if (removedPiece != Piece.NONE) {
|
|
||||||
removedPieces.remove(removedPiece);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copies the current move list to the savestate
|
|
||||||
*/
|
|
||||||
public void quicksave() {
|
|
||||||
// TODO: save the current clocktime
|
|
||||||
this.savestate = new MoveList(this.movelist);
|
|
||||||
|
|
||||||
logger.info("Quicksaved...");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads the save state
|
|
||||||
*
|
|
||||||
* @brief creates a new board with the startPosFen and then plays all the moves
|
|
||||||
* from the savestate
|
|
||||||
*/
|
|
||||||
public void quickload() {
|
|
||||||
if (this.savestate != null) {
|
|
||||||
|
|
||||||
this.board = new Board();
|
|
||||||
this.movelist.clear();
|
|
||||||
this.board.loadFromFen(startPosFen);
|
|
||||||
|
|
||||||
for (Move move : savestate) {
|
|
||||||
this.playMove(move);
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Quickloaded...");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Plays the move on the board and adds it to the movelist
|
|
||||||
*
|
|
||||||
* @param origin The square from which it moves from.
|
|
||||||
* @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() {
|
|
||||||
return board.isMated();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDraw() {
|
|
||||||
return board.isDraw();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getActivePlayer() {
|
|
||||||
if (board.getSideToMove() == Side.WHITE) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -261,97 +98,9 @@ public class Game {
|
||||||
* @return A list of legal moves that originate from the specified square.
|
* @return A list of legal moves that originate from the specified square.
|
||||||
*/
|
*/
|
||||||
public List<Move> getLegalMoves(Square 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPromotionMove(Move move) {
|
|
||||||
return ((move.getTo().getRank().equals(Rank.RANK_8) || move.getTo().getRank().equals(Rank.RANK_1)) &&
|
|
||||||
(board.getPiece(move.getFrom()) == Piece.BLACK_PAWN || board.getPiece(move.getFrom()) == Piece.WHITE_PAWN));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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()
|
return this.board.legalMoves().stream()
|
||||||
.filter(move -> move.getFrom() == square)
|
.filter(move -> move.getFrom() == square)
|
||||||
.map(move -> move.getTo())
|
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
|
||||||
|
|
||||||
public Clock getClock() {
|
|
||||||
return this.clock;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isZuruecknahme() {
|
|
||||||
return zuruecknahme;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean movesNotNull() {
|
|
||||||
if (movelist.getLast() != null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFen() {
|
|
||||||
return this.board.getFen();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Move getLastMove() {
|
|
||||||
logger.info(this.movelist.getLast().toString());
|
|
||||||
return this.movelist.getLast();
|
|
||||||
}
|
|
||||||
|
|
||||||
public MoveList getMoveList() {
|
|
||||||
return this.movelist;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Board getBoard() {
|
|
||||||
return this.board;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toFEN() {
|
|
||||||
board.toString();
|
|
||||||
return board.getFen();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUnicodeFromMove(Move move) {
|
|
||||||
return board.getPiece(move.getTo()).getFanSymbol().toUpperCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setViewPointer(int i) {
|
|
||||||
this.viewPointer = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getViewPointer() {
|
|
||||||
return this.viewPointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Piece> getRemovedPieces() {
|
|
||||||
return removedPieces;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRotieren() {
|
|
||||||
return rotieren;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
package de.mannheim.th.chess.domain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ueberprueft, ob ein Zug gueltig ist.
|
||||||
|
*/
|
||||||
|
public class MoveChecker{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
package de.mannheim.th.chess.domain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Liest einen Zug ein.
|
||||||
|
*/
|
||||||
|
public class MoveReader{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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();
|
||||||
|
}
|
||||||
|
|
@ -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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,161 +0,0 @@
|
||||||
package de.mannheim.th.chess.ui;
|
|
||||||
|
|
||||||
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 de.mannheim.th.chess.App;
|
|
||||||
import de.mannheim.th.chess.domain.Game;
|
|
||||||
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import javax.swing.Box;
|
|
||||||
import javax.swing.BoxLayout;
|
|
||||||
import javax.swing.JButton;
|
|
||||||
|
|
||||||
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 long serialVersionUID = 1L;
|
|
||||||
private JPanel contentPane;
|
|
||||||
private Game game;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the frame.
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public MainFrame() {
|
|
||||||
|
|
||||||
|
|
||||||
setBackground(Color.LIGHT_GRAY);
|
|
||||||
setResizable(true);
|
|
||||||
setAlwaysOnTop(true);
|
|
||||||
setTitle("Schach");
|
|
||||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
|
||||||
setBounds(100, 100, 500, 500);
|
|
||||||
|
|
||||||
contentPane = new JPanel();
|
|
||||||
contentPane.setBackground(new Color(90, 90, 90));
|
|
||||||
contentPane.setForeground(Color.BLACK);
|
|
||||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
|
||||||
|
|
||||||
setContentPane(contentPane);
|
|
||||||
|
|
||||||
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
|
|
||||||
|
|
||||||
contentPane.add(Box.createVerticalStrut(10));
|
|
||||||
|
|
||||||
JLabel lblNewLabel = new JLabel("Schach");
|
|
||||||
lblNewLabel.setForeground(Color.BLACK);
|
|
||||||
lblNewLabel.setFont(new Font("Serif", Font.BOLD, 60));
|
|
||||||
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(CENTER_ALIGNMENT);
|
|
||||||
contentPane.add(lblNewLabel_1);
|
|
||||||
|
|
||||||
contentPane.add(Box.createVerticalStrut(75));
|
|
||||||
|
|
||||||
JButton btnNewButton = new JButton("Neues Spiel starten");
|
|
||||||
|
|
||||||
btnNewButton.setBackground(Color.LIGHT_GRAY);
|
|
||||||
btnNewButton.setForeground(Color.BLACK);
|
|
||||||
btnNewButton.setFont(new Font("Tahoma", Font.BOLD, 16));
|
|
||||||
btnNewButton.setAlignmentX(CENTER_ALIGNMENT);
|
|
||||||
btnNewButton.addActionListener(new ActionListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
openSelectModeFrame();
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
contentPane.add(btnNewButton);
|
|
||||||
|
|
||||||
contentPane.add(Box.createVerticalStrut(15));
|
|
||||||
|
|
||||||
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());
|
|
||||||
contentPane.add(pgnLoaderButton);
|
|
||||||
|
|
||||||
contentPane.add(Box.createVerticalStrut(15));
|
|
||||||
|
|
||||||
JButton btnNewButton_2 = new JButton("App beenden");
|
|
||||||
|
|
||||||
btnNewButton_2.setBackground(Color.LIGHT_GRAY);
|
|
||||||
btnNewButton_2.setForeground(Color.BLACK);
|
|
||||||
btnNewButton_2.setFont(new Font("Tahoma", Font.BOLD, 16));
|
|
||||||
btnNewButton_2.setAlignmentX(CENTER_ALIGNMENT);
|
|
||||||
btnNewButton_2.addActionListener(new ActionListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
contentPane.add(btnNewButton_2);
|
|
||||||
setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts the spielframe and game in playmode
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public void startGame() {
|
|
||||||
if (this.game != null) {
|
|
||||||
//this.game.stopClock();
|
|
||||||
new SpielFrame(this.game);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts the spielframe and game in view mode
|
|
||||||
*/
|
|
||||||
public void startView() {
|
|
||||||
if (this.game != null) {
|
|
||||||
this.game.stopClock();
|
|
||||||
SpielFrame sf = new SpielFrame(this.game);
|
|
||||||
sf.setMode(SpielFrame.BoardMode.finished);
|
|
||||||
sf.enableControlPanelButtons();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGame(Game game) {
|
|
||||||
this.game = game;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* opens the selectmodeframe
|
|
||||||
*/
|
|
||||||
private void openSelectModeFrame() {
|
|
||||||
new ModeSelectionFrame(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Opens the pgnselectorframe
|
|
||||||
*/
|
|
||||||
private void openPgnSelectFrame() {
|
|
||||||
new PGNLoaderFrame(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,132 +0,0 @@
|
||||||
package de.mannheim.th.chess.ui;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import javax.swing.*;
|
|
||||||
import javax.swing.border.EmptyBorder;
|
|
||||||
|
|
||||||
// import org.apache.logging.log4j.LogManager;
|
|
||||||
// import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
// 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 long serialVersionUID = 1L;
|
|
||||||
private final JPanel contentPane;
|
|
||||||
private String fen;
|
|
||||||
|
|
||||||
public ModeSelectionFrame(MainFrame mf) {
|
|
||||||
// Frame-Eigenschaften
|
|
||||||
setTitle("Modusauswahl");
|
|
||||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
|
||||||
setBounds(100, 100, 600, 600);
|
|
||||||
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(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(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(CENTER_ALIGNMENT);
|
|
||||||
contentPane.add(jl2);
|
|
||||||
|
|
||||||
JCheckBox jb1 = new JCheckBox();
|
|
||||||
jb1.setOpaque(false);
|
|
||||||
jb1.setFocusPainted(false);
|
|
||||||
jb1.setForeground(Color.BLACK);
|
|
||||||
jb1.setAlignmentX(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(CENTER_ALIGNMENT);
|
|
||||||
contentPane.add(jl3);
|
|
||||||
|
|
||||||
JCheckBox jb2 = new JCheckBox();
|
|
||||||
jb2.setOpaque(false);
|
|
||||||
jb2.setFocusPainted(false);
|
|
||||||
jb2.setForeground(Color.BLACK);
|
|
||||||
jb2.setAlignmentX(CENTER_ALIGNMENT);
|
|
||||||
jb2.setMaximumSize(new Dimension(30, 30));
|
|
||||||
contentPane.add(jb2);
|
|
||||||
|
|
||||||
contentPane.add(Box.createVerticalStrut(15));
|
|
||||||
|
|
||||||
JButton btnNewButton_1 = new JButton("Vergangenes Spiel laden");
|
|
||||||
|
|
||||||
btnNewButton_1.setBackground(Color.LIGHT_GRAY);
|
|
||||||
btnNewButton_1.setForeground(Color.BLACK);
|
|
||||||
btnNewButton_1.setFont(new Font("Tahoma", Font.BOLD, 16));
|
|
||||||
btnNewButton_1.setAlignmentX(CENTER_ALIGNMENT);
|
|
||||||
btnNewButton_1.addActionListener(new ButtonFileLoaderListener(this));
|
|
||||||
|
|
||||||
contentPane.add(btnNewButton_1);
|
|
||||||
|
|
||||||
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(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, fen);
|
|
||||||
mf.setGame(game);
|
|
||||||
mf.startGame();
|
|
||||||
|
|
||||||
// spiele.add(game);
|
|
||||||
|
|
||||||
dispose();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFen(String fen) {
|
|
||||||
this.fen = fen;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,154 +0,0 @@
|
||||||
package de.mannheim.th.chess.ui;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import javax.swing.BoxLayout;
|
|
||||||
import javax.swing.DefaultListModel;
|
|
||||||
import javax.swing.JButton;
|
|
||||||
import javax.swing.JFileChooser;
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JList;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JProgressBar;
|
|
||||||
import javax.swing.JScrollPane;
|
|
||||||
import javax.swing.ListSelectionModel;
|
|
||||||
import javax.swing.SwingWorker;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
import com.github.bhlangonijr.chesslib.game.Game;
|
|
||||||
import com.github.bhlangonijr.chesslib.pgn.PgnHolder;
|
|
||||||
import com.github.bhlangonijr.chesslib.pgn.PgnLoadListener;
|
|
||||||
|
|
||||||
public class PGNLoaderFrame extends JFrame {
|
|
||||||
|
|
||||||
private static final Logger logger = LogManager.getLogger(PGNLoaderFrame.class);
|
|
||||||
|
|
||||||
private PgnHolder pgn;
|
|
||||||
private File selectedFile;
|
|
||||||
private List<Game> games;
|
|
||||||
private DefaultListModel<String> gameListModel;
|
|
||||||
private JPanel contentPane;
|
|
||||||
private JList<String> gameList;
|
|
||||||
private JProgressBar progressBar;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Opens the PNGLoaderFrame
|
|
||||||
*/
|
|
||||||
public PGNLoaderFrame(MainFrame mf) {
|
|
||||||
|
|
||||||
// ----- Style -----
|
|
||||||
setResizable(true);
|
|
||||||
setAlwaysOnTop(true);
|
|
||||||
setTitle("PGNLoader");
|
|
||||||
setBounds(100, 100, 500, 500);
|
|
||||||
|
|
||||||
// ----- contentPane -----
|
|
||||||
contentPane = new JPanel();
|
|
||||||
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
|
|
||||||
|
|
||||||
setContentPane(contentPane);
|
|
||||||
|
|
||||||
// ----- FileSelector -----
|
|
||||||
JButton fileSelectButton = new JButton("Select File");
|
|
||||||
fileSelectButton.addActionListener(e -> {
|
|
||||||
JFileChooser fileChooser = new JFileChooser();
|
|
||||||
int returnValue = fileChooser.showOpenDialog(null);
|
|
||||||
if (returnValue == JFileChooser.APPROVE_OPTION) {
|
|
||||||
selectedFile = fileChooser.getSelectedFile();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
contentPane.add(fileSelectButton);
|
|
||||||
|
|
||||||
// ----- LoadButton -----
|
|
||||||
JButton loadPgnButton = new JButton("Load file");
|
|
||||||
loadPgnButton.addActionListener(e -> loadFile());
|
|
||||||
contentPane.add(loadPgnButton);
|
|
||||||
|
|
||||||
// ----- SelectionList -----
|
|
||||||
gameListModel = new DefaultListModel<>();
|
|
||||||
gameList = new JList<>(gameListModel);
|
|
||||||
gameList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
|
||||||
gameList.setVisibleRowCount(5);
|
|
||||||
JScrollPane scrollPane = new JScrollPane(gameList);
|
|
||||||
contentPane.add(scrollPane);
|
|
||||||
|
|
||||||
// ----- ProgressBar -----
|
|
||||||
progressBar = new JProgressBar(0, 100);
|
|
||||||
progressBar.setValue(0);
|
|
||||||
progressBar.setStringPainted(true);
|
|
||||||
contentPane.add(progressBar);
|
|
||||||
|
|
||||||
// ----- StartButton -----
|
|
||||||
JButton startGameButton = new JButton("Starte Spiel");
|
|
||||||
startGameButton.addActionListener(e -> {
|
|
||||||
int index = gameList.getSelectedIndex();
|
|
||||||
de.mannheim.th.chess.domain.Game game = new de.mannheim.th.chess.domain.Game(games.get(index).getHalfMoves());
|
|
||||||
|
|
||||||
mf.setGame(game);
|
|
||||||
mf.startView();
|
|
||||||
});
|
|
||||||
contentPane.add(startGameButton);
|
|
||||||
|
|
||||||
this.setVisible(true);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadFile() {
|
|
||||||
if (this.selectedFile != null) {
|
|
||||||
pgn = new PgnHolder(this.selectedFile.getAbsolutePath());
|
|
||||||
|
|
||||||
LoadPGNWorker loadPGNWorker = new LoadPGNWorker();
|
|
||||||
loadPGNWorker.addPropertyChangeListener(e -> {
|
|
||||||
progressBar.setIndeterminate(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
pgn.getListener().add(loadPGNWorker);
|
|
||||||
loadPGNWorker.execute();
|
|
||||||
|
|
||||||
gameList.revalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class LoadPGNWorker extends SwingWorker<Integer, Integer> implements PgnLoadListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Integer doInBackground() throws Exception {
|
|
||||||
try {
|
|
||||||
pgn.loadPgn();
|
|
||||||
games = pgn.getGames();
|
|
||||||
int totalGames = games.size();
|
|
||||||
for (int i = 0; i < totalGames; i++) {
|
|
||||||
publish(i);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.info("Could not load pgn file!");
|
|
||||||
}
|
|
||||||
return pgn.getSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void process(List<Integer> chunks) {
|
|
||||||
for (Integer index : chunks) {
|
|
||||||
gameListModel.addElement("Game: " + index);
|
|
||||||
setProgress(Math.min(90, index * 100 / games.size()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void done() {
|
|
||||||
setProgress(100);
|
|
||||||
progressBar.setValue(100);
|
|
||||||
progressBar.setIndeterminate(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void notifyProgress(int games) {
|
|
||||||
setProgress(Math.min(90, games));
|
|
||||||
progressBar.setValue(Math.min(90, games));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,759 +0,0 @@
|
||||||
package de.mannheim.th.chess.ui;
|
|
||||||
|
|
||||||
// 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 com.github.bhlangonijr.chesslib.Piece;
|
|
||||||
import com.github.bhlangonijr.chesslib.Side;
|
|
||||||
|
|
||||||
import de.mannheim.th.chess.domain.Game;
|
|
||||||
import de.mannheim.th.chess.utl.Clock;
|
|
||||||
import de.mannheim.th.chess.utl.OpeningRecognizer;
|
|
||||||
import de.mannheim.th.chess.controller.ButtonAufgebenListener;
|
|
||||||
import de.mannheim.th.chess.controller.ButtonFileSaverListener;
|
|
||||||
import de.mannheim.th.chess.controller.ButtonMovePieceListener;
|
|
||||||
import de.mannheim.th.chess.controller.controlPanel.ButtonQuickloadListener;
|
|
||||||
import de.mannheim.th.chess.controller.controlPanel.ButtonQuicksaveListener;
|
|
||||||
import de.mannheim.th.chess.controller.ButtonSelectPieceListener;
|
|
||||||
import de.mannheim.th.chess.controller.ButtonToNormalListener;
|
|
||||||
import de.mannheim.th.chess.controller.ButtonUndoMoveListener;
|
|
||||||
import de.mannheim.th.chess.controller.controlPanel.ButtonViewBackListener;
|
|
||||||
import de.mannheim.th.chess.controller.controlPanel.ButtonViewFirstListener;
|
|
||||||
import de.mannheim.th.chess.controller.controlPanel.ButtonViewForwardListener;
|
|
||||||
import de.mannheim.th.chess.controller.controlPanel.ButtonViewLastListener;
|
|
||||||
|
|
||||||
import java.awt.Font;
|
|
||||||
|
|
||||||
import javax.swing.BorderFactory;
|
|
||||||
import javax.swing.Box;
|
|
||||||
import javax.swing.BoxLayout;
|
|
||||||
import javax.swing.ImageIcon;
|
|
||||||
import javax.swing.JButton;
|
|
||||||
import javax.swing.JDialog;
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JScrollPane;
|
|
||||||
import javax.swing.JSplitPane;
|
|
||||||
import javax.swing.JTextArea;
|
|
||||||
import javax.swing.SwingConstants;
|
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.Component;
|
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.FlowLayout;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.awt.GridLayout;
|
|
||||||
import java.awt.Toolkit;
|
|
||||||
|
|
||||||
public class SpielFrame extends JFrame {
|
|
||||||
|
|
||||||
// private static final Logger logger = LogManager.getLogger(App.class);
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
private ArrayList<JButton> buttons = new ArrayList<>();
|
|
||||||
private HashMap<JButton, String> belegungen = new HashMap<>();
|
|
||||||
private JPanel panelLinks, panelRechts, contentPane, controlPanel;
|
|
||||||
private JButton undo, undo2, aufgeben, aufgeben2;
|
|
||||||
private JTextArea ausgabe, blackRemovedPieces, whiteRemovedPieces;
|
|
||||||
private Game game;
|
|
||||||
private Clock clock;
|
|
||||||
private String opening;
|
|
||||||
private ArrayList<String> anzeigeMoves = new ArrayList<String>();
|
|
||||||
private boolean wechsel = false;
|
|
||||||
|
|
||||||
private BoardMode mode;
|
|
||||||
private Square selectedSquare;
|
|
||||||
|
|
||||||
public enum BoardMode {
|
|
||||||
normal, pieceSelected, finished
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the frame.
|
|
||||||
*/
|
|
||||||
public SpielFrame(Game game) {
|
|
||||||
opening = "unbekannte Eröffnung";
|
|
||||||
this.game = game;
|
|
||||||
this.clock = game.getClock();
|
|
||||||
this.clock.start();
|
|
||||||
|
|
||||||
mode = BoardMode.normal;
|
|
||||||
|
|
||||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
|
||||||
|
|
||||||
//setBounds(100, 100, 1920, 1080);
|
|
||||||
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
|
|
||||||
setBounds(0,0, d.width, d.height);
|
|
||||||
setExtendedState(JFrame.MAXIMIZED_BOTH);
|
|
||||||
setTitle("Schach");
|
|
||||||
setAlwaysOnTop(true);
|
|
||||||
|
|
||||||
contentPane = new JPanel();
|
|
||||||
contentPane.setLayout(new BorderLayout());
|
|
||||||
setContentPane(contentPane);
|
|
||||||
|
|
||||||
// Linkes Panel mit GridLayout 8x8 für Schachbrett
|
|
||||||
panelLinks = new JPanel(new GridLayout(8, 8));
|
|
||||||
|
|
||||||
erstelleBrett();
|
|
||||||
|
|
||||||
// Rechtes Panel für Steuerung oder zusätzliche Eingaben
|
|
||||||
panelRechts = new JPanel();
|
|
||||||
panelRechts.setBackground(new Color(90, 90, 90));
|
|
||||||
panelRechts.setLayout(new BoxLayout(panelRechts, BoxLayout.Y_AXIS));
|
|
||||||
|
|
||||||
// Panel für alle Eingaben von Player 2
|
|
||||||
panelRechts.add(getUiPlayerTwo());
|
|
||||||
|
|
||||||
panelRechts.add(createControlPanel());
|
|
||||||
|
|
||||||
// Panel für Statistikanzeigen
|
|
||||||
panelRechts.add(getUiStatistik());
|
|
||||||
|
|
||||||
// Panel für alle Eingaben von Player 1
|
|
||||||
panelRechts.add(getUiPlayerOne());
|
|
||||||
|
|
||||||
// JSplitPane horizontal (linke und rechte Hälfte)
|
|
||||||
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panelLinks, panelRechts);
|
|
||||||
splitPane.setResizeWeight(0.75);
|
|
||||||
splitPane.setBackground(Color.BLACK);
|
|
||||||
splitPane.setDividerSize(1);
|
|
||||||
splitPane.setEnabled(false);
|
|
||||||
|
|
||||||
contentPane.add(splitPane, BorderLayout.CENTER);
|
|
||||||
|
|
||||||
setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Erstellt alle Buttons und fügt sie dem Frame hinzu.
|
|
||||||
*/
|
|
||||||
public void erstelleBrett() {
|
|
||||||
|
|
||||||
this.setDefaultButtons();
|
|
||||||
this.setButtonsActions();
|
|
||||||
this.applyBoardButtons();
|
|
||||||
|
|
||||||
this.ladeBrett();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the to default buttons
|
|
||||||
*/
|
|
||||||
public void setDefaultButtons() {
|
|
||||||
this.clearButtons();
|
|
||||||
this.setDefaultBackground();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* holt sich FEN-Zeichenkette und extrahiert daraus die Positionen der Figuren
|
|
||||||
*/
|
|
||||||
public void ladeBrett() {
|
|
||||||
char[] fen = game.toFEN().replaceAll("/", "").split(" ")[0].toCharArray();
|
|
||||||
int i = 0;
|
|
||||||
for (int j = 0; j < fen.length; j++) {
|
|
||||||
if (Character.isDigit(fen[j])) {
|
|
||||||
int leerfelder = Character.getNumericValue(fen[j]);
|
|
||||||
for (int k = 0; k < leerfelder; k++) {
|
|
||||||
int idx;
|
|
||||||
if (game.isRotieren())
|
|
||||||
idx = wechsel ? mirrowedGrid(i) : i;
|
|
||||||
else
|
|
||||||
idx = i;
|
|
||||||
belegungen.put(buttons.get(idx), "n-n");
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
} else if (fen[j] >= 65 && fen[j] <= 90) { // Großbuchstabe = weiß
|
|
||||||
int idx;
|
|
||||||
if (game.isRotieren())
|
|
||||||
idx = wechsel ? mirrowedGrid(i) : i;
|
|
||||||
else
|
|
||||||
idx = i;
|
|
||||||
belegungen.put(buttons.get(idx), "w-" + fen[j]);
|
|
||||||
} else if (fen[j] >= 97 && fen[j] <= 122) { // Kleinbuchstabe = schwarz
|
|
||||||
int idx;
|
|
||||||
if (game.isRotieren())
|
|
||||||
idx = wechsel ? mirrowedGrid(i) : i;
|
|
||||||
else
|
|
||||||
idx = i;
|
|
||||||
belegungen.put(buttons.get(idx), "b-" + fen[j]);
|
|
||||||
}
|
|
||||||
int idx;
|
|
||||||
if (game.isRotieren())
|
|
||||||
idx = wechsel ? mirrowedGrid(i) : i;
|
|
||||||
else
|
|
||||||
idx = i;
|
|
||||||
buttons.get(idx).setIcon(new ImageIcon("src/main/resources/" + (int) fen[j] + ".png"));
|
|
||||||
buttons.get(idx).setDisabledIcon(new ImageIcon("src/main/resources/" + (int) fen[j] + ".png"));
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Switches the button actions depending on the boardmode
|
|
||||||
*/
|
|
||||||
public void setButtonsActions() {
|
|
||||||
|
|
||||||
List<Square> selectables;
|
|
||||||
|
|
||||||
switch (this.mode) {
|
|
||||||
case normal:
|
|
||||||
selectables = game.getAllLegalMoveableSquares();
|
|
||||||
for (Square square : selectables) {
|
|
||||||
int idx;
|
|
||||||
|
|
||||||
if (game.isRotieren())
|
|
||||||
idx = wechsel ? square.ordinal() : mirrowedGrid(square.ordinal());
|
|
||||||
else
|
|
||||||
idx = this.mirrowedGrid(square.ordinal());
|
|
||||||
|
|
||||||
JButton b = buttons.get(idx);
|
|
||||||
b.setEnabled(true);
|
|
||||||
b.addActionListener(new ButtonSelectPieceListener(this, square));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case pieceSelected:
|
|
||||||
int idxSelected;
|
|
||||||
|
|
||||||
if (game.isRotieren())
|
|
||||||
idxSelected = wechsel ? selectedSquare.ordinal() : mirrowedGrid(selectedSquare.ordinal());
|
|
||||||
else
|
|
||||||
idxSelected = mirrowedGrid(selectedSquare.ordinal());
|
|
||||||
|
|
||||||
JButton s = buttons.get(idxSelected);
|
|
||||||
s.setEnabled(true);
|
|
||||||
s.setBackground(new Color(165, 42, 42));
|
|
||||||
s.addActionListener(new ButtonToNormalListener(this));
|
|
||||||
|
|
||||||
selectables = game.getLegalMoveableSquares(selectedSquare);
|
|
||||||
for (Square square : selectables) {
|
|
||||||
int idx;
|
|
||||||
if (game.isRotieren())
|
|
||||||
idx = wechsel ? square.ordinal() : mirrowedGrid(square.ordinal());
|
|
||||||
else
|
|
||||||
idx = mirrowedGrid(square.ordinal());
|
|
||||||
final Move move = new Move(selectedSquare, square);
|
|
||||||
JButton b = buttons.get(idx);
|
|
||||||
b.setEnabled(true);
|
|
||||||
b.setBackground(new Color(230, 100, 100));
|
|
||||||
b.addActionListener(new ButtonMovePieceListener(this, this.game, move));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case finished:
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void showWin(int player) {
|
|
||||||
JFrame frame = new JFrame("Result");
|
|
||||||
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
|
||||||
frame.setSize(300, 150);
|
|
||||||
frame.setLayout(null);
|
|
||||||
|
|
||||||
JLabel jl = new JLabel(String.format("%d - %d", player / 2, player % 2));
|
|
||||||
jl.setBounds(50, 30, 200, 25);
|
|
||||||
jl.setFont(new Font("Tahoma", Font.BOLD, 20));
|
|
||||||
frame.add(jl);
|
|
||||||
frame.setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void showResult(String res) {
|
|
||||||
|
|
||||||
ausgabe.setFont(new Font("Calibri", Font.BOLD, 40));
|
|
||||||
ausgabe.setForeground(new Color(178, 34, 34));
|
|
||||||
ausgabe.setText(" " + res);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public int showPromotion() {
|
|
||||||
final int[] result = { -1 };
|
|
||||||
|
|
||||||
JDialog dialog = new JDialog(this, "Wähle eine Figur", true);
|
|
||||||
dialog.setLayout(new GridLayout(2, 2));
|
|
||||||
dialog.setSize(300, 200);
|
|
||||||
|
|
||||||
int[] pictures = { 81, 82, 66, 78, 113, 114, 98, 110 };
|
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
int index = (game.getActivePlayer() - 1) * 4 + i;
|
|
||||||
JButton jb = new JButton();
|
|
||||||
jb.setIcon(new ImageIcon("src/main/resources/" + pictures[index] + ".png"));
|
|
||||||
int selectedPiece = index;
|
|
||||||
jb.addActionListener(e -> {
|
|
||||||
result[0] = selectedPiece;
|
|
||||||
dialog.dispose();
|
|
||||||
});
|
|
||||||
dialog.add(jb);
|
|
||||||
}
|
|
||||||
|
|
||||||
dialog.setLocationRelativeTo(null);
|
|
||||||
dialog.setVisible(true);
|
|
||||||
|
|
||||||
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
|
|
||||||
*/
|
|
||||||
private JPanel createControlPanel() {
|
|
||||||
this.controlPanel = new JPanel();
|
|
||||||
this.controlPanel.setBackground(new Color(90, 90, 90));
|
|
||||||
this.controlPanel.setLayout(new FlowLayout());
|
|
||||||
|
|
||||||
this.controlPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, controlPanel.getPreferredSize().height));
|
|
||||||
|
|
||||||
// ----- ViewQuicksaveButton -----
|
|
||||||
JButton quicksave = new JButton("Quicksave");
|
|
||||||
quicksave.setBackground(Color.LIGHT_GRAY);
|
|
||||||
quicksave.setForeground(Color.BLACK);
|
|
||||||
quicksave.setFont(new Font("Tahoma", Font.BOLD, 16));
|
|
||||||
quicksave.setAlignmentX(CENTER_ALIGNMENT);
|
|
||||||
quicksave.setEnabled(true);
|
|
||||||
quicksave.addActionListener(new ButtonQuicksaveListener(this.game));
|
|
||||||
this.controlPanel.add(quicksave);
|
|
||||||
|
|
||||||
// ----- ViewFirstButton -----
|
|
||||||
JButton viewFirstButton = new JButton("<<");
|
|
||||||
viewFirstButton.setBackground(Color.LIGHT_GRAY);
|
|
||||||
viewFirstButton.setForeground(Color.BLACK);
|
|
||||||
viewFirstButton.setFont(new Font("Calibri", Font.BOLD, 16));
|
|
||||||
viewFirstButton.setAlignmentX(CENTER_ALIGNMENT);
|
|
||||||
viewFirstButton.setEnabled(false);
|
|
||||||
viewFirstButton.addActionListener(new ButtonViewFirstListener(this.game, this));
|
|
||||||
this.controlPanel.add(viewFirstButton);
|
|
||||||
|
|
||||||
// ----- ViewBackButton -----
|
|
||||||
JButton viewBackButton = new JButton("←");
|
|
||||||
viewBackButton.setBackground(Color.LIGHT_GRAY);
|
|
||||||
viewBackButton.setForeground(Color.BLACK);
|
|
||||||
viewBackButton.setFont(new Font("Calibri", Font.BOLD, 16));
|
|
||||||
viewBackButton.setAlignmentX(CENTER_ALIGNMENT);
|
|
||||||
viewBackButton.setEnabled(false);
|
|
||||||
viewBackButton.addActionListener(new ButtonViewBackListener(this.game, this));
|
|
||||||
this.controlPanel.add(viewBackButton);
|
|
||||||
|
|
||||||
// ----- ViewForwardButton -----
|
|
||||||
JButton viewForwardButton = new JButton("→");
|
|
||||||
viewForwardButton.setBackground(Color.LIGHT_GRAY);
|
|
||||||
viewForwardButton.setForeground(Color.BLACK);
|
|
||||||
viewForwardButton.setFont(new Font("Calibri", Font.BOLD, 16));
|
|
||||||
viewForwardButton.setAlignmentX(CENTER_ALIGNMENT);
|
|
||||||
viewForwardButton.setEnabled(false);
|
|
||||||
viewForwardButton.addActionListener(new ButtonViewForwardListener(this.game, this));
|
|
||||||
this.controlPanel.add(viewForwardButton);
|
|
||||||
|
|
||||||
// ----- ViewLastButton -----
|
|
||||||
JButton viewLastButton = new JButton(">>");
|
|
||||||
viewLastButton.setBackground(Color.LIGHT_GRAY);
|
|
||||||
viewLastButton.setForeground(Color.BLACK);
|
|
||||||
viewLastButton.setFont(new Font("Calibri", Font.BOLD, 16));
|
|
||||||
viewLastButton.setAlignmentX(CENTER_ALIGNMENT);
|
|
||||||
viewLastButton.setEnabled(false);
|
|
||||||
viewLastButton.addActionListener(new ButtonViewLastListener(this.game, this));
|
|
||||||
this.controlPanel.add(viewLastButton);
|
|
||||||
|
|
||||||
// ----- ViewQuickloadButton -----
|
|
||||||
JButton quickload = new JButton("Quickload");
|
|
||||||
quickload.setBackground(Color.LIGHT_GRAY);
|
|
||||||
quickload.setForeground(Color.BLACK);
|
|
||||||
quickload.setFont(new Font("Tahoma", Font.BOLD, 16));
|
|
||||||
quickload.setAlignmentX(CENTER_ALIGNMENT);
|
|
||||||
quickload.setEnabled(true);
|
|
||||||
quickload.addActionListener(new ButtonQuickloadListener(this.game, this));
|
|
||||||
this.controlPanel.add(quickload);
|
|
||||||
|
|
||||||
return controlPanel;
|
|
||||||
}
|
|
||||||
|
|
||||||
private JPanel getUiPlayerTwo() {
|
|
||||||
|
|
||||||
JPanel playerTwo = new JPanel();
|
|
||||||
playerTwo.setBackground(new Color(90, 90, 90));
|
|
||||||
playerTwo.setLayout(new BoxLayout(playerTwo, BoxLayout.Y_AXIS));
|
|
||||||
|
|
||||||
playerTwo.add(Box.createVerticalStrut(15));
|
|
||||||
|
|
||||||
JLabel pl2 = new JLabel("Player 2:");
|
|
||||||
pl2.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0));
|
|
||||||
pl2.setFont(new Font("Calibri", Font.BOLD, 35));
|
|
||||||
pl2.setForeground(Color.BLACK);
|
|
||||||
pl2.setAlignmentX(CENTER_ALIGNMENT);
|
|
||||||
playerTwo.add(pl2);
|
|
||||||
|
|
||||||
playerTwo.add(Box.createVerticalStrut(10));
|
|
||||||
|
|
||||||
JLabel clock1 = clock.getClock2();
|
|
||||||
playerTwo.add(clock1);
|
|
||||||
|
|
||||||
playerTwo.add(Box.createVerticalStrut(10));
|
|
||||||
|
|
||||||
// Button zurücknahme und aufgeben für Player 2
|
|
||||||
JPanel aufgebenUndo = new JPanel();
|
|
||||||
aufgebenUndo.setBackground(new Color(90, 90, 90));
|
|
||||||
aufgebenUndo.setLayout(new BoxLayout(aufgebenUndo, BoxLayout.X_AXIS));
|
|
||||||
|
|
||||||
if (game.isZuruecknahme()) {
|
|
||||||
undo = new JButton("Zug zurücknehmen");
|
|
||||||
undo.setBackground(Color.LIGHT_GRAY);
|
|
||||||
undo.setForeground(Color.BLACK);
|
|
||||||
undo.setFont(new Font("Tahoma", Font.BOLD, 16));
|
|
||||||
undo.setAlignmentX(CENTER_ALIGNMENT);
|
|
||||||
aufgebenUndo.add(undo);
|
|
||||||
|
|
||||||
// Button-Listener
|
|
||||||
undo.addActionListener(new ButtonUndoMoveListener(this, this.game));
|
|
||||||
}
|
|
||||||
|
|
||||||
aufgebenUndo.add(Box.createHorizontalStrut(10));
|
|
||||||
|
|
||||||
aufgeben2 = new JButton("Aufgeben");
|
|
||||||
aufgeben2.setBackground(Color.LIGHT_GRAY);
|
|
||||||
aufgeben2.setForeground(Color.BLACK);
|
|
||||||
aufgeben2.setFont(new Font("Tahoma", Font.BOLD, 16));
|
|
||||||
aufgeben2.setAlignmentX(CENTER_ALIGNMENT);
|
|
||||||
|
|
||||||
aufgeben2.addActionListener(new ButtonAufgebenListener(this, this.game));
|
|
||||||
aufgebenUndo.add(aufgeben2);
|
|
||||||
|
|
||||||
aufgebenUndo.add(Box.createHorizontalStrut(10));
|
|
||||||
|
|
||||||
JButton safe = new JButton("Spielstand sichern");
|
|
||||||
safe.setBackground(Color.LIGHT_GRAY);
|
|
||||||
safe.setForeground(Color.BLACK);
|
|
||||||
safe.setFont(new Font("Tahoma", Font.BOLD, 16));
|
|
||||||
safe.setAlignmentX(CENTER_ALIGNMENT);
|
|
||||||
aufgebenUndo.add(safe);
|
|
||||||
|
|
||||||
// Button-Listener
|
|
||||||
safe.addActionListener(new ButtonFileSaverListener(this, this.game));
|
|
||||||
|
|
||||||
playerTwo.add(aufgebenUndo);
|
|
||||||
|
|
||||||
playerTwo.add(Box.createVerticalStrut(10));
|
|
||||||
|
|
||||||
return playerTwo;
|
|
||||||
}
|
|
||||||
|
|
||||||
private JPanel getUiStatistik() {
|
|
||||||
|
|
||||||
JPanel statistik = new JPanel();
|
|
||||||
statistik.setBackground(new Color(90, 90, 90));
|
|
||||||
statistik.setLayout(new BoxLayout(statistik, BoxLayout.Y_AXIS));
|
|
||||||
|
|
||||||
|
|
||||||
ausgabe = new JTextArea();
|
|
||||||
ausgabe.setEditable(false);
|
|
||||||
ausgabe.setBackground(new Color(75, 75, 75));
|
|
||||||
ausgabe.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1));
|
|
||||||
ausgabe.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 20));
|
|
||||||
ausgabe.setForeground(Color.BLACK);
|
|
||||||
ausgabe.setText("\n Bisherige Züge:\n");
|
|
||||||
|
|
||||||
whiteRemovedPieces = new JTextArea();
|
|
||||||
whiteRemovedPieces.setPreferredSize(new Dimension(300, 100));
|
|
||||||
whiteRemovedPieces.setEditable(false);
|
|
||||||
whiteRemovedPieces.setBackground(new Color(75, 75, 75));
|
|
||||||
whiteRemovedPieces.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1));
|
|
||||||
whiteRemovedPieces.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 40));
|
|
||||||
whiteRemovedPieces.setForeground(Color.WHITE);
|
|
||||||
|
|
||||||
blackRemovedPieces = new JTextArea();
|
|
||||||
blackRemovedPieces.setPreferredSize(new Dimension(300, 100));
|
|
||||||
blackRemovedPieces.setEditable(false);
|
|
||||||
blackRemovedPieces.setBackground(new Color(75, 75, 75));
|
|
||||||
blackRemovedPieces.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1));
|
|
||||||
blackRemovedPieces.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 40));
|
|
||||||
blackRemovedPieces.setForeground(Color.BLACK);
|
|
||||||
|
|
||||||
JScrollPane scrollPane = new JScrollPane(ausgabe);
|
|
||||||
scrollPane.setPreferredSize(new Dimension(500, 1000));
|
|
||||||
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
|
||||||
|
|
||||||
statistik.add(whiteRemovedPieces);
|
|
||||||
statistik.add(scrollPane);
|
|
||||||
statistik.add(blackRemovedPieces);
|
|
||||||
|
|
||||||
return statistik;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void aktualisiereAusgabe() {
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
opening = OpeningRecognizer.compareOpening(game.getMoveList(), opening);
|
|
||||||
sb.append("\n Bisherige Züge: " + opening + "\n");
|
|
||||||
|
|
||||||
MoveList l = game.getMoveList();
|
|
||||||
anzeigeMoves.add(" " + game.getUnicodeFromMove(l.getLast()) + ": " + l.getLast().toString() + "\n");
|
|
||||||
|
|
||||||
for (String line : anzeigeMoves) {
|
|
||||||
sb.append(line);
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder whitePieces = new StringBuilder();
|
|
||||||
StringBuilder blackPieces = new StringBuilder();
|
|
||||||
for (Piece piece: game.getRemovedPieces()) {
|
|
||||||
if (piece.getPieceSide() == Side.BLACK) {
|
|
||||||
blackPieces.append(piece.getFanSymbol().toUpperCase());
|
|
||||||
} else {
|
|
||||||
whitePieces.append(piece.getFanSymbol().toUpperCase());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
blackRemovedPieces.setText(blackPieces.toString());
|
|
||||||
whiteRemovedPieces.setText(whitePieces.toString());
|
|
||||||
|
|
||||||
ausgabe.setText(sb.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteLastAusgabe() {
|
|
||||||
String[] zeilen = ausgabe.getText().split("\n");
|
|
||||||
|
|
||||||
// es müssen immer mind 5 Zeilen existieren, dass also 1 Zug löschbar ist
|
|
||||||
if (zeilen.length <= 2)
|
|
||||||
return;
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (int i = 0; i < zeilen.length - 1; i++) {
|
|
||||||
sb.append(zeilen[i]).append("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
ausgabe.setText(sb.toString());
|
|
||||||
anzeigeMoves.removeLast();
|
|
||||||
}
|
|
||||||
|
|
||||||
private JPanel getUiPlayerOne() {
|
|
||||||
|
|
||||||
JPanel playerOne = new JPanel();
|
|
||||||
playerOne.setBackground(new Color(90, 90, 90));
|
|
||||||
playerOne.setLayout(new BoxLayout(playerOne, BoxLayout.Y_AXIS));
|
|
||||||
|
|
||||||
playerOne.add(Box.createVerticalStrut(10));
|
|
||||||
|
|
||||||
// Button zurücknahme und aufgeben für Player 1
|
|
||||||
JPanel aufgebenUndo = new JPanel();
|
|
||||||
aufgebenUndo.setBackground(new Color(90, 90, 90));
|
|
||||||
aufgebenUndo.setLayout(new BoxLayout(aufgebenUndo, BoxLayout.X_AXIS));
|
|
||||||
|
|
||||||
if (game.isZuruecknahme()) {
|
|
||||||
undo2 = new JButton("Zug zurücknehmen");
|
|
||||||
undo2.setBackground(Color.LIGHT_GRAY);
|
|
||||||
undo2.setForeground(Color.BLACK);
|
|
||||||
undo2.setFont(new Font("Tahoma", Font.BOLD, 16));
|
|
||||||
undo2.setAlignmentX(CENTER_ALIGNMENT);
|
|
||||||
aufgebenUndo.add(undo2);
|
|
||||||
|
|
||||||
// Button-Listener
|
|
||||||
undo2.addActionListener(new ButtonUndoMoveListener(this, this.game));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
aufgebenUndo.add(Box.createHorizontalStrut(10));
|
|
||||||
|
|
||||||
aufgeben = new JButton("Aufgeben");
|
|
||||||
aufgeben.setBackground(Color.LIGHT_GRAY);
|
|
||||||
aufgeben.setForeground(Color.BLACK);
|
|
||||||
aufgeben.setFont(new Font("Tahoma", Font.BOLD, 16));
|
|
||||||
aufgeben.setAlignmentX(CENTER_ALIGNMENT);
|
|
||||||
aufgeben.addActionListener(new ButtonAufgebenListener(this, this.game));
|
|
||||||
|
|
||||||
aufgebenUndo.add(aufgeben);
|
|
||||||
|
|
||||||
aufgebenUndo.add(Box.createHorizontalStrut(10));
|
|
||||||
|
|
||||||
JButton safe = new JButton("Spielstand sichern");
|
|
||||||
safe.setBackground(Color.LIGHT_GRAY);
|
|
||||||
safe.setForeground(Color.BLACK);
|
|
||||||
safe.setFont(new Font("Tahoma", Font.BOLD, 16));
|
|
||||||
safe.setAlignmentX(CENTER_ALIGNMENT);
|
|
||||||
aufgebenUndo.add(safe);
|
|
||||||
|
|
||||||
// Button-Listener
|
|
||||||
safe.addActionListener(new ButtonFileSaverListener(this, this.game));
|
|
||||||
|
|
||||||
playerOne.add(aufgebenUndo);
|
|
||||||
|
|
||||||
playerOne.add(Box.createVerticalStrut(15));
|
|
||||||
|
|
||||||
JLabel clock1 = clock.getClock1();
|
|
||||||
playerOne.add(clock1);
|
|
||||||
|
|
||||||
playerOne.add(Box.createVerticalStrut(10));
|
|
||||||
|
|
||||||
JLabel pl2 = new JLabel("Player 1:");
|
|
||||||
pl2.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0));
|
|
||||||
pl2.setFont(new Font("Calibri", Font.BOLD, 35));
|
|
||||||
pl2.setForeground(Color.BLACK);
|
|
||||||
pl2.setAlignmentX(CENTER_ALIGNMENT);
|
|
||||||
playerOne.add(pl2);
|
|
||||||
|
|
||||||
return playerOne;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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++;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
package de.mannheim.th.chess.ui;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import de.mannheim.th.chess.utl.GameReader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zeigt das Main-Menü der App an.
|
||||||
|
*/
|
||||||
|
public class Ui{
|
||||||
|
|
||||||
|
private ArrayList<GameWindow> gamewindows = new ArrayList<>();
|
||||||
|
private GameReader reader = new GameReader();
|
||||||
|
|
||||||
|
public Ui() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,152 +3,10 @@ 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.Color;
|
public class Clock{
|
||||||
import java.awt.Component;
|
|
||||||
import java.awt.Font;
|
public Clock() {
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
}
|
||||||
import javax.swing.BorderFactory;
|
|
||||||
import javax.swing.JLabel;
|
}
|
||||||
import javax.swing.Timer;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
public Clock(String 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 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);
|
|
||||||
|
|
||||||
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 t = new Timer(1000, (ae) -> {
|
|
||||||
|
|
||||||
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());
|
|
||||||
|
|
||||||
} 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
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 JLabel getClock1() {
|
|
||||||
|
|
||||||
return clock1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JLabel getClock2() {
|
|
||||||
|
|
||||||
return clock2;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -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();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 797 B |
|
Before Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 725 B |
|
Before Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 933 B |
|
Before Width: | Height: | Size: 1.2 KiB |
|
|
@ -1,13 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<Configuration status="WARN">
|
|
||||||
<Appenders>
|
|
||||||
<Console name="Console" target="SYSTEM_OUT">
|
|
||||||
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
|
|
||||||
</Console>
|
|
||||||
</Appenders>
|
|
||||||
<Loggers>
|
|
||||||
<Root level="info">
|
|
||||||
<AppenderRef ref="Console"/>
|
|
||||||
</Root>
|
|
||||||
</Loggers>
|
|
||||||
</Configuration>
|
|
||||||
|
|
@ -9,11 +9,11 @@ import org.junit.jupiter.api.Test;
|
||||||
*/
|
*/
|
||||||
public class AppTest {
|
public class AppTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rigorous Test :-)
|
* Rigorous Test :-)
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldAnswerWithTrue() {
|
public void shouldAnswerWithTrue() {
|
||||||
assertTrue(true);
|
assertTrue(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package de.mannheim.th.chess.domain;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
@ -25,40 +24,4 @@ public class GameTest {
|
||||||
assertEquals("a2a4", list.getLast().toString());
|
assertEquals("a2a4", list.getLast().toString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void getLegalMoveableSquaresTest() {
|
|
||||||
Game game = new Game();
|
|
||||||
Square square = Square.A2;
|
|
||||||
|
|
||||||
List<Square> controllList = Arrays.asList(Square.A3, Square.A4);
|
|
||||||
assertEquals(controllList, game.getLegalMoveableSquares(square));
|
|
||||||
|
|
||||||
game = new Game("k7/8/8/8/8/8/8/K6N w - - 0 1");
|
|
||||||
square = Square.H1;
|
|
||||||
controllList = Arrays.asList(Square.F2, Square.G3);
|
|
||||||
assertEquals(controllList, game.getLegalMoveableSquares(square));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getAllLegalMoveableSquaresTest() {
|
|
||||||
Game game = new Game();
|
|
||||||
|
|
||||||
List<Square> controllList = Arrays.asList(Square.A2, Square.B2, Square.C2, Square.D2, Square.E2, Square.F2,
|
|
||||||
Square.G2, Square.H2, Square.B1, Square.G1);
|
|
||||||
assertEquals(controllList, game.getAllLegalMoveableSquares());
|
|
||||||
|
|
||||||
game = new Game("k7/8/8/8/8/8/8/K6N w - - 0 1");
|
|
||||||
controllList = Arrays.asList(Square.H1, Square.A1);
|
|
||||||
assertEquals(controllList, game.getAllLegalMoveableSquares());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getUnicodeFromMoveTest() {
|
|
||||||
|
|
||||||
Game g = new Game();
|
|
||||||
Move m = new Move(Square.A2, Square.A4);
|
|
||||||
g.getBoard().doMove(m);
|
|
||||||
assertEquals("♙", g.getUnicodeFromMove(m));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
package de.mannheim.th.chess.ui;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
class SpielFrameTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void mirrowedGridTest() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -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");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||