Geschlagene Figuren werden an der Seite angezeigt
parent
201497b4a8
commit
116e2c5e55
|
|
@ -1,5 +1,6 @@
|
|||
package de.mannheim.th.chess.domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
@ -28,6 +29,8 @@ public class Game {
|
|||
private Board board;
|
||||
private Clock clock;
|
||||
private boolean rotieren, zuruecknahme;
|
||||
|
||||
ArrayList<Piece> removedPieces;
|
||||
|
||||
private MoveList movelist;
|
||||
private int viewPointer;
|
||||
|
|
@ -43,6 +46,7 @@ public class Game {
|
|||
this.board = new Board();
|
||||
this.movelist = new MoveList();
|
||||
this.startPosFen = this.board.getFen();
|
||||
removedPieces = new ArrayList<>();
|
||||
|
||||
clock = new Clock("blitz");
|
||||
clock.start();
|
||||
|
|
@ -63,6 +67,7 @@ public class Game {
|
|||
this.movelist = new MoveList();
|
||||
|
||||
clock = new Clock(modus);
|
||||
removedPieces = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -102,6 +107,10 @@ public class Game {
|
|||
* @param move the move to be played
|
||||
*/
|
||||
public void playMove(Move move) {
|
||||
Piece removedPiece = board.getPiece(move.getTo());
|
||||
if (removedPiece != Piece.NONE) {
|
||||
removedPieces.add(removedPiece);
|
||||
}
|
||||
this.board.doMove(move);
|
||||
this.movelist.add(move);
|
||||
clock.pressClock();
|
||||
|
|
@ -116,7 +125,11 @@ public class Game {
|
|||
|
||||
public void undo() {
|
||||
this.board.undoMove();
|
||||
this.movelist.removeLast();
|
||||
Move lastMove = this.movelist.removeLast();
|
||||
Piece removedPiece = board.getPiece(lastMove.getTo());
|
||||
if (removedPiece != Piece.NONE) {
|
||||
removedPieces.remove(removedPiece);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -153,11 +166,15 @@ public class Game {
|
|||
/**
|
||||
* Plays the move on the board and adds it to the movelist
|
||||
*
|
||||
* @param origin The square from wich it moves from.
|
||||
* @param origin The square from which it moves from.
|
||||
* @param desination The square where it will move to.
|
||||
*/
|
||||
public void playMove(Square origin, Square desination) {
|
||||
Move move = new Move(origin, desination);
|
||||
Piece removedPiece = board.getPiece(desination);
|
||||
if (removedPiece != Piece.NONE) {
|
||||
removedPieces.add(removedPiece);
|
||||
}
|
||||
this.board.doMove(move);
|
||||
this.movelist.add(move);
|
||||
|
||||
|
|
@ -319,6 +336,10 @@ public class Game {
|
|||
public int getViewPointer() {
|
||||
return this.viewPointer;
|
||||
}
|
||||
|
||||
public ArrayList<Piece> getRemovedPieces() {
|
||||
return removedPieces;
|
||||
}
|
||||
|
||||
public boolean isRotieren() {
|
||||
return rotieren;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ package de.mannheim.th.chess.ui;
|
|||
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;
|
||||
|
|
@ -57,7 +59,7 @@ public class SpielFrame extends JFrame {
|
|||
private HashMap<JButton, String> belegungen = new HashMap<>();
|
||||
private JPanel panelLinks, panelRechts, contentPane, controlPanel;
|
||||
private JButton undo, undo2, aufgeben, aufgeben2;
|
||||
private JTextArea ausgabe;
|
||||
private JTextArea ausgabe, blackRemovedPieces, whiteRemovedPieces;
|
||||
private Game game;
|
||||
private Clock clock;
|
||||
private ArrayList<String> anzeigeMoves = new ArrayList<String>();
|
||||
|
|
@ -305,7 +307,6 @@ public class SpielFrame extends JFrame {
|
|||
jb.setIcon(new ImageIcon("src/main/resources/" + pictures[index] + ".png"));
|
||||
int selectedPiece = index;
|
||||
jb.addActionListener(e -> {
|
||||
System.out.println("Test");
|
||||
result[0] = selectedPiece;
|
||||
dialog.dispose();
|
||||
});
|
||||
|
|
@ -525,7 +526,8 @@ public class SpielFrame extends JFrame {
|
|||
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));
|
||||
|
|
@ -533,11 +535,27 @@ public class SpielFrame extends JFrame {
|
|||
ausgabe.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 20));
|
||||
ausgabe.setForeground(Color.BLACK);
|
||||
ausgabe.setText("\n Bisherige Züge:\n");
|
||||
|
||||
whiteRemovedPieces = new JTextArea();
|
||||
whiteRemovedPieces.setEditable(false);
|
||||
whiteRemovedPieces.setBackground(new Color(75, 75, 75));
|
||||
whiteRemovedPieces.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
whiteRemovedPieces.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 40));
|
||||
whiteRemovedPieces.setForeground(Color.WHITE);
|
||||
|
||||
blackRemovedPieces = new JTextArea();
|
||||
blackRemovedPieces.setEditable(false);
|
||||
blackRemovedPieces.setBackground(new Color(75, 75, 75));
|
||||
blackRemovedPieces.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
blackRemovedPieces.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 40));
|
||||
blackRemovedPieces.setForeground(Color.BLACK);
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane(ausgabe);
|
||||
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
||||
|
||||
statistik.add(blackRemovedPieces);
|
||||
statistik.add(scrollPane);
|
||||
statistik.add(whiteRemovedPieces);
|
||||
|
||||
return statistik;
|
||||
}
|
||||
|
|
@ -553,6 +571,18 @@ public class SpielFrame extends JFrame {
|
|||
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());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue