mirror of
https://github.com/lov3b/Schack.git
synced 2024-11-10 07:00:11 +01:00
Se till att rätt person får schack popup
This commit is contained in:
parent
bf9d170040
commit
7bd6bea0e4
@ -108,26 +108,6 @@ public final class NetworkBoard extends Board implements Runnable {
|
|||||||
outputStream.writeObject(new BasicMove(move));
|
outputStream.writeObject(new BasicMove(move));
|
||||||
System.out.println("Move sent");
|
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) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -154,6 +134,28 @@ public final class NetworkBoard extends Board implements Runnable {
|
|||||||
move.movedPiece.move(pieces, move.to);
|
move.movedPiece.move(pieces, move.to);
|
||||||
System.out.println("Repainting");
|
System.out.println("Repainting");
|
||||||
getParent().repaint();
|
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) {
|
} catch (EOFException | SocketException e) {
|
||||||
JOptionPane.showMessageDialog(this, "Lost connection to opponent");
|
JOptionPane.showMessageDialog(this, "Lost connection to opponent");
|
||||||
|
Loading…
Reference in New Issue
Block a user