Aufgeben, Draw und Mate sollten jetzt in Ausgabe angezeigt werden.
parent
596a3a4dea
commit
cd89c3b131
|
|
@ -5,17 +5,49 @@ import java.awt.event.ActionListener;
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
|
||||||
public class ButtonAufgebenListener extends JFrame implements ActionListener{
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public ButtonAufgebenListener() {
|
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
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
Object source = e.getSource();
|
||||||
|
|
||||||
|
g.stopClock();
|
||||||
|
|
||||||
|
// weil nur der aktive Spieler button drücken darf
|
||||||
|
if (source == sf.getAufgeben()) {
|
||||||
|
logger.info("Spieler 1 will aufgeben.");
|
||||||
|
sf.getAufgeben2().setEnabled(false);
|
||||||
|
sf.showResult("Spieler 2 hat gewonnen!");
|
||||||
|
} else if (source == sf.getAufgeben2()) {
|
||||||
|
logger.info("Spieler 2 will aufgeben.");
|
||||||
|
sf.getAufgeben().setEnabled(false);
|
||||||
|
sf.showResult("Spieler 1 hat gewonnen!");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.sf.setBoardMode(BoardMode.finished);
|
||||||
|
|
||||||
|
sf.setButtonsActions();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,12 +29,16 @@ public class ButtonMovePieceListener implements ActionListener {
|
||||||
|
|
||||||
if (this.game.isDraw()) {
|
if (this.game.isDraw()) {
|
||||||
this.game.stopClock();
|
this.game.stopClock();
|
||||||
this.sf.setBoardMode(BoardMode.finished);
|
this.sf.showResult("Unentschieden!");
|
||||||
this.sf.showDraw();
|
this.sf.setBoardMode(BoardMode.gameEnd);
|
||||||
|
|
||||||
} else if (this.game.isMate()) {
|
} else if (this.game.isMate()) {
|
||||||
this.game.stopClock();
|
this.game.stopClock();
|
||||||
this.sf.setBoardMode(BoardMode.finished);
|
this.sf.showResult("Spieler "+game.getActivePlayer()+" hat gewonnen!");
|
||||||
this.sf.showWin(game.getActivePlayer());
|
|
||||||
|
|
||||||
|
this.sf.setBoardMode(BoardMode.gameEnd);
|
||||||
|
|
||||||
}
|
}
|
||||||
this.sf.setBoardMode(BoardMode.normal);
|
this.sf.setBoardMode(BoardMode.normal);
|
||||||
this.sf.setCursor(null);
|
this.sf.setCursor(null);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package de.mannheim.th.chess.ui;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import com.github.bhlangonijr.chesslib.Piece;
|
|
||||||
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;
|
||||||
|
|
@ -50,7 +49,7 @@ public class SpielFrame extends JFrame {
|
||||||
private ArrayList<JButton> buttons = new ArrayList<>();
|
private ArrayList<JButton> buttons = new ArrayList<>();
|
||||||
private HashMap<JButton, String> belegungen = new HashMap<>();
|
private HashMap<JButton, String> belegungen = new HashMap<>();
|
||||||
private JPanel panelLinks, panelRechts, contentPane;
|
private JPanel panelLinks, panelRechts, contentPane;
|
||||||
private JButton undo, undo2;
|
private JButton undo, undo2, aufgeben, aufgeben2;
|
||||||
private JTextArea ausgabe;
|
private JTextArea ausgabe;
|
||||||
private Game game;
|
private Game game;
|
||||||
private Clock clock;
|
private Clock clock;
|
||||||
|
|
@ -60,7 +59,7 @@ public class SpielFrame extends JFrame {
|
||||||
private Square selectedSquare;
|
private Square selectedSquare;
|
||||||
|
|
||||||
public enum BoardMode {
|
public enum BoardMode {
|
||||||
normal, pieceSelected, finished
|
normal, pieceSelected, finished, gameEnd
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -190,6 +189,7 @@ public class SpielFrame extends JFrame {
|
||||||
|
|
||||||
buttons.add(b);
|
buttons.add(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -211,7 +211,7 @@ public class SpielFrame extends JFrame {
|
||||||
/*
|
/*
|
||||||
* Switches the button actions depending on the boardmode
|
* Switches the button actions depending on the boardmode
|
||||||
*/
|
*/
|
||||||
private void setButtonsActions() {
|
public void setButtonsActions() {
|
||||||
|
|
||||||
List<Square> selectables;
|
List<Square> selectables;
|
||||||
|
|
||||||
|
|
@ -248,6 +248,14 @@ public class SpielFrame extends JFrame {
|
||||||
break;
|
break;
|
||||||
case finished:
|
case finished:
|
||||||
clearButtons();
|
clearButtons();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case gameEnd:
|
||||||
|
|
||||||
|
//alle Eingabemöglichkeiten deaktivieren
|
||||||
|
panelLinks.setEnabled(false);
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
@ -260,16 +268,8 @@ public class SpielFrame extends JFrame {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showDraw() {
|
public void showDraw() {
|
||||||
JFrame frame = new JFrame("Result");
|
|
||||||
frame.setDefaultCloseOperation(JFrame.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 showWin(int player) {
|
public void showWin(int player) {
|
||||||
|
|
@ -284,6 +284,14 @@ public class SpielFrame extends JFrame {
|
||||||
frame.add(jl);
|
frame.add(jl);
|
||||||
frame.setVisible(true);
|
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() {
|
public int showPromotion() {
|
||||||
final int[] result = { -1 };
|
final int[] result = { -1 };
|
||||||
|
|
@ -354,15 +362,14 @@ public class SpielFrame extends JFrame {
|
||||||
|
|
||||||
aufgebenUndo.add(Box.createHorizontalStrut(10));
|
aufgebenUndo.add(Box.createHorizontalStrut(10));
|
||||||
|
|
||||||
JButton aufgeben = new JButton("Aufgeben");
|
aufgeben2 = new JButton("Aufgeben");
|
||||||
aufgeben.setBackground(Color.LIGHT_GRAY);
|
aufgeben2.setBackground(Color.LIGHT_GRAY);
|
||||||
aufgeben.setForeground(Color.BLACK);
|
aufgeben2.setForeground(Color.BLACK);
|
||||||
aufgeben.setFont(new Font("Tahoma", Font.BOLD, 16));
|
aufgeben2.setFont(new Font("Tahoma", Font.BOLD, 16));
|
||||||
aufgeben.setAlignmentX(Component.CENTER_ALIGNMENT);
|
aufgeben2.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
aufgebenUndo.add(aufgeben);
|
|
||||||
|
aufgeben2.addActionListener(new ButtonAufgebenListener(this, this.game));
|
||||||
// Button-Listener
|
aufgebenUndo.add(aufgeben2);
|
||||||
aufgeben.addActionListener(new ButtonAufgebenListener());
|
|
||||||
|
|
||||||
aufgebenUndo.add(Box.createHorizontalStrut(10));
|
aufgebenUndo.add(Box.createHorizontalStrut(10));
|
||||||
|
|
||||||
|
|
@ -463,15 +470,14 @@ public class SpielFrame extends JFrame {
|
||||||
|
|
||||||
aufgebenUndo.add(Box.createHorizontalStrut(10));
|
aufgebenUndo.add(Box.createHorizontalStrut(10));
|
||||||
|
|
||||||
JButton aufgeben = new JButton("Aufgeben");
|
aufgeben = new JButton("Aufgeben");
|
||||||
aufgeben.setBackground(Color.LIGHT_GRAY);
|
aufgeben.setBackground(Color.LIGHT_GRAY);
|
||||||
aufgeben.setForeground(Color.BLACK);
|
aufgeben.setForeground(Color.BLACK);
|
||||||
aufgeben.setFont(new Font("Tahoma", Font.BOLD, 16));
|
aufgeben.setFont(new Font("Tahoma", Font.BOLD, 16));
|
||||||
aufgeben.setAlignmentX(Component.CENTER_ALIGNMENT);
|
aufgeben.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
aufgebenUndo.add(aufgeben);
|
aufgeben.addActionListener(new ButtonAufgebenListener(this, this.game));
|
||||||
|
|
||||||
// Button-Listener
|
aufgebenUndo.add(aufgeben);
|
||||||
aufgeben.addActionListener(new ButtonAufgebenListener());
|
|
||||||
|
|
||||||
aufgebenUndo.add(Box.createHorizontalStrut(10));
|
aufgebenUndo.add(Box.createHorizontalStrut(10));
|
||||||
|
|
||||||
|
|
@ -532,4 +538,20 @@ public class SpielFrame extends JFrame {
|
||||||
return clock;
|
return clock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JButton getAufgeben() {
|
||||||
|
return aufgeben;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAufgeben(JButton aufgeben) {
|
||||||
|
this.aufgeben = aufgeben;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JButton getAufgeben2() {
|
||||||
|
return aufgeben2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAufgeben2(JButton aufgeben2) {
|
||||||
|
this.aufgeben2 = aufgeben2;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue