-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
다즐의 체스 게임 #8
base: main
Are you sure you want to change the base?
다즐의 체스 게임 #8
Changes from 39 commits
ff4f19d
1bab9ff
98598c0
1dd0f93
a762eb2
1610552
20539aa
295abff
d721903
279523e
a244af0
b94e60c
f8c8cfc
a3464a7
0018acb
85cd37d
83ce04a
c3bd497
7f968ee
a94dbb4
b865ae3
ff8bc45
8ccc18f
09db9cc
e589479
b4fe033
8933b75
7e4d664
cfa6f6a
72fcb86
1f57caa
8278add
50440a5
98e5b26
3918940
8c20f4a
1d11b77
b6ee99a
727d999
334d8e8
03c3e84
0e3476e
86451fb
47cf4bc
0c5feb5
d86af18
eb37ed2
661e1e5
55d8bce
04af044
6f81b3b
ca97f14
153a5d4
adaee92
7910ae9
0d0e5f4
65e4c3d
8f6d9a5
b8237f4
f63f543
9d9f51f
932d774
abdb43c
951b32d
b0eb44c
c015026
c986ac9
e2eeee0
932f1fe
584a958
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
## 도메인 객체 그래프 | ||
|
||
```mermaid | ||
graph TD | ||
ChessController --> InputView | ||
ChessController --> OutputView | ||
|
||
ChessController --> ChessGame | ||
ChessGame --> Board | ||
|
||
Square --> File | ||
Square --> Rank | ||
|
||
Board --> Square | ||
Board --> PIECE | ||
|
||
PIECE --> Color | ||
|
||
subgraph PIECE | ||
direction BT | ||
Pawn -.-> Piece | ||
Rook -.-> Piece | ||
Bishop -.-> Piece | ||
Knight -.-> Piece | ||
Queen -.-> Piece | ||
King -.-> Piece | ||
end | ||
``` | ||
|
||
## 구현 기능 목록 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 구현 목록이 깔끔해서 좋은 것 같아! |
||
|
||
### 체스 게임 | ||
|
||
- [x] 기물을 이동시킨다. | ||
|
||
### 체스 보드 | ||
|
||
- 체스 기물 위치를 알고 있다. | ||
- [x] 체스 기물 위치를 초기화한다. | ||
- [x] 특정 칸에 존재하는 기물을 확인한다. | ||
- [x] 이동 경로로 이동할 수 있는지 확인한다. | ||
- [x] 폰이 이동 경로로 이동할 수 있는지 확인한다. | ||
- [x] 기물 위치를 업데이트한다. | ||
|
||
### 체스 칸 | ||
|
||
- 세로줄 (File) | ||
- [x] 왼쪽부터 a ~ h이다. | ||
- [x] [예외사항] 존재하지 않는 인덱스라면 예외를 던진다. | ||
- [x] 파일 간 거리를 계산한다. | ||
- [x] 다음 파일을 반환한다. | ||
- [x] 이전 파일을 반환한다. | ||
- 가로줄 (Rank) | ||
- [x] 아래부터 1 ~ 8이다. | ||
- [x] [예외사항] 존재하지 않는 인덱스라면 예외를 던진다. | ||
- [x] 랭크 간 거리를 계산한다. | ||
- [x] 다음 랭크를 반환한다. | ||
- [x] 이전 랭크를 반환한다. | ||
|
||
### 체스 기물 | ||
|
||
- 색을 가진다. | ||
- [x] 흑과 백이 존재한다. | ||
- [x] 검은색인지 확인한다. | ||
- [x] 움직이는 경로를 반환한다. | ||
- [x] 폰인지 확인한다. | ||
|
||
### 방향 벡터 | ||
|
||
- [x] 움직이려는 방향으로 갈 수 있는지 확인한다. | ||
- [x] 방향의 다음 파일을 반환한다. | ||
- [x] 방향의 다음 랭크를 반환한다. | ||
|
||
### 입력 | ||
|
||
- [x] 게임 시작/종료 여부를 입력한다. | ||
- [x] 이동할 기물의 위치를 입력한다. | ||
|
||
### 출력 | ||
|
||
- [x] 게임 시작 문구를 출력한다. | ||
- [x] 체스판을 출력한다. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package chess; | ||
|
||
import chess.controller.ChessController; | ||
|
||
public class ChessApplication { | ||
public static void main(String[] args) { | ||
final ChessController chessController = new ChessController(); | ||
chessController.run(); | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package chess.controller; | ||
|
||
import static chess.controller.ChessStartCommand.START; | ||
|
||
import chess.controller.dto.ChessBoardDto; | ||
import chess.domain.ChessGame; | ||
import chess.view.InputView; | ||
import chess.view.OutputView; | ||
|
||
public class ChessController { | ||
|
||
private static final InputView inputView = new InputView(); | ||
private static final OutputView outputView = new OutputView(); | ||
Comment on lines
+19
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기서 생성하신 이유가 있나욥? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 클래스 필드가 늘어나는 것도 막을 수 있고, 뷰 자체로 상태를 가지지 않기에 |
||
|
||
private final ChessGame chessGame = new ChessGame(); | ||
|
||
public void run() { | ||
outputView.printStartMessage(); | ||
if (readChessStartCommand() == START) { | ||
outputView.printChessBoard(ChessBoardDto.from(chessGame)); | ||
playChessGame(); | ||
} | ||
} | ||
|
||
private ChessStartCommand readChessStartCommand() { | ||
while (true) { | ||
try { | ||
return ChessStartCommand.from(inputView.readChessExecuteCommand()); | ||
} catch (IllegalArgumentException e) { | ||
outputView.printErrorMessage(e.getMessage()); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 다즐은 depth 2 어떻게 생각하시나요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 재귀를 사용하지 않으려 했던 소심한 반란이였습니다 |
||
} | ||
|
||
private void playChessGame() { | ||
while (true) { | ||
try { | ||
repeatMove(); | ||
return; | ||
} catch (IllegalArgumentException e) { | ||
outputView.printErrorMessage(e.getMessage()); | ||
} | ||
} | ||
} | ||
|
||
private void repeatMove() { | ||
ChessGameCommand chessGameCommand = ChessGameCommand.from(inputView.readChessGameCommand()); | ||
while (chessGameCommand.getChessExecuteCommand() == ChessExecuteCommand.MOVE) { | ||
chessGame.move(chessGameCommand.getSource(), chessGameCommand.getDestination()); | ||
outputView.printChessBoard(ChessBoardDto.from(chessGame)); | ||
chessGameCommand = ChessGameCommand.from(inputView.readChessGameCommand()); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package chess.controller; | ||
|
||
import static java.lang.String.format; | ||
|
||
import java.util.Arrays; | ||
|
||
public enum ChessExecuteCommand { | ||
|
||
MOVE("move"), | ||
STOP("end"); | ||
|
||
private final String input; | ||
|
||
ChessExecuteCommand(final String input) { | ||
this.input = input; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return input; | ||
} | ||
|
||
public static ChessExecuteCommand from(final String input) { | ||
return Arrays.stream(ChessExecuteCommand.values()) | ||
.filter(chessExecuteCommand -> chessExecuteCommand.input.equals(input)) | ||
.findFirst() | ||
.orElseThrow(() -> new IllegalArgumentException(format("%s나 %s 중 입력해야 합니다.", MOVE, STOP))); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package chess.controller; | ||
|
||
import chess.domain.board.Square; | ||
import java.util.List; | ||
|
||
public class ChessGameCommand { | ||
|
||
private final ChessExecuteCommand chessExecuteCommand; | ||
private final Square source; | ||
private final Square destination; | ||
|
||
private ChessGameCommand(final ChessExecuteCommand chessExecuteCommand) { | ||
this(chessExecuteCommand, null, null); | ||
} | ||
|
||
private ChessGameCommand( | ||
final ChessExecuteCommand chessExecuteCommand, | ||
final Square source, | ||
final Square destination | ||
) { | ||
this.chessExecuteCommand = chessExecuteCommand; | ||
this.source = source; | ||
this.destination = destination; | ||
} | ||
|
||
public static ChessGameCommand initMove() { | ||
return new ChessGameCommand(ChessExecuteCommand.MOVE); | ||
} | ||
|
||
public static ChessGameCommand from(final List<String> inputs) { | ||
validateEmpty(inputs); | ||
final ChessExecuteCommand chessExecuteCommand = ChessExecuteCommand.from(inputs.get(0)); | ||
if (chessExecuteCommand == ChessExecuteCommand.STOP) { | ||
return getEndCommand(inputs, chessExecuteCommand); | ||
} | ||
return getMoveCommand(inputs, chessExecuteCommand); | ||
} | ||
|
||
private static void validateEmpty(final List<String> inputs) { | ||
if (inputs.isEmpty()) { | ||
throw new IllegalArgumentException("move랑 end 중 입력하세요."); | ||
} | ||
} | ||
|
||
private static ChessGameCommand getEndCommand( | ||
final List<String> inputs, | ||
final ChessExecuteCommand chessExecuteCommand | ||
) { | ||
validateEnd(inputs); | ||
return new ChessGameCommand(chessExecuteCommand); | ||
} | ||
|
||
private static void validateEnd(final List<String> inputs) { | ||
if (inputs.size() != 1) { | ||
throw new IllegalArgumentException("end만 입력해야 합니다."); | ||
} | ||
} | ||
|
||
private static ChessGameCommand getMoveCommand( | ||
final List<String> inputs, | ||
final ChessExecuteCommand chessExecuteCommand | ||
) { | ||
validateMove(inputs); | ||
return new ChessGameCommand(chessExecuteCommand, Square.from(inputs.get(1)), Square.from(inputs.get(2))); | ||
} | ||
|
||
private static void validateMove(final List<String> inputs) { | ||
if (inputs.size() != 3) { | ||
throw new IllegalArgumentException("(예. move b2 b3)와 같이 입력해야 합니다."); | ||
} | ||
} | ||
|
||
public ChessExecuteCommand getChessExecuteCommand() { | ||
return chessExecuteCommand; | ||
} | ||
|
||
public Square getSource() { | ||
return source; | ||
} | ||
|
||
public Square getDestination() { | ||
return destination; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package chess.controller; | ||
|
||
import static java.lang.String.format; | ||
|
||
import java.util.Arrays; | ||
|
||
public enum ChessStartCommand { | ||
|
||
START("start"), | ||
END("end"); | ||
|
||
private final String input; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
라고 현구막이 달아줬어요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 위와 동일한 내용인 것 같네요 👍 |
||
|
||
ChessStartCommand(final String input) { | ||
this.input = input; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return input; | ||
} | ||
|
||
public static ChessStartCommand from(final String input) { | ||
return Arrays.stream(ChessStartCommand.values()) | ||
.filter(chessStartCommand -> chessStartCommand.input.equals(input)) | ||
.findFirst() | ||
.orElseThrow(() -> new IllegalArgumentException(format("%s나 %s 중 입력해야 합니다.", START, END))); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분이 변경된 이유가 있나욥><
큰 이유가 없다면, 변경되지 않았어도 좋을 것 같아욥><!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
헉 건들이지 않았던 것 같은데 무슨일이죠 🤔