-
Notifications
You must be signed in to change notification settings - Fork 5
[숫자 야구] 정현우 미션 제출합니다. #5
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
jiffyin7
wants to merge
14
commits into
woowacourse-java-study:main
Choose a base branch
from
jiffyin7:Time
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
14 commits
Select commit
Hold shift + click to select a range
3a3f31f
docs(Readme): Start
hyeonwoody d317ec3
docs(Readme): 기능 요구사항 정리
hyeonwoody 276023f
feat(Outputview): 게임시작 문구 출력
hyeonwoody ffd5294
feat(BaseNumber): 1~9 범위 3개의 중복되지 않는 숫자 생성
hyeonwoody 395fbf9
feat(InputView): 숫자 추측 입력
hyeonwoody 681889e
feat(GuessNumber): 숫자 추측 입력 검증 및 객체화
hyeonwoody e7af530
feat(GuessResult): 숫자 추측 결과 연산 및 반환
hyeonwoody 59e00bd
feat(OutputView): 추측 결과 출력
hyeonwoody be2aba3
feat(GameController): 게임 종료 후 재시도 로직 구현
hyeonwoody 29bb23c
feat(GameController): 중복되는 숫자 입력 예외처리
hyeonwoody a1a121a
refactor(BaseNumber): 불필요한 로직 제거
hyeonwoody 5041ef1
refactor(BaseNumber): 생성 로직 변경
hyeonwoody 381314b
feat(GameController): 게임 재시작 /종료 예외처리
hyeonwoody 43be646
test(BaseNumber): 테스트 코드 작성
hyeonwoody 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
Binary file not shown.
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,6 +1,6 @@ | ||
| distributionBase=GRADLE_USER_HOME | ||
| distributionPath=wrapper/dists | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip | ||
| networkTimeout=10000 | ||
| zipStoreBase=GRADLE_USER_HOME | ||
| zipStorePath=wrapper/dists |
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,92 +1,92 @@ | ||
| @rem | ||
| @rem Copyright 2015 the original author or authors. | ||
| @rem | ||
| @rem Licensed under the Apache License, Version 2.0 (the "License"); | ||
| @rem you may not use this file except in compliance with the License. | ||
| @rem You may obtain a copy of the License at | ||
| @rem | ||
| @rem https://www.apache.org/licenses/LICENSE-2.0 | ||
| @rem | ||
| @rem Unless required by applicable law or agreed to in writing, software | ||
| @rem distributed under the License is distributed on an "AS IS" BASIS, | ||
| @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| @rem See the License for the specific language governing permissions and | ||
| @rem limitations under the License. | ||
| @rem | ||
|
|
||
| @if "%DEBUG%"=="" @echo off | ||
| @rem ########################################################################## | ||
| @rem | ||
| @rem Gradle startup script for Windows | ||
| @rem | ||
| @rem ########################################################################## | ||
|
|
||
| @rem Set local scope for the variables with windows NT shell | ||
| if "%OS%"=="Windows_NT" setlocal | ||
|
|
||
| set DIRNAME=%~dp0 | ||
| if "%DIRNAME%"=="" set DIRNAME=. | ||
| @rem This is normally unused | ||
| set APP_BASE_NAME=%~n0 | ||
| set APP_HOME=%DIRNAME% | ||
|
|
||
| @rem Resolve any "." and ".." in APP_HOME to make it shorter. | ||
| for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi | ||
|
|
||
| @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. | ||
| set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" | ||
|
|
||
| @rem Find java.exe | ||
| if defined JAVA_HOME goto findJavaFromJavaHome | ||
|
|
||
| set JAVA_EXE=java.exe | ||
| %JAVA_EXE% -version >NUL 2>&1 | ||
| if %ERRORLEVEL% equ 0 goto execute | ||
|
|
||
| echo. | ||
| echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. | ||
| echo. | ||
| echo Please set the JAVA_HOME variable in your environment to match the | ||
| echo location of your Java installation. | ||
|
|
||
| goto fail | ||
|
|
||
| :findJavaFromJavaHome | ||
| set JAVA_HOME=%JAVA_HOME:"=% | ||
| set JAVA_EXE=%JAVA_HOME%/bin/java.exe | ||
|
|
||
| if exist "%JAVA_EXE%" goto execute | ||
|
|
||
| echo. | ||
| echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% | ||
| echo. | ||
| echo Please set the JAVA_HOME variable in your environment to match the | ||
| echo location of your Java installation. | ||
|
|
||
| goto fail | ||
|
|
||
| :execute | ||
| @rem Setup the command line | ||
|
|
||
| set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar | ||
|
|
||
|
|
||
| @rem Execute Gradle | ||
| "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* | ||
|
|
||
| :end | ||
| @rem End local scope for the variables with windows NT shell | ||
| if %ERRORLEVEL% equ 0 goto mainEnd | ||
|
|
||
| :fail | ||
| rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of | ||
| rem the _cmd.exe /c_ return code! | ||
| set EXIT_CODE=%ERRORLEVEL% | ||
| if %EXIT_CODE% equ 0 set EXIT_CODE=1 | ||
| if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% | ||
| exit /b %EXIT_CODE% | ||
|
|
||
| :mainEnd | ||
| if "%OS%"=="Windows_NT" endlocal | ||
|
|
||
| :omega | ||
| @rem | ||
| @rem Copyright 2015 the original author or authors. | ||
| @rem | ||
| @rem Licensed under the Apache License, Version 2.0 (the "License"); | ||
| @rem you may not use this file except in compliance with the License. | ||
| @rem You may obtain a copy of the License at | ||
| @rem | ||
| @rem https://www.apache.org/licenses/LICENSE-2.0 | ||
| @rem | ||
| @rem Unless required by applicable law or agreed to in writing, software | ||
| @rem distributed under the License is distributed on an "AS IS" BASIS, | ||
| @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| @rem See the License for the specific language governing permissions and | ||
| @rem limitations under the License. | ||
| @rem | ||
| @if "%DEBUG%"=="" @echo off | ||
| @rem ########################################################################## | ||
| @rem | ||
| @rem Gradle startup script for Windows | ||
| @rem | ||
| @rem ########################################################################## | ||
| @rem Set local scope for the variables with windows NT shell | ||
| if "%OS%"=="Windows_NT" setlocal | ||
| set DIRNAME=%~dp0 | ||
| if "%DIRNAME%"=="" set DIRNAME=. | ||
| @rem This is normally unused | ||
| set APP_BASE_NAME=%~n0 | ||
| set APP_HOME=%DIRNAME% | ||
| @rem Resolve any "." and ".." in APP_HOME to make it shorter. | ||
| for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi | ||
| @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. | ||
| set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" | ||
| @rem Find java.exe | ||
| if defined JAVA_HOME goto findJavaFromJavaHome | ||
| set JAVA_EXE=java.exe | ||
| %JAVA_EXE% -version >NUL 2>&1 | ||
| if %ERRORLEVEL% equ 0 goto execute | ||
| echo. | ||
| echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. | ||
| echo. | ||
| echo Please set the JAVA_HOME variable in your environment to match the | ||
| echo location of your Java installation. | ||
| goto fail | ||
| :findJavaFromJavaHome | ||
| set JAVA_HOME=%JAVA_HOME:"=% | ||
| set JAVA_EXE=%JAVA_HOME%/bin/java.exe | ||
| if exist "%JAVA_EXE%" goto execute | ||
| echo. | ||
| echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% | ||
| echo. | ||
| echo Please set the JAVA_HOME variable in your environment to match the | ||
| echo location of your Java installation. | ||
| goto fail | ||
| :execute | ||
| @rem Setup the command line | ||
| set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar | ||
| @rem Execute Gradle | ||
| "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* | ||
| :end | ||
| @rem End local scope for the variables with windows NT shell | ||
| if %ERRORLEVEL% equ 0 goto mainEnd | ||
| :fail | ||
| rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of | ||
| rem the _cmd.exe /c_ return code! | ||
| set EXIT_CODE=%ERRORLEVEL% | ||
| if %EXIT_CODE% equ 0 set EXIT_CODE=1 | ||
| if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% | ||
| exit /b %EXIT_CODE% | ||
| :mainEnd | ||
| if "%OS%"=="Windows_NT" endlocal | ||
| :omega |
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,23 @@ | ||
| # 기능요구사항 | ||
| - Exception | ||
|
|
||
| - GameController | ||
| - 서로 다른 3 랜덤 숫자 생성 | ||
| - 사용자 랜덤 숫자 추측 입력 | ||
| - 추측 결과 출력 | ||
| - 게임 재시작 / 종료 여부 입력 | ||
| - 게임 재시작 / 종료 | ||
|
|
||
| - Number | ||
| - 숫자 유효성 검사 | ||
| - 추측 결과 반환 | ||
|
|
||
| - InputView | ||
| - 서로 다른 3자리의 수 | ||
| - 게임 재시작 / 종료 (1 / 2) | ||
|
|
||
| - OutputView | ||
| - 게임 시작 문구 | ||
| - 입력한 숫자에 대한 결과 출력 | ||
| - 볼, 스트라이크 개수로 표시 | ||
| - 3개의 숫자 모두 맞힐 경우 게임 종료 |
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,14 @@ | ||
| package baseball; | ||
|
|
||
| import baseball.game.controller.GameController; | ||
| import baseball.view.Inputview; | ||
| import baseball.view.OutputView; | ||
|
|
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| // TODO: 프로그램 구현 | ||
| OutputView outputView = new OutputView(); | ||
| Inputview inputview = new Inputview(); | ||
| GameController gameController = new GameController(outputView, inputview); | ||
| gameController.play(); | ||
| } | ||
| } |
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,66 @@ | ||
| package baseball.baseNumber; | ||
|
|
||
| import baseball.game.controller.constant.Rules; | ||
| import baseball.guessNumber.GuessNumber; | ||
| import baseball.guessResult.GuessResult; | ||
| import camp.nextstep.edu.missionutils.Randoms; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| public class BaseNumber { | ||
| private final List<Integer> numbers; | ||
|
|
||
| public BaseNumber(List<Integer> numbers) { | ||
| this.numbers = new ArrayList<>(numbers); | ||
| } | ||
|
|
||
| public static BaseNumber from(Set<Integer> numbers) { | ||
| validateCount(numbers); | ||
| return new BaseNumber(numbers.stream().toList()); | ||
| } | ||
|
|
||
| private static void validateCount(Set<Integer> numbers) { | ||
| if (numbers.size() != Rules.BASE_NUMBER_COUNT) { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| public GuessResult match(GuessNumber guessNumber) { | ||
| int strike = checkStrike(guessNumber); | ||
| int temporaryBall = checkTemporaryBall(guessNumber); | ||
| return GuessResult.from(strike, temporaryBall - strike); | ||
| } | ||
|
|
||
| private int checkStrike(GuessNumber guessNumber) { | ||
| int strike = 0; | ||
| for (int i = 0; i < Rules.BASE_NUMBER_COUNT; ++i) { | ||
| int singleGuessNumber = guessNumber.numbers.get(i); | ||
| if (isStrike(singleGuessNumber, numbers.get(i))) { | ||
| strike++; | ||
| } | ||
| } | ||
| return strike; | ||
| } | ||
|
|
||
| private int checkTemporaryBall(GuessNumber guessNumber) { | ||
| int ball = 0; | ||
| for (int i = 0; i < Rules.BASE_NUMBER_COUNT; ++i) { | ||
| if (isBall(guessNumber.numbers.get(i))) { | ||
| ball++; | ||
| } | ||
| } | ||
| return ball; | ||
| } | ||
|
|
||
| private boolean isStrike(int guessNumber, int baseNumber) { | ||
| return guessNumber == baseNumber; | ||
| } | ||
|
|
||
| private boolean isBall(int singleGuessNumber) { | ||
| return numbers.contains(singleGuessNumber); | ||
| } | ||
| } | ||
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.
조그만 부분이지만,
temporaryBall이 조금 와닿지 않습니다! 아래temporaryBall - strike까지 봐야 이해할 수 있었어요. 다른 메서드명과 변수명을 시도해보면 좋을 것 같습니다.