From 3ef6adbda89a595f5cef6499ba0d0cbabf0a2aa8 Mon Sep 17 00:00:00 2001 From: Beenie93 Date: Sat, 4 Sep 2021 04:31:48 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EB=AA=85=EB=A0=B9=EC=96=B4=20enum?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B6=84=EB=A6=AC=20=EB=B0=8F=20=EC=98=B5?= =?UTF-8?q?=EC=85=98=20=ED=8F=AC=ED=95=A8=EB=90=9C=20=EB=AA=85=EB=A0=B9?= =?UTF-8?q?=EC=96=B4=20=EA=B0=9D=EC=B2=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/chess/domain/board/Board.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/chess/domain/board/Board.java b/src/main/java/chess/domain/board/Board.java index 77db463..32f2a3b 100644 --- a/src/main/java/chess/domain/board/Board.java +++ b/src/main/java/chess/domain/board/Board.java @@ -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); @@ -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("자신의 기물만 움직일 수 있습니다.");