Skip to content

Commit

Permalink
refactor: 명령어 enum으로 분리 및 옵션 포함된 명령어 객체 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
seongbeenkim committed Sep 3, 2021
1 parent d6edf85 commit 3ef6adb
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main/java/chess/domain/board/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ public void move(final MoveOptions moveOptions, final boolean isWhiteTurn) {
Position source = moveOptions.getSource();
Position target = moveOptions.getTarget();

validateSourceOwner(enemy, source);
validateSamePosition(source, target);
validateTarget(player, target);
validateKingMovable(player, enemy, source, target);
validate(player, enemy, source, target);

enemy.removePieceOn(target);
movePiece(player, source, target);
Expand All @@ -39,6 +36,13 @@ private Player currentPlayer(final boolean isWhiteTurn) {
return black;
}

private void validate(final Player player, final Player enemy, final Position source, final Position target) {
validateSourceOwner(enemy, source);
validateSamePosition(source, target);
validateTarget(player, target);
validateKingMovable(player, enemy, source, target);
}

private void validateSourceOwner(final Player enemy, final Position source) {
if (enemy.hasPieceOn(source)) {
throw new IllegalArgumentException("자신의 기물만 움직일 수 있습니다.");
Expand Down

0 comments on commit 3ef6adb

Please sign in to comment.