diff --git a/src/handlers/EnemyOnDestinationHandler.java b/src/handlers/EnemyOnDestinationHandler.java new file mode 100644 index 0000000..2e1d244 --- /dev/null +++ b/src/handlers/EnemyOnDestinationHandler.java @@ -0,0 +1,2 @@ +package handlers;public class EnemyOnDestinationHandler { +} diff --git a/src/handlers/LeftSquareDiagonallyHandler.java b/src/handlers/LeftSquareDiagonallyHandler.java new file mode 100644 index 0000000..7005308 --- /dev/null +++ b/src/handlers/LeftSquareDiagonallyHandler.java @@ -0,0 +1,2 @@ +package handlers;public class LeftSquareDiagonallyHandler { +} diff --git a/src/handlers/OneMoveForwardHandler.java b/src/handlers/OneMoveForwardHandler.java index 554466b..b895182 100644 --- a/src/handlers/OneMoveForwardHandler.java +++ b/src/handlers/OneMoveForwardHandler.java @@ -7,9 +7,13 @@ public class OneMoveForwardHandler extends BaseHandler { @Override protected boolean isValid(Board board, Square from, Square to) { - if (board.getPieceAt(from).getOwner().getColor() == Color.BLACK) { - return to.getRow() == from.getRow() - 1; + boolean result = to.getColumn() == from.getColumn(); + if (board.getPieceAt(from).getOwner().getColor() == Color.WHITE) { + result = result && to.getRow() == from.getRow() + 1; + } else { + result = result && to.getRow() == from.getRow() - 1; } - return to.getRow() == from.getRow() + 1; + + return result; } } diff --git a/src/handlers/RightSquareDiagonallyHandler.java b/src/handlers/RightSquareDiagonallyHandler.java new file mode 100644 index 0000000..6e0d8ca --- /dev/null +++ b/src/handlers/RightSquareDiagonallyHandler.java @@ -0,0 +1,2 @@ +package handlers;public class RightSquareDiagonallyHandler { +} diff --git a/src/handlers/TwoMovesForwardHandler.java b/src/handlers/TwoMovesForwardHandler.java index a6a947b..e259236 100644 --- a/src/handlers/TwoMovesForwardHandler.java +++ b/src/handlers/TwoMovesForwardHandler.java @@ -7,9 +7,13 @@ public class TwoMovesForwardHandler extends BaseHandler { @Override protected boolean isValid(Board board, Square from, Square to) { - if (board.getPieceAt(from).getOwner().getColor() == Color.BLACK) { - return to.getRow() == from.getRow() - 2; + boolean result = to.getColumn() == from.getColumn(); + if (board.getPieceAt(from).getOwner().getColor() == Color.WHITE) { + result = result && to.getRow() == from.getRow() + 2; + } else { + result = result && to.getRow() == from.getRow() - 2; } - return to.getRow() == from.getRow() + 2; + + return result; } } diff --git a/src/movements/LeftSquareDiagonallyIfEnemyExistsStrategy.java b/src/movements/LeftSquareDiagonallyIfEnemyExistsStrategy.java new file mode 100644 index 0000000..b2a4a19 --- /dev/null +++ b/src/movements/LeftSquareDiagonallyIfEnemyExistsStrategy.java @@ -0,0 +1,24 @@ +package movements; + +import board.Board; +import general.Square; +import handlers.*; + +public class LeftSquareDiagonallyIfEnemyExists extends BaseHandler { + @Override + protected boolean isValid(Board board, Square from, Square to) { + if (board == null || from == null || to == null) { + throw new IllegalArgumentException("NullPointer argument"); + } + + BaseHandler handler1 = new ValidStartLocationHandler(); + BaseHandler handler2 = new ValidDestinationHandler(); + BaseHandler handler3 = new LeftSquareDiagonallyHandler(); + BaseHandler handler4 = new EnemyOnDestinationHandler(); + handler1.setNext(handler2); + handler2.setNext(handler3); + handler3.setNext(handler4); + + return handler1.canHandle(board, from, to); + } +} diff --git a/src/movements/RightSquareDiagonallyIfEnemyExistsStrategy.java b/src/movements/RightSquareDiagonallyIfEnemyExistsStrategy.java new file mode 100644 index 0000000..e7c66b7 --- /dev/null +++ b/src/movements/RightSquareDiagonallyIfEnemyExistsStrategy.java @@ -0,0 +1,2 @@ +package movements;public class RightSquareDiagonallyIfEnemyExists { +}