chess/src/main/java/org/apidesign/html/demo/chess/BoardModel.java
changeset 244 cea2063fd0f9
parent 53 bc0094a5f88c
     1.1 --- a/chess/src/main/java/org/apidesign/html/demo/chess/BoardModel.java	Wed Sep 25 04:18:47 2013 +0200
     1.2 +++ b/chess/src/main/java/org/apidesign/html/demo/chess/BoardModel.java	Mon Nov 22 15:58:31 2021 +0100
     1.3 @@ -104,15 +104,32 @@
     1.4                  b.getMoves().add(newMove);
     1.5                  b.setPendingMove(newMove);
     1.6  
     1.7 -                data.setPieceColor(previoslySelected.getPieceColor());
     1.8 -                data.setPiece(previoslySelected.getPiece());
     1.9 -                previoslySelected.setPiece(null);
    1.10 -                previoslySelected.setPieceColor(null);
    1.11 +                if (PieceType.KING == previoslySelected.getPiece() && previoslySelected.getX() == 'E' && previoslySelected.getY() == 1 || previoslySelected.getY() == 8) {
    1.12 +                    if (data.getX() == 'G') {
    1.13 +                        movePieceFromTo(
    1.14 +                            findSquare(b, 'F', data.getY()),
    1.15 +                            findSquare(b, 'H', data.getY())
    1.16 +                        );
    1.17 +                    } else if (data.getX() == 'C') {
    1.18 +                        movePieceFromTo(
    1.19 +                            findSquare(b, 'D', data.getY()),
    1.20 +                            findSquare(b, 'A', data.getY())
    1.21 +                        );
    1.22 +                    }
    1.23 +                }
    1.24 +                movePieceFromTo(data, previoslySelected);
    1.25                  b.setTurn(b.getTurn() == Color.W ? Color.B : Color.W);
    1.26                  Rules.computeAccessible(b, null);
    1.27              }
    1.28          }
    1.29      }
    1.30 +
    1.31 +    private static void movePieceFromTo(Square newSquare, Square oldSquare) {
    1.32 +        newSquare.setPieceColor(oldSquare.getPieceColor());
    1.33 +        newSquare.setPiece(oldSquare.getPiece());
    1.34 +        oldSquare.setPiece(null);
    1.35 +        oldSquare.setPieceColor(null);
    1.36 +    }
    1.37      
    1.38      static class NextMove extends TimerTask {
    1.39          private static final Timer T = new Timer("Animate moves");