KLienterna ansluter men Piece är inte serialiserbar eftersom BufferedImage inte är det

This commit is contained in:
2022-12-04 21:51:28 +01:00
parent 86e11f5c62
commit 54dd294433
7 changed files with 224 additions and 44 deletions

View File

@@ -0,0 +1,56 @@
package com.billenius.schack.boards;
import java.io.IOException;
import java.util.ArrayList;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import com.billenius.schack.Move;
import com.billenius.schack.SchackState;
import com.billenius.schack.pieces.Piece;
public final class SameBoard extends Board {
public SameBoard(DefaultListModel<Move> listModel) throws IOException {
super(listModel);
}
@Override
protected void makeMove(Move move) {
move.movedPiece.move(pieces, move.to);
turnCount++;
whitesTurn = !whitesTurn;
SchackState state = getSchackState();
switch (state) {
case SCHACK:
JOptionPane.showMessageDialog(this, "Du står i schack");
break;
case SCHACKMATT:
case PATT:
String stateStr = state.toString();
String msg = stateStr.charAt(0) + stateStr.substring(1, stateStr.length()).toLowerCase();
int choice = JOptionPane.showConfirmDialog(this, msg + "\nVill du starta om?");
if (choice == JOptionPane.YES_OPTION)
try {
restartGame();
} catch (IOException ex) {
}
break;
default:
}
}
@Override
protected void toDoIfNoPreviousPieceSelected(Piece selectedPiece) {
if (selectedPiece != null && selectedPiece.isWhite() == whitesTurn)
validMovesToDraw.addAll(selectedPiece.validMoves(pieces, true));
else
validMovesToDraw = new ArrayList<>(); // Snabbare än .clear
}
}