Skip to content
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

[다리 건너기] 박준수 미션 제출합니다.(2) #7

Open
wants to merge 73 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
f74d90f
docs: 기능 목록/에러 처리 정의
GaBaljaintheroom Aug 23, 2023
294a3c3
feat: 다리 길이 입력 메서드 작성
GaBaljaintheroom Aug 23, 2023
4b55d76
feat: 다리 길이 입력 validator 작성
GaBaljaintheroom Aug 23, 2023
02200dd
feat: ErrorMessage 작성
GaBaljaintheroom Aug 23, 2023
01b693d
feat: GameProgressMessage 작성
GaBaljaintheroom Aug 23, 2023
6705e56
feat: outputView printInputBridgeSize 작성
GaBaljaintheroom Aug 23, 2023
5cc0f3c
test: 다리 길이 InputValidator 테스트
GaBaljaintheroom Aug 23, 2023
2d49a41
docs: 다리 길이 만큼 다리를 생성
GaBaljaintheroom Aug 23, 2023
27eff97
feat: GameCommand 생성
GaBaljaintheroom Aug 23, 2023
6faa1cd
feat: makeBridge 작성
GaBaljaintheroom Aug 23, 2023
6fa6061
test: 다리가 'U','D'로 구성되어 있는지 확인
GaBaljaintheroom Aug 23, 2023
6cc2dac
test: 입력된 길이 만큼 다리가 크기가 생성이 된는지 확인
GaBaljaintheroom Aug 23, 2023
209d74d
docs: 이동할 칸을 입력
GaBaljaintheroom Aug 23, 2023
55de42f
feat: 이동할 칸 ErrorMessage 생성
GaBaljaintheroom Aug 23, 2023
5b0e88d
feat: GameCommand에 isNotBridgeStageCommand 추가
GaBaljaintheroom Aug 23, 2023
896cd71
feat: GameProgressMessage 이동할 칸 추가
GaBaljaintheroom Aug 23, 2023
bfd6f34
feat: InputValidator validateBridgeStage 추가
GaBaljaintheroom Aug 23, 2023
7a00d9d
feat: InputView 이동할 칸 입력 추가
GaBaljaintheroom Aug 23, 2023
651e518
feat: OutputView printInputBridgeStage 추가
GaBaljaintheroom Aug 23, 2023
6c01772
feat: InputValidatorTest 이동할 칸 테스트
GaBaljaintheroom Aug 23, 2023
871c1d9
docs: Bridge 화면 생성
GaBaljaintheroom Aug 23, 2023
3903ace
feat: BridgeGame move 작성
GaBaljaintheroom Aug 23, 2023
4665501
feat: Bridge 생성
GaBaljaintheroom Aug 23, 2023
84fcafc
feat: BridgeStageRecord 생성
GaBaljaintheroom Aug 23, 2023
351ee56
feat: BridgeWindowElement 생성
GaBaljaintheroom Aug 23, 2023
ce51a48
feat: BridgeWindowMaker 생성
GaBaljaintheroom Aug 23, 2023
25120fc
feat: GameCommand isBridgeStageCommandU 추가
GaBaljaintheroom Aug 23, 2023
e263391
test: 생성된 다리가 Bridge에 저장이 되는지 확인
GaBaljaintheroom Aug 23, 2023
ad49f85
test: bridge에 입력할 칸이 맞으면 true를 반환하는지 확인
GaBaljaintheroom Aug 23, 2023
37f0ef8
test: 입력한 칸이 성공했을 때 SUCCESS를 반환하는지 확인
GaBaljaintheroom Aug 23, 2023
2783759
refactor: Bridge boolean 메서드명 수정
GaBaljaintheroom Aug 23, 2023
31da5ae
refactor: BridgeGame move 메서드 수정
GaBaljaintheroom Aug 23, 2023
92aeff8
refactor: 변수명 수정
GaBaljaintheroom Aug 23, 2023
0554e3b
refactor: BRIDGE_GAME_START 메세지 추가
GaBaljaintheroom Aug 23, 2023
6be2497
feat: printMap 작성
GaBaljaintheroom Aug 23, 2023
a9e4c4d
feat: printGameStart 작성
GaBaljaintheroom Aug 23, 2023
9008403
feat: BridgeStageRecord boolean 필드 추가
GaBaljaintheroom Aug 23, 2023
369b07c
feat: BridgeGameController 작성
GaBaljaintheroom Aug 23, 2023
7e03965
refactor: BridgeMap/Element로 이름 변경
GaBaljaintheroom Aug 25, 2023
983d809
feat: ErrorMessage 게임 다시 시도 여부 추가
GaBaljaintheroom Aug 25, 2023
c7f3321
feat: GameCommand 게임 다시 시도 여부 추가
GaBaljaintheroom Aug 25, 2023
0ded25d
feat: INPUT_BRIDGE_RETRY 게임 다시 시도 여부 추가
GaBaljaintheroom Aug 25, 2023
b0aa52b
feat: validateBridgeRetry 추가
GaBaljaintheroom Aug 25, 2023
adf59ac
feat: InputView readGameCommand 작성
GaBaljaintheroom Aug 25, 2023
67e9624
feat: OutputView printInputBridgeRetry 작성
GaBaljaintheroom Aug 25, 2023
582a014
test: 재시도 여부 명령어가 대문자 영어가 아니면 에러
GaBaljaintheroom Aug 25, 2023
8a53115
test: 재시도 여부 명령어가 'R' 혹은 'Q'가 아니면 에러
GaBaljaintheroom Aug 25, 2023
6284da3
docs: 재시작 여부를 입력 받는다.
GaBaljaintheroom Aug 25, 2023
2ed4e23
refactor: InputView isNotInputNull 추출
GaBaljaintheroom Aug 25, 2023
9791ef0
feat: BridgeGame retry 작성
GaBaljaintheroom Aug 25, 2023
f76b694
feat: BridgeStageRecord canNotMoveNextStage 추가
GaBaljaintheroom Aug 25, 2023
f8c11ea
feat: GameCommand isBridgeRetryCommandR 추가
GaBaljaintheroom Aug 25, 2023
e6129d7
feat: BridgeGameController ifCanNotMoveNextStageThenRetryGameOrQuit 추가
GaBaljaintheroom Aug 25, 2023
e318e5e
test: 게임 재시작 시 현재 stage와 이동 여부를 기본값으로 reset되는지 확인
GaBaljaintheroom Aug 25, 2023
4c13756
test: main함수 작성
GaBaljaintheroom Aug 25, 2023
921bc5c
refactor: clearsAllStage 수정
GaBaljaintheroom Aug 25, 2023
8b0ab73
refactor: BridgeGame retry 수정
GaBaljaintheroom Aug 25, 2023
2a9373d
feat: BridgeGameController ifFailStageThenRetryGameOrQuit 생성
GaBaljaintheroom Aug 25, 2023
45e8311
feat: BridgeStageRecord get 추가
GaBaljaintheroom Aug 25, 2023
ac23282
feat: GameProgressMessage 메세지 추가
GaBaljaintheroom Aug 25, 2023
36af97b
feat: GameResult 생성
GaBaljaintheroom Aug 25, 2023
7cd8fc1
feat: 입출력 수정
GaBaljaintheroom Aug 25, 2023
4d6a252
refactor: 폴더 구조 변경
GaBaljaintheroom Aug 25, 2023
bc3b328
refactor: 메서드명 수정
GaBaljaintheroom Aug 25, 2023
592f8de
test: Bridge 게임 진행의 기본 상태가 true인지 확인
GaBaljaintheroom Aug 26, 2023
36b1916
test: Bridge 게임 진행의 기본 stage가 0인지 확인
GaBaljaintheroom Aug 26, 2023
cc7a7ce
test: bridge를 완주했을 때 false를 반환하는지 확인
GaBaljaintheroom Aug 26, 2023
e6a82f4
test: Bridge 게임의 다음 단계로 이동 시 stage가 1 증가하는지 확인
GaBaljaintheroom Aug 26, 2023
e385dcc
test: Bridge 게임의 상태가 이동할 수 없을 때 Record에 저장되는지 확인
GaBaljaintheroom Aug 26, 2023
6b25e96
test: Bridge 게임이 완주되었을 때 Record에 저장되는지 확인
GaBaljaintheroom Aug 26, 2023
a3229f1
refactor: 전체 테스트 수정
GaBaljaintheroom Aug 26, 2023
5e5a703
test: 게임 결과 메시지를 반환하는지 확인
GaBaljaintheroom Aug 26, 2023
6a7a5c9
docs: README.md 수정
GaBaljaintheroom Aug 26, 2023
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
67 changes: 67 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
## 기능 목록

### input
- [x] 다리 길이를 입력 받는다.
- 3~20 사이의 숫자이다.
- [x] 이동할 칸을 입력 받는다.
- 위 칸 -> U, 아래 칸 -> D
- [x] 재시작 여부를 입력 받는다.
- 재시작 -> R, 종료 -> Q

### inputValidator
- [x] 다리 길이 validate
- 숫자이다.
- 3~20사이의 숫자이다.
- [x] 이동할 칸 validate
- 대문자 영어이다.
- U or D이다.
- [x] 재시작 validate
- 대문자 영어이다.
- R or Q이다.

### output
1. 다리 화면 출력한다.
- [x] 이동한 칸을 건널 수 있다면 -> O 건널 수 없다면 X
- [x] 결과 출력한다.
- [x] 에러 출력한다.
- [x] 진행 메시지 출력한다.

### bridge
1. 다리 길이 만큼 다리를 저장한다.
- [x] List<String> 위 칸 -> U, 아래 칸 -> D
- 재시작해도 처음에 만든 다리로 재사용한다.

### BridgeMaker
- [x] 다리를 만든다.
- 랜덤 숫자 1 -> 위 칸, 0 -> 아래 칸

### BridgeMap
- [x] 게임 화면을 만든다.

### BridgeStageRecord
- [x] 게임 진행 결과를 기록한다.

## 상수 처리

### BridgeMapElement
-[x] 게임 화면 요소

### ErrorMessage
-[x] 에러 메시지

### GameCommand
-[x] 게임 명령어

### GameProgressMessage
-[x] 게임 진행 메시지

### GameResult
-[x] 게임 결정

## 에러 처리
- [x] 에러 발생시 [ERROR] 단어가 포함 되어있어야 한다.
- [x] 그 부분 부터 다시 입력 받는다.

- [x] 다리 길이는 3~20 사이의 숫자이다.
- [x] 이동할 칸 명령어는 'U', 'D' 이다.
- [x] 재시작 여부 명령어는 'R', 'Q' 이다.
5 changes: 4 additions & 1 deletion src/main/java/bridge/Application.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package bridge;

import bridge.controller.BridgeGameController;

public class Application {

public static void main(String[] args) {
// TODO: 프로그램 구현
BridgeGameController bridgeGameController = new BridgeGameController();
bridgeGameController.startGame();
}
}
23 changes: 0 additions & 23 deletions src/main/java/bridge/BridgeGame.java

This file was deleted.

28 changes: 0 additions & 28 deletions src/main/java/bridge/InputView.java

This file was deleted.

23 changes: 0 additions & 23 deletions src/main/java/bridge/OutputView.java

This file was deleted.

29 changes: 29 additions & 0 deletions src/main/java/bridge/constant/BridgeMapElement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package bridge.constant;

public enum BridgeMapElement {
START("[ "),
SUCCESS("O"),
FAIL("X"),
DIVISION(" | "),
BLANK(" "),
END(" ]");

private final String value;

BridgeMapElement(String value) {
this.value = value;
}

@Override
public String toString() {
return value;
}

public static BridgeMapElement getStageWindowElement(boolean canMoveStage) {
if (canMoveStage){
return SUCCESS;
}
return FAIL;
}

}
26 changes: 26 additions & 0 deletions src/main/java/bridge/constant/ErrorMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package bridge.constant;

public enum ErrorMessage {

// bridge
BRIDGE_LENGTH_ERROR("다리 길이는 %s~%s 사이의 숫자입니다."),
BRIDGE_STAGE_COMMAND_ERROR("이동할 칸은 %s 혹은 %s 입니다."),
BRIDGE_RETRY_COMMAND_ERROR("게임 다시 시도 여부 명령어는 '%s' 혹은 '%s' 입니다."),

// global
INPUT_NOT_NUMBER_ERROR("숫자가 아닙니다."),
INPUT_NOT_UPPER_ENGLISH_ERROR("대문자 영어가 아닙니다.");


private static final String error = "[ERROR] ";
private final String message;


ErrorMessage(String message) {
this.message = message;
}

public String getMessage() {
return error + message;
}
}
49 changes: 49 additions & 0 deletions src/main/java/bridge/constant/GameCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package bridge.constant;

public enum GameCommand {
UP_STAIR("U"),
DOWN_STAIR("D"),
BRIDGE_RETRY("R"),
BRIDGE_QUITE("Q");


private final static int DOWN_RANDOM_NUMBER = 0;
private final String command;

GameCommand(String command) {
this.command = command;
}

public String getCommand() {
return command;
}

@Override
public String toString() {
return command;
}

public static String bridgeStageCase(int num){
if (num == DOWN_RANDOM_NUMBER){
return DOWN_STAIR.getCommand();
}
return UP_STAIR.getCommand();
}

public static boolean isNotBridgeStageCommand(String bridgeStage) {
return !bridgeStage.equals(UP_STAIR.getCommand()) && !bridgeStage.equals(DOWN_STAIR.getCommand());
}

public static boolean isBridgeStageCommandU(String bridgeStage){
return bridgeStage.equals(UP_STAIR.getCommand());
}

public static boolean isNotBridgeRetryCommand(String bridgeRetry){
return !bridgeRetry.equals(BRIDGE_RETRY.getCommand()) && !bridgeRetry.equals(BRIDGE_QUITE.getCommand());
}

public static boolean isBridgeRetryCommandR(String bridgeRetry){
return bridgeRetry.equals(BRIDGE_RETRY.getCommand());
}

}
27 changes: 27 additions & 0 deletions src/main/java/bridge/constant/GameProgressMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package bridge.constant;

public enum GameProgressMessage {

BRIDGE_GAME_START("다리 건너기 게임을 시작합니다."),

// input
INPUT_BRIDGE_LENGTH("다리의 길이를 입력해주세요."),
INPUT_BRIDGE_STAGE("이동할 칸을 선택해주세요. (위: %s, 아래: %s)"),
INPUT_BRIDGE_RETRY("게임을 다시 시도할지 여부를 입력해주세요. (재시도: %s, 종료: %s)"),

//output
OUTPUT_FINAL_GAME_RESULT("최종 게임 결과"),
OUTPUT_BRIDGE_SUCCESS_OR_NOT("게임 성공 여부: %s"),
OUTPUT_BRIDGE_ATTEMPT_RESULT("총 시도한 횟수: %d");

private final String message;

GameProgressMessage(String message) {
this.message = message;
}

@Override
public String toString() {
return message;
}
}
28 changes: 28 additions & 0 deletions src/main/java/bridge/constant/GameResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package bridge.constant;

import bridge.model.BridgeStageRecord;

public enum GameResult {


GAME_SUCCESS("성공"),
GAME_FAILED("실패");

private final String message;

GameResult(String message) {
this.message = message;
}

public static String gameResult(){
if (BridgeStageRecord.clearsGame()){
return GAME_SUCCESS.message;
}
return GAME_FAILED.message;
}

@Override
public String toString() {
return message;
}
}
46 changes: 46 additions & 0 deletions src/main/java/bridge/controller/BridgeGameController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package bridge.controller;

import bridge.model.BridgeGame;
import bridge.model.BridgeStageRecord;
import bridge.view.InputView;
import bridge.view.OutputView;

public class BridgeGameController {

private final InputView inputView;
private final OutputView outputView;
private final BridgeGame bridgeGame;

public BridgeGameController() {
this.inputView = new InputView();
this.outputView = new OutputView();
this.bridgeGame = new BridgeGame();
}

public void startGame(){
makeGame();
progressGame();
}

private void makeGame() {
outputView.printGameStart();
int bridgeSize = inputView.readBridgeSize();
bridgeGame.makeBridge(bridgeSize);
}

private void progressGame() {
while (BridgeStageRecord.isProgressing()){
String stage = inputView.readMoving();
bridgeGame.move(stage);
outputView.printMap(bridgeGame.getBridgeMap());
ifFailStageThenRetryGameOrQuit();
}
outputView.printResult(bridgeGame.getBridgeMap());
}

private void ifFailStageThenRetryGameOrQuit(){
if (BridgeStageRecord.canNotMoveNextStage()){
bridgeGame.retry(inputView.readGameCommand());
}
}
}
29 changes: 29 additions & 0 deletions src/main/java/bridge/model/Bridge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package bridge.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Bridge {
private static final int DEFAULT_STAGE_NUM = 1;
private final List<String> bridge;
public Bridge(List<String> bridge) {
this.bridge = new ArrayList<>(bridge);
}

public List<String> getBridge() {
return Collections.unmodifiableList(bridge);
}

public int stages(){
return bridge.size();
}

public boolean canMoveStage(String bridgeStage, int curStage){
return bridge.get(curStage).equals(bridgeStage);
}

public boolean clearsAllStage(int curStage, boolean canMoveStage) {
return canMoveStage && stages() == curStage+DEFAULT_STAGE_NUM;
}
}
Loading