From 7bd6bea0e428f017f0caaf6e7c36105074f66dbd Mon Sep 17 00:00:00 2001 From: loveb Date: Tue, 6 Dec 2022 19:00:32 +0100 Subject: [PATCH] =?UTF-8?q?Se=20till=20att=20r=C3=A4tt=20person=20f=C3=A5r?= =?UTF-8?q?=20schack=20popup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../billenius/schack/boards/NetworkBoard.java | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/billenius/schack/boards/NetworkBoard.java b/src/main/java/com/billenius/schack/boards/NetworkBoard.java index d29276b..15a302d 100644 --- a/src/main/java/com/billenius/schack/boards/NetworkBoard.java +++ b/src/main/java/com/billenius/schack/boards/NetworkBoard.java @@ -108,26 +108,6 @@ public final class NetworkBoard extends Board implements Runnable { outputStream.writeObject(new BasicMove(move)); System.out.println("Move sent"); - 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: - } } catch (Exception e) { e.printStackTrace(); } @@ -154,6 +134,28 @@ public final class NetworkBoard extends Board implements Runnable { move.movedPiece.move(pieces, move.to); System.out.println("Repainting"); getParent().repaint(); + + 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: + } + } } catch (EOFException | SocketException e) { JOptionPane.showMessageDialog(this, "Lost connection to opponent");