-
Notifications
You must be signed in to change notification settings - Fork 5
[야구게임] 박진현 리뷰부탁드립니다 #4
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
Open
tiemo0708
wants to merge
16
commits into
woowacourse-java-study:main
Choose a base branch
from
tiemo0708:tiemo0708
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
630aa2e
docs: 기능목록 작성
tiemo0708 85a566a
feat: 야구게임 숫자 입력 기능
tiemo0708 6b28aec
feat: 야구게임 숫자 입력 검증 기능
tiemo0708 80dd380
feat: 야구게임 숫자 랜덤생성기능
tiemo0708 2cedc9c
fix: 오류메시지 수정
tiemo0708 0e14cc7
feat: 랜덤 생성하 번호를 저장하는기능
tiemo0708 63a2cb9
feat: 스트라이크와 볼을 계산하는 기능
tiemo0708 44a9ba2
feat: 스트라이크와 볼 개수를 출력하는 기능
tiemo0708 968d6a3
feat: 3스트라이크가 될때까지 반복하는 기능
tiemo0708 afc1842
refactor: 클래스 이름 변경
tiemo0708 e49eae4
feat: 게임 재시작 기능
tiemo0708 c533998
fix: 예외처리 수정
tiemo0708 e0f361f
fix: 선택 번호 오류 수정
tiemo0708 44c803a
refactor: 메서드 분리
tiemo0708 d240b53
feat: 중복된 숫자 예외처리 기능
tiemo0708 98d166b
docs: 구현목록 업데이트
tiemo0708 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,144 +1,61 @@ | ||
| # 미션 - 숫자 야구 | ||
|
|
||
| ## 🔍 진행 방식 | ||
| ### 구현할 기능목록 | ||
|
|
||
| - 미션은 **기능 요구 사항, 프로그래밍 요구 사항, 과제 진행 요구 사항** 세 가지로 구성되어 있다. | ||
| - 세 개의 요구 사항을 만족하기 위해 노력한다. 특히 기능을 구현하기 전에 기능 목록을 만든다. | ||
| - 기능 요구 사항에 기재되지 않은 내용은 스스로 판단하여 구현한다. | ||
| **3자리수 생성** | ||
|
|
||
| ## 📮 미션 제출 방법 | ||
| - [x] 1에서 9까지의 서로 다른 수로 이루어진 3자리 숫자를 생성한다. | ||
|
|
||
| - 미션 구현을 완료한 후 GitHub을 통해 제출해야 한다. | ||
| - GitHub을 활용한 제출 방법은 [프리코스 과제 제출](https://github.com/woowacourse/woowacourse-docs/tree/master/precourse) 문서를 참고해 | ||
| 제출한다. | ||
| - GitHub에 미션을 제출한 후 [우아한테크코스 지원](https://apply.techcourse.co.kr) 사이트에 접속하여 프리코스 과제를 제출한다. | ||
| - 자세한 방법은 [제출 가이드](https://github.com/woowacourse/woowacourse-docs/tree/master/precourse#제출-가이드) 참고 | ||
| - **Pull Request만 보내고 지원 플랫폼에서 과제를 제출하지 않으면 최종 제출하지 않은 것으로 처리되니 주의한다.** | ||
| **사용자 입력** | ||
|
|
||
| ## 🚨 과제 제출 전 체크 리스트 - 0점 방지 | ||
| - [x] 사용자에게 중복없는 세자리 숫자를 입력 받는다 | ||
|
|
||
| - 기능 구현을 모두 정상적으로 했더라도 **요구 사항에 명시된 출력값 형식을 지키지 않을 경우 0점으로 처리**한다. | ||
| - 기능 구현을 완료한 뒤 아래 가이드에 따라 테스트를 실행했을 때 모든 테스트가 성공하는지 확인한다. | ||
| - **테스트가 실패할 경우 0점으로 처리**되므로, 반드시 확인 후 제출한다. | ||
| **야구 게임 진행** | ||
|
|
||
| ### 테스트 실행 가이드 | ||
| - [x] 랜덤 생성한 세자리 숫자와 사용자에게 입력받은 세자리 숫자를 비교한다. | ||
| - [x] 같은 숫자가 같은 자리에 있을 때 스트라이크를 출력한다 | ||
| - [x] 같은 숫자이지만 다른 자리에 있을 때 볼을 출력한다 | ||
| - [x] 일치하는 숫자가 하나도 없을 경우 낫싱을 출력한다 | ||
|
|
||
| - 터미널에서 `java -version`을 실행하여 Java 버전이 17인지 확인한다. | ||
| Eclipse 또는 IntelliJ IDEA와 같은 IDE에서 Java 17로 실행되는지 확인한다. | ||
| - 터미널에서 Mac 또는 Linux 사용자의 경우 `./gradlew clean test` 명령을 실행하고, | ||
| Windows 사용자의 경우 `gradlew.bat clean test` 또는 `./gradlew.bat clean test` 명령을 실행할 때 모든 테스트가 아래와 같이 통과하는지 확인한다. | ||
| 예시: | ||
|
|
||
| ``` | ||
| BUILD SUCCESSFUL in 0s | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 🚀 기능 요구 사항 | ||
|
|
||
| 기본적으로 1부터 9까지 서로 다른 수로 이루어진 3자리의 수를 맞추는 게임이다. | ||
|
|
||
| - 같은 수가 같은 자리에 있으면 스트라이크, 다른 자리에 있으면 볼, 같은 수가 전혀 없으면 낫싱이란 힌트를 얻고, 그 힌트를 이용해서 먼저 상대방(컴퓨터)의 수를 맞추면 승리한다. | ||
| - 예) 상대방(컴퓨터)의 수가 425일 때 | ||
| - 123을 제시한 경우 : 1스트라이크 | ||
| - 456을 제시한 경우 : 1볼 1스트라이크 | ||
| - 789를 제시한 경우 : 낫싱 | ||
| - 위 숫자 야구 게임에서 상대방의 역할을 컴퓨터가 한다. 컴퓨터는 1에서 9까지 서로 다른 임의의 수 3개를 선택한다. 게임 플레이어는 컴퓨터가 생각하고 있는 서로 다른 3개의 숫자를 입력하고, 컴퓨터는 입력한 숫자에 대한 | ||
| 결과를 출력한다. | ||
| - 이 같은 과정을 반복해 컴퓨터가 선택한 3개의 숫자를 모두 맞히면 게임이 종료된다. | ||
| - 게임을 종료한 후 게임을 다시 시작하거나 완전히 종료할 수 있다. | ||
| - 사용자가 잘못된 값을 입력할 경우 `IllegalArgumentException`을 발생시킨 후 애플리케이션은 종료되어야 한다. | ||
|
|
||
| ### 입출력 요구 사항 | ||
|
|
||
| #### 입력 | ||
| 낫싱 | ||
|
|
||
| - 서로 다른 3자리의 수 | ||
| - 게임이 끝난 경우 재시작/종료를 구분하는 1과 2 중 하나의 수 | ||
| ``` | ||
|
|
||
| #### 출력 | ||
| - [x] 볼과 스트라이크과 동시에 있을 경우 볼 스트라이크 순서로 출력한다 | ||
|
|
||
| - 입력한 수에 대한 결과를 볼, 스트라이크 개수로 표시 | ||
| 예시: | ||
|
|
||
| ``` | ||
| 1볼 1스트라이크 | ||
| ``` | ||
|
|
||
| - 하나도 없는 경우 | ||
|
|
||
| ``` | ||
| 낫싱 | ||
| ``` | ||
|
|
||
| - 3개의 숫자를 모두 맞힐 경우 | ||
| - [x] 3개의 숫자를 모두 맞힐 경우 3스트라이크 와 게임 종료 메시지를 출력한다 | ||
|
|
||
| ``` | ||
| 3스트라이크 | ||
| 3개의 숫자를 모두 맞히셨습니다! 게임 종료 | ||
| ``` | ||
|
|
||
| - 게임 시작 문구 출력 | ||
|
|
||
| ``` | ||
| 숫자 야구 게임을 시작합니다. | ||
| ``` | ||
|
|
||
| #### 실행 결과 예시 | ||
| 예시: | ||
|
|
||
| ``` | ||
| 숫자 야구 게임을 시작합니다. | ||
| 숫자를 입력해주세요 : 123 | ||
| 1볼 1스트라이크 | ||
| 숫자를 입력해주세요 : 145 | ||
| 1볼 | ||
| 숫자를 입력해주세요 : 671 | ||
| 2볼 | ||
| 숫자를 입력해주세요 : 216 | ||
| 1스트라이크 | ||
| 숫자를 입력해주세요 : 713 | ||
| 3스트라이크 | ||
| 3개의 숫자를 모두 맞히셨습니다! 게임 종료 | ||
| 게임을 새로 시작하려면 1, 종료하려면 2를 입력하세요. | ||
| 1 | ||
| 숫자를 입력해주세요 : 123 | ||
| 1볼 | ||
| ... | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 🎯 프로그래밍 요구 사항 | ||
|
|
||
| - JDK 17 버전에서 실행 가능해야 한다. **JDK 17에서 정상적으로 동작하지 않을 경우 0점 처리한다.** | ||
| - 프로그램 실행의 시작점은 `Application`의 `main()`이다. | ||
| - `build.gradle` 파일을 변경할 수 없고, 외부 라이브러리를 사용하지 않는다. | ||
| - [Java 코드 컨벤션](https://github.com/woowacourse/woowacourse-docs/tree/master/styleguide/java) 가이드를 준수하며 프로그래밍한다. | ||
| - 프로그램 종료 시 `System.exit()`를 호출하지 않는다. | ||
| - 프로그램 구현이 완료되면 `ApplicationTest`의 모든 테스트가 성공해야 한다. **테스트가 실패할 경우 0점 처리한다.** | ||
| - 프로그래밍 요구 사항에서 달리 명시하지 않는 한 파일, 패키지 이름을 수정하거나 이동하지 않는다. | ||
| ``` | ||
|
|
||
| ### 라이브러리 | ||
| **게임 진행 & 종료-사용자 입력** | ||
|
|
||
| - `camp.nextstep.edu.missionutils`에서 제공하는 `Randoms` 및 `Console` API를 사용하여 구현해야 한다. | ||
| - Random 값 추출은 `camp.nextstep.edu.missionutils.Randoms`의 `pickNumberInRange()`를 활용한다. | ||
| - 사용자가 입력하는 값은 `camp.nextstep.edu.missionutils.Console`의 `readLine()`을 활용한다. | ||
| - [x] 게임이 끝났을시 재시작 여부를 확인한다 | ||
| - [x] 1이면 재시작, 2면 종료 | ||
|
|
||
| #### 사용 예시 | ||
| ### 예외처리 | ||
|
|
||
| ```java | ||
| List<Integer> computer = new ArrayList<>(); | ||
| while (computer.size() < 3) { | ||
| int randomNumber = Randoms.pickNumberInRange(1, 9); | ||
| if (!computer.contains(randomNumber)) { | ||
| computer.add(randomNumber); | ||
| } | ||
| } | ||
| ``` | ||
| **3자리 숫자 입력 부분** | ||
|
|
||
| --- | ||
| - [x] 3자리 숫자가 아닌 경우 | ||
| - [x] 중복된 숫자가 들어가는 경우 | ||
| - [x] 0이 들어가는 경우 | ||
|
|
||
| ## ✏️ 과제 진행 요구 사항 | ||
| **재시작 여부 입력 부분** | ||
|
|
||
| - 미션은 [java-baseball-6](https://github.com/woowacourse-precourse/java-baseball-6) 저장소를 Fork & Clone해 시작한다. | ||
| - **기능을 구현하기 전 `docs/README.md`에 구현할 기능 목록을 정리**해 추가한다. | ||
| - 과제 진행 및 제출 방법은 [프리코스 과제 제출](https://github.com/woowacourse/woowacourse-docs/tree/master/precourse) 문서를 참고한다. | ||
| - [x] 1또는 2가 아니면 예외처리 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,12 @@ | ||
| package baseball; | ||
|
|
||
| import baseball.config.Appconfig; | ||
| import baseball.controller.BaseballController; | ||
|
|
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| // TODO: 프로그램 구현 | ||
| Appconfig appConfig = new Appconfig(); | ||
| BaseballController baseballController = appConfig.baseballController(); | ||
| baseballController.start(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package baseball.config; | ||
|
|
||
| import baseball.controller.BaseballController; | ||
| import baseball.generator.BaseballNumberGenerator; | ||
| import baseball.generator.BaseballNumberGeneratorImpl; | ||
| import baseball.validation.InputNumberValidation; | ||
| import baseball.validation.InputNumberValidationImpl; | ||
| import baseball.validation.InputUserChoiceValidation; | ||
| import baseball.validation.InputUserChoiceValidationImpl; | ||
| import baseball.view.InputView; | ||
| import baseball.view.OutputView; | ||
|
|
||
| public class Appconfig { | ||
| public BaseballController baseballController() { | ||
| return new BaseballController(inputView(), outputView(), inputValidation(),baseballNumberGenerator(),inputUserChoiceValidation()); | ||
| } | ||
|
|
||
| public InputNumberValidation inputValidation(){ | ||
| return new InputNumberValidationImpl(); | ||
| } | ||
|
|
||
| public BaseballNumberGenerator baseballNumberGenerator(){ | ||
| return new BaseballNumberGeneratorImpl(); | ||
| } | ||
|
|
||
| public InputUserChoiceValidation inputUserChoiceValidation(){ | ||
| return new InputUserChoiceValidationImpl(); | ||
| } | ||
| public InputView inputView() { | ||
| return new InputView(); | ||
| } | ||
|
|
||
| public OutputView outputView() { | ||
| return new OutputView(); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| package baseball.controller; | ||
|
|
||
| import baseball.dto.ResultDTO; | ||
| import baseball.generator.BaseballNumberGenerator; | ||
| import baseball.model.Baseball; | ||
| import baseball.model.Referee; | ||
| import baseball.model.Result; | ||
| import baseball.validation.InputNumberValidation; | ||
| import baseball.validation.InputUserChoiceValidation; | ||
| import baseball.view.InputView; | ||
| import baseball.view.OutputView; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class BaseballController { | ||
| private final InputView inputView; | ||
| private final OutputView outputView; | ||
| private final InputNumberValidation inputNumberValidationImpl; | ||
| private final BaseballNumberGenerator baseballNumberGeneratorImpl; | ||
| private final InputUserChoiceValidation inputUserChoiceValidation; | ||
|
|
||
| public BaseballController(InputView inputView, OutputView outputView, InputNumberValidation inputNumberValidationImpl, BaseballNumberGenerator baseballNumberGeneratorImpl, InputUserChoiceValidation inputUserChoiceValidation) { | ||
| this.inputView = inputView; | ||
| this.outputView = outputView; | ||
| this.inputNumberValidationImpl = inputNumberValidationImpl; | ||
| this.baseballNumberGeneratorImpl = baseballNumberGeneratorImpl; | ||
| this.inputUserChoiceValidation = inputUserChoiceValidation; | ||
| } | ||
|
|
||
| public void start() { | ||
| inputView.printBaseballGameStart(); | ||
| boolean keepPlaying = true; | ||
| while (keepPlaying) { | ||
| keepPlaying = playGame(); | ||
| } | ||
| } | ||
|
|
||
| private boolean playGame() { | ||
| List<Integer> baseballNumber = baseballNumberGeneratorImpl.generate(); | ||
| Baseball baseball = new Baseball(baseballNumber); | ||
| boolean gameFinished = false; | ||
|
|
||
| while (!gameFinished) { | ||
| gameFinished = playTurn(baseball); | ||
| } | ||
|
|
||
| return processUserChoice(); | ||
| } | ||
|
|
||
| private boolean playTurn(Baseball baseball) { | ||
| String userNumber = inputNumberValidationImpl.validate(inputView.inputBasebalNumber()); | ||
| Result result = new Referee(baseball, userNumber).getResult(); | ||
| ResultDTO resultDTO = new ResultDTO(result.getStrikes(), result.getBalls()); | ||
| outputView.printResult(resultDTO); | ||
|
|
||
| return result.getStrikes() == 3; | ||
| } | ||
|
|
||
| private boolean processUserChoice() { | ||
| int userChoice = inputUserChoiceValidation.validate(inputView.restartGame()); | ||
| if (userChoice == 1) { | ||
| return true; | ||
| } | ||
| if (userChoice == 2) { | ||
| return false; | ||
| } | ||
| return false; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package baseball.dto; | ||
|
|
||
| public class ResultDTO { | ||
| private final int strikes; | ||
| private final int balls; | ||
|
|
||
| public ResultDTO(int strikes, int balls) { | ||
| this.strikes = strikes; | ||
| this.balls = balls; | ||
| } | ||
|
|
||
| public int getStrikes() { | ||
| return strikes; | ||
| } | ||
|
|
||
| public int getBalls() { | ||
| return balls; | ||
| } | ||
| } | ||
7 changes: 7 additions & 0 deletions
7
src/main/java/baseball/generator/BaseballNumberGenerator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package baseball.generator; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface BaseballNumberGenerator { | ||
| List<Integer> generate(); | ||
| } |
16 changes: 16 additions & 0 deletions
16
src/main/java/baseball/generator/BaseballNumberGeneratorImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package baseball.generator; | ||
|
|
||
| import camp.nextstep.edu.missionutils.Randoms; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class BaseballNumberGeneratorImpl implements BaseballNumberGenerator{ | ||
| private static final int BASEBALL_NUMBER_COUNT = 3; | ||
| private static final int MIN_BASEBALL_NUMBER = 1; | ||
| private static final int MAX_BASEBALL_NUMBER = 9; | ||
| @Override | ||
| public List<Integer> generate() { | ||
| return Randoms.pickUniqueNumbersInRange(MIN_BASEBALL_NUMBER, MAX_BASEBALL_NUMBER, BASEBALL_NUMBER_COUNT); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package baseball.model; | ||
|
|
||
| import baseball.utils.ErrorMessages; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class Baseball { | ||
| private final List<Integer> numbers; | ||
|
|
||
| public Baseball(List<Integer> numbers) { | ||
| validateRange(numbers); | ||
| validateNumberRange(numbers); | ||
| this.numbers = numbers; | ||
| } | ||
| private void validateRange(List<Integer> numbers) { | ||
| if (numbers.size() != 3) { | ||
| throw new IllegalArgumentException(ErrorMessages.INVALID_INPUT_COUNT); | ||
| } | ||
| } | ||
| private void validateNumberRange(List<Integer> numbers) { | ||
| if (numbers.stream().anyMatch(num -> num < 1 || num > 9)) { | ||
| throw new IllegalArgumentException(ErrorMessages.INVALID_NUMBER_RANGE); | ||
| } | ||
| } | ||
| public List<Integer> getNumbers() { | ||
| return numbers; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Result도메인과 이름말곤 똑같이 생겼는데 따로 만든 이유가 있으실까요?refree에서 return값을ResultDto로 하면 어땠을까요?