Commit 63f13924 by Paktalin

Left isMovable() method only for parent Piece class

parent a932bb0c
...@@ -13,8 +13,4 @@ public class Bishop extends Piece { ...@@ -13,8 +13,4 @@ public class Bishop extends Piece {
this.color = color; this.color = color;
} }
@Override
public boolean isMovable(Position from, Position to) {
return false;
}
} }
package com.example.paktalin.agilejava_exercises.pieces; package com.example.paktalin.agilejava_exercises.pieces;
import com.example.paktalin.agilejava_exercises.Position;
import com.example.paktalin.agilejava_exercises.moves.KingMoveStrategy; import com.example.paktalin.agilejava_exercises.moves.KingMoveStrategy;
/** /**
...@@ -14,9 +13,4 @@ public class King extends Piece { ...@@ -14,9 +13,4 @@ public class King extends Piece {
moveStrategy = new KingMoveStrategy(); moveStrategy = new KingMoveStrategy();
this.color = color; this.color = color;
} }
@Override
public boolean isMovable(Position from, Position to) {
return (new KingMoveStrategy()).isMovable(from, to);
}
} }
...@@ -13,8 +13,4 @@ public class Knight extends Piece { ...@@ -13,8 +13,4 @@ public class Knight extends Piece {
this.color = color; this.color = color;
} }
@Override
public boolean isMovable(Position from, Position to) {
return false;
}
} }
...@@ -26,11 +26,6 @@ public class Pawn extends Piece { ...@@ -26,11 +26,6 @@ public class Pawn extends Piece {
} }
} }
@Override
public boolean isMovable(Position from, Position to) {
return false;
}
private static boolean pawnsOnSameColumn(Piece currentPiece, Piece piece) { private static boolean pawnsOnSameColumn(Piece currentPiece, Piece piece) {
return piece.getPosition().getColumn() == currentPiece.getPosition().getColumn() && return piece.getPosition().getColumn() == currentPiece.getPosition().getColumn() &&
piece.getPosition().getRow() != currentPiece.getPosition().getRow() && piece.getPosition().getRow() != currentPiece.getPosition().getRow() &&
......
...@@ -19,7 +19,7 @@ public abstract class Piece implements Comparable<Piece> { ...@@ -19,7 +19,7 @@ public abstract class Piece implements Comparable<Piece> {
Color color; Color color;
double strength; double strength;
Position position; private Position position;
MoveStrategy moveStrategy; MoveStrategy moveStrategy;
char representation; char representation;
...@@ -50,7 +50,9 @@ public abstract class Piece implements Comparable<Piece> { ...@@ -50,7 +50,9 @@ public abstract class Piece implements Comparable<Piece> {
return 0; return 0;
} }
public abstract boolean isMovable(Position from, Position to); public boolean isMovable(Position from, Position to){
return moveStrategy.isMovable(from, to);
}
public double getStrength() { public double getStrength() {
return this.strength; return this.strength;
......
...@@ -16,10 +16,4 @@ public class Queen extends Piece { ...@@ -16,10 +16,4 @@ public class Queen extends Piece {
moveStrategy = new QueenMoveStrategy(); moveStrategy = new QueenMoveStrategy();
this.color = color; this.color = color;
} }
@Override
public boolean isMovable(Position from, Position to) {
return (new QueenMoveStrategy()).isMovable(from, to);
}
} }
package com.example.paktalin.agilejava_exercises.pieces; package com.example.paktalin.agilejava_exercises.pieces;
import com.example.paktalin.agilejava_exercises.Position;
/** /**
* Created by Paktalin on 01/06/2018. * Created by Paktalin on 01/06/2018.
*/ */
...@@ -13,9 +11,4 @@ public class Rook extends Piece{ ...@@ -13,9 +11,4 @@ public class Rook extends Piece{
representation = 'r'; representation = 'r';
this.color = color; this.color = color;
} }
@Override
public boolean isMovable(Position from, Position to) {
return false;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment