-
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
오잉또잉 체스게임 #6
base: hanueleee
Are you sure you want to change the base?
오잉또잉 체스게임 #6
Changes from 48 commits
ff4f19d
1bab9ff
98598c0
abee5c9
4bbccbe
644808c
29390c8
80458aa
d902919
fa15be0
2e1eca1
14a6733
edaa59a
f482756
467627d
c7a7db4
232fe0a
cc72eb0
c3f340b
e79765c
31c776d
34b9b80
a5f3e86
d174cd9
8dae288
83915ae
f6e8145
6d814c7
a256899
03d5ca7
4c810b1
0acc0ba
cfd6765
0ad7f2f
5ce5dc3
b6a8808
053604f
7c9622e
4cd77f2
fc66c75
a869608
e83eb59
31e0fe7
a0bc8fe
c6f5f35
df8cd7a
ecfc8b6
d6a8ff7
8f8d542
d7d310e
2e37b07
22384af
dfe166c
14ddc61
1b6daee
c7612a3
bec77c8
6481479
d0f7612
2ba065c
7e54715
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 |
---|---|---|
@@ -1,7 +1,62 @@ | ||
# java-chess | ||
|
||
체스 미션 저장소 | ||
# 기능 목록 | ||
|
||
## 우아한테크코스 코드리뷰 | ||
## 도메인 | ||
|
||
- [온라인 코드 리뷰 과정](https://github.com/woowacourse/woowacourse-docs/blob/master/maincourse/README.md) | ||
### 좌표 | ||
|
||
- [x] 좌표는 file과 rank를 필드로 가진다. | ||
- [x] 좌표는 (A,1) ~ (H,8) 까지 가능 | ||
- [x] 좌표는 다른 좌표로의 방향을 구할 수 있다. | ||
|
||
### 피스 | ||
|
||
- [x] 자신의 진영을 필드로 가지고 있다. | ||
- [x] 움직일 수 있는지 검증 | ||
- [x] 폰 | ||
- [x] 나이트 | ||
- [x] 룩 | ||
- [x] 비숍 | ||
- [x] 퀸 | ||
- [x] 킹 | ||
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. 왜여 >< 다 알자나 |
||
|
||
### 체스판 | ||
|
||
- [x] 빈 보드를 생성 | ||
- [x] 좌표를 입력으로 주었을때, 좌표의 피스를 반환(getPiece) | ||
- [x] 좌표에 피스가 존재하는지 확인 | ||
- [x] 같은 색깔 피스 인지 확인. | ||
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] 피스를 교체(replace) | ||
- [x] 두 좌표를 주었을때, 두 좌표 사이에 피스가 있는지 검증(checkBetweenRoute) | ||
- [x] 목적지에 같은 색깔의 피스가 있는지 확인(checkSameColor) | ||
- [x] 폰이 움직일 수 있는지 확인(checkRestrictionForPawn) | ||
- [x] 대각선으로 움직일때, 상대편 피스가 있는지 확인 | ||
- [x] 위,아래 방향으로 움직일때, 칸이 비어있지 않은지 확인 | ||
|
||
### 피스 팩토리 | ||
|
||
- [x] 색상에 따라 초기 피스들의 리스트를 반환 | ||
|
||
### 랭크 : 가로줄을 나타내는 enum | ||
|
||
### 파일 : 세로줄을 나타내느 enum | ||
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. 아차차~ |
||
|
||
### 게임 | ||
|
||
- [x] 체스판을 초기화 | ||
- [x] 피스를 이동 | ||
|
||
### 명령 | ||
|
||
- [x] 입력받은 명령를 검증(start,end,move) | ||
|
||
## UI | ||
|
||
### 입력 | ||
|
||
- [x] 명령어를 입력 | ||
|
||
### 출력 | ||
|
||
- [x] 체스판을 출력 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package chess; | ||
|
||
import chess.controller.ChessController; | ||
import chess.view.InputView; | ||
import chess.view.OutputView; | ||
|
||
public class Applictaion { | ||
|
||
public static void main(String[] args) { | ||
ChessController chessController = new ChessController(new InputView(), new OutputView()); | ||
chessController.execute(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package chess; | ||
|
||
import java.util.List; | ||
|
||
public class CommandLine { | ||
|
||
private static final String INVALID_COMMAND_ERROR_MESSAGE = "잘못된 명령어입니다."; | ||
private static final String INVALID_ARGUMENT_ERROR_MESSAGE = "는 인자를 입력할 수 없습니다."; | ||
private static final String INVALID_ARGUMENT_COUNT_ERROR_MESSAGE = "는 인자를 2개만 가질 수 있습니다."; | ||
private static final String NO_ARGUMENT_ERROR_MESSAGE = "인자를 반환할 수 없는 명령입니다."; | ||
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. ㅇㅈ 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 static final String START = "start"; | ||
private static final String MOVE = "move"; | ||
private static final String END = "end"; | ||
private static final int ZERO_ARGUMENT_SIZE = 1; | ||
private static final int TWO_ARGUMENT_SIZE = 3; | ||
private static final int SOURCE_INDEX = 1; | ||
private static final int TARGET_INDEX = 3; | ||
private static final List<String> VALID_COMMANDS = List.of(START, MOVE, END); | ||
private final List<String> tokens; | ||
|
||
public CommandLine(final List<String> tokens) { | ||
this.validate(tokens); | ||
this.tokens = tokens; | ||
} | ||
|
||
private void validate(final List<String> tokens) { | ||
String command = tokens.get(0); | ||
if (!VALID_COMMANDS.contains(command)) { | ||
throw new IllegalArgumentException(INVALID_COMMAND_ERROR_MESSAGE); | ||
} | ||
if (!command.equals(MOVE) && tokens.size() != ZERO_ARGUMENT_SIZE) { | ||
throw new IllegalArgumentException(command + INVALID_ARGUMENT_ERROR_MESSAGE); | ||
} | ||
if (command.equals(MOVE) && tokens.size() != TWO_ARGUMENT_SIZE) { | ||
throw new IllegalArgumentException(command + INVALID_ARGUMENT_COUNT_ERROR_MESSAGE); | ||
} | ||
} | ||
|
||
public List<String> getArguments() { | ||
if (this.tokens.size() != TWO_ARGUMENT_SIZE) { | ||
throw new IllegalStateException(NO_ARGUMENT_ERROR_MESSAGE); | ||
} | ||
return this.tokens.subList(SOURCE_INDEX, TARGET_INDEX); | ||
} | ||
|
||
public boolean isStart() { | ||
return START.equals(this.getCommand()); | ||
} | ||
|
||
public String getCommand() { | ||
return this.tokens.get(0); | ||
} | ||
|
||
public boolean isMove() { | ||
return MOVE.equals(this.getCommand()); | ||
} | ||
|
||
public boolean isEnd() { | ||
return END.endsWith(this.getCommand()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package chess; | ||
|
||
public enum GameStatus { | ||
START, | ||
END, | ||
MOVE | ||
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. 엥 그러게 얘말고도 다른 enum도 땀 안붙였는데 잘돌아가네 왤까,, 일단 수정했슴당 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. |
||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package chess.controller; | ||
|
||
import chess.domain.Board; | ||
import chess.domain.piece.Piece; | ||
import chess.domain.position.Rank; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class BoardDto { | ||
|
||
private final List<String> stringPieces; | ||
|
||
private BoardDto(final List<String> pieces) { | ||
this.stringPieces = pieces; | ||
} | ||
|
||
public static BoardDto create(Board board) { | ||
List<String> stringPieces = new ArrayList<>(); | ||
for (Rank rank : Rank.values()) { | ||
String stringRank = makeStringRank(board, rank); | ||
stringPieces.add(stringRank); | ||
} | ||
Collections.reverse(stringPieces); | ||
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. ?!! 왜 굳이 만들고 |
||
return new BoardDto(stringPieces); | ||
} | ||
|
||
private static String makeStringRank(final Board board, final Rank rank) { | ||
StringBuilder builder = new StringBuilder(); | ||
for (Piece piece : board.getPiecesAt(rank)) { | ||
builder.append(PieceMapper.map(piece)); | ||
} | ||
return builder.toString(); | ||
} | ||
|
||
public List<String> getStringPieces() { | ||
return this.stringPieces; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package chess.controller; | ||
|
||
import chess.CommandLine; | ||
import chess.domain.ChessGame; | ||
import chess.view.InputView; | ||
import chess.view.OutputView; | ||
|
||
public class ChessController { | ||
|
||
|
||
private final InputView inputView; | ||
private final OutputView outputView; | ||
|
||
public ChessController(final InputView inputView, final OutputView outputView) { | ||
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. 말랑 근데 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. @hanueleee |
||
this.inputView = inputView; | ||
this.outputView = outputView; | ||
} | ||
|
||
public void execute() { | ||
this.outputView.printGameStartMessage(); | ||
ChessGame chessGame = new ChessGame(); | ||
while (!chessGame.isGameEnd()) { | ||
this.runGame(chessGame); | ||
} | ||
} | ||
|
||
private void runGame(final ChessGame chessGame) { | ||
try { | ||
CommandLine commandLine = this.getCommandLine(); | ||
this.handleCommandLine(chessGame, commandLine); | ||
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.
|
||
this.outputView.printBoard(BoardDto.create(chessGame.getBoard())); | ||
} catch (Exception e) { | ||
this.outputView.printError(e.getMessage()); | ||
} | ||
} | ||
|
||
private CommandLine getCommandLine() { | ||
return new CommandLine(this.inputView.readCommand()); | ||
} | ||
|
||
private void handleCommandLine(final ChessGame chessGame, final CommandLine commandLine) { | ||
if (commandLine.isStart()) { | ||
chessGame.start(); | ||
} | ||
if (commandLine.isMove()) { | ||
chessGame.move(commandLine.getArguments()); | ||
} | ||
if (commandLine.isEnd()) { | ||
chessGame.end(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package chess.controller; | ||
|
||
import chess.domain.piece.Piece; | ||
import chess.domain.piece.PieceType; | ||
|
||
public class PieceMapper { | ||
|
||
public static String map(Piece piece) { | ||
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. Map<Type, String>을 쓰면 분기를 줄일 수 있을 것 같아 |
||
String defaultPiece = ""; | ||
if (piece.getType() == PieceType.EMPTY) { | ||
return "."; | ||
} | ||
if (piece.getType() == PieceType.PAWN) { | ||
defaultPiece = "p"; | ||
} | ||
if (piece.getType() == PieceType.BISHOP) { | ||
defaultPiece = "b"; | ||
} | ||
if (piece.getType() == PieceType.KNIGHT) { | ||
defaultPiece = "n"; | ||
} | ||
if (piece.getType() == PieceType.ROOK) { | ||
defaultPiece = "r"; | ||
} | ||
if (piece.getType() == PieceType.QUEEN) { | ||
defaultPiece = "q"; | ||
} | ||
if (piece.getType() == PieceType.KING) { | ||
defaultPiece = "k"; | ||
} | ||
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 static filnal Map<PieceType, String> Mapper = Map.of(
PieceType.PAWN, "p"
) 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. 오 그렇네 감사링 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. 친절했다 ㄷㄷ |
||
if (!piece.isWhite()) { | ||
return defaultPiece.toUpperCase(); | ||
} | ||
return defaultPiece; | ||
} | ||
} |
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.
와 commit 보고 벌써 4단계 DB연결 다한줄 ㄷㄷ
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.
킥 킥 어림도 없지