Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7d27a33
fix: 향상된 문법으로 equals 수정
junseoplee Jul 19, 2024
d6ca9b5
docs: 기능 요구 사항 업데이트
junseoplee Jul 20, 2024
5e9f872
feat: 승리한 팀을 찾고 출력하는 기능 구현
junseoplee Jul 20, 2024
fba2d73
feat: King 이 잡혔을 때 승리 팀과 점수를 출력하는 기능 구현
junseoplee Jul 22, 2024
90f634b
fix: Pawn 피스가 적이 없을 경우에도 대각선으로 움직일 수 있던 오류 수정
junseoplee Jul 22, 2024
89edcb7
docs: 기능 요구 사항 정리
junseoplee Jul 22, 2024
0218cec
refactor: 프로젝트 구조 수정
junseoplee Jul 23, 2024
c786f3d
feat: 게임별로 구분할 수 있는 ChessGame 클래스 구현, 저장할 수 있도록 상태를 나타내는 State 열거형 구현
junseoplee Jul 23, 2024
5fd16d9
feat: DB 연결에 필요한 설정 추가
junseoplee Jul 23, 2024
54b66b5
feat: DB 연결을 위한 ChessGameDao 기능 추가
junseoplee Jul 23, 2024
9f7f78c
feat: DB 연결을 위한 PieceDao 기능 추가
junseoplee Jul 23, 2024
037471d
feat: DB 연결을 위한 PieceDao 기능 추가
junseoplee Jul 23, 2024
61d451a
fix: DB 연결을 위한 설정 수정
junseoplee Jul 25, 2024
3f07391
refactor: Board 반환을 위한 리팩토링
junseoplee Jul 25, 2024
a4d293e
refactor: 진행 상태를 보다 명확하게 알 수 있도록 변경
junseoplee Jul 25, 2024
e20a260
feat: DB 연결 기능과 컨트롤러 조립
junseoplee Jul 25, 2024
80b7e47
docs: 기능 요구 사항 및 에러메세지 업데이트
junseoplee Jul 25, 2024
a3ac67f
fix: 기존 게임이 정상적으로 불러와지지 않던 오류 수정
junseoplee Jul 25, 2024
ddfb961
refactor: 명령어를 다루는 책임을 컨트롤러에서 분리
junseoplee Jul 29, 2024
7c6c78e
feat: UnsupportedOperationException 으로 사용되지 않는 메서드 관리
junseoplee Jul 29, 2024
0ad0e65
test: 폰의 공격 움직임을 검증하는 테스트 추가
junseoplee Jul 29, 2024
3ce712d
fix: 변수 이름을 명확하게 수정
junseoplee Jul 29, 2024
d5483e4
fix: 상태를 더 명확하게 나타낼 수 있는 이름으로 수정
junseoplee Jul 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chess.model;
package chess.domain;

public enum ErrorMessage {
INVALID_INITIAL_COMMAND("[ERROR] 게임 시작 명령은 start, 게임 종료 명령은 end 여야 합니다."),
Expand All @@ -13,7 +13,10 @@ public enum ErrorMessage {
SAME_COLOR_PIECE("[ERROR] 같은 색의 말로는 이동할 수 없습니다."),
SAME_POSITION("[ERROR] 출발지와 목적지가 동일하여 이동할 수 없습니다."),
INVALID_MOVE_COMMAND("[ERROR] 이동은 move source 위치 target 위치여야 합니다."),
INVALID_COMMAND("[ERROR] 유효하지 않은 명령입니다.");
INVALID_COMMAND("[ERROR] 유효하지 않은 명령입니다."),

ALREADY_RUNNING("[ERROR] 이미 진행 중인 게임입니다."),
NOT_RUNNING("[ERROR] 진행 중인 게임이 아닙니다.");

private final String message;

Expand Down
63 changes: 63 additions & 0 deletions src/main/java/chess/domain/game/ChessGame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package chess.domain.game;

import chess.domain.ErrorMessage;
import chess.domain.board.Board;
import chess.domain.piece.Piece;
import chess.domain.piece.PieceInfo;
import chess.domain.position.Color;
import chess.domain.position.Position;

public class ChessGame {

private final long id;
private State state;
private Color turn;
private final Board board;

public ChessGame(long id, Board board, Color turn) {
this.id = id;
this.state = State.WAITING;
this.board = board;
this.turn = turn;
}

public void start() {
if (state == State.RUNNING) {
throw new IllegalArgumentException(ErrorMessage.ALREADY_RUNNING.getMessage());
}
this.state = State.RUNNING;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

END 상태에서 START를 할 수는 없는 상태인가요?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

할 수 있습니다! 애플리케이션에서 end로 종료한 후에 continue 로 해당 게임을 불러오면 END 상태에 있고 start 커맨드를 입력하면 RUNNING 상태가 되어 다시 게임을 시작합니다


public void end() {
this.state = State.FINISHED;
}

public void movePiece(Position source, Position target) {
checkRunning();
Piece capturedPiece = board.moveAndReturnPiece(source, target, turn);
checkKingCaptured(capturedPiece);
changeTurn();
}

public Double calculateScore(Color color) {
checkRunning();
return ScoreCalculator.calculate(board.getMap(), color);
}

private void checkRunning() {
if (state == State.RUNNING) {
return;
}
throw new IllegalArgumentException(ErrorMessage.NOT_RUNNING.getMessage());
}

private void checkKingCaptured(Piece capturedPiece) {
if (capturedPiece != null && capturedPiece.pieceType() == PieceInfo.KING) {
end();
}
}

private void changeTurn() {
turn = turn.changeTurn();
}
}
7 changes: 7 additions & 0 deletions src/main/java/chess/domain/game/State.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package chess.domain.game;

public enum State {
WAITING,
RUNNING,
FINISHED
}