-
Notifications
You must be signed in to change notification settings - Fork 0
숫자 야구 게임 [sjiwon] #1
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
sjiwon
wants to merge
26
commits into
main
Choose a base branch
from
sjiwon
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 1 commit
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
67acfb9
docs: 기본 기능 및 모델링에 대한 README.md 작성
sjiwon d1eef0e
feat: Baseballs 관련 상수 인터페이스 구현
sjiwon 7077cce
feat: Baseballs 모델 구현 및 예외 케이스 검증
sjiwon bd0fecc
test: Baseballs 테스트 케이스 작성
sjiwon 2da9bf0
feat: Computer 모델 구현 및 테스트 케이스 작성
sjiwon 312f766
feat: User 모델 구현 및 테스트 케이스 작성
sjiwon 55bee8e
feat: 게임 결과 명세를 위한 Result 모델 구현
sjiwon 6ffb501
feat: 게임 결과 도출을 위한 Referee 모델 구현 및 테스트 케이스 작성
sjiwon 1dde87d
feat: 게임 진행 상태 Tracking을 위한 GameStatus 구현 및 테스트 케이스 작성
sjiwon 7a3481e
feat: 게임 재시작 관련 GameProcessDecider 구현 및 테스트 케이스 작성
sjiwon ed74d6e
feat: 사용자 Input을 위한 InputView 구현
sjiwon cb910f1
feat: 콘솔 출력을 위한 OutputView 구현
sjiwon 7150851
feat: 게임 프로세싱을 위한 GameController 및 Application 동작 처리
sjiwon f28211a
test: Controller 테스트 케이스 추가
sjiwon 7f0707b
refactor: 사용자 숫자 Input시 Baseballs 수만큼 입력했는지 검증 추가
sjiwon b0dabea
refactor: 사용자 Input에 대한 Length 검증 -> 공백 존재 검증 케이스로 수정
sjiwon ba99c7e
refactor: SPACE -> SEPARATOR 네이밍 수정
sjiwon 36107ff
fix: 컴퓨터 Baseballs 랜덤 생성 관련 not equal -> less 조건으로 수정
sjiwon 10961ce
test: Computer Baseballs 랜덤 생성 관련 테스트 케이스 추가
sjiwon e619cf8
refactor: readUserBaseballInput 접근제어자 public -> private
sjiwon 95f69e0
refactor: Computer baseballs 생성 간 내부 로직 메소드화
sjiwon 0e47d89
refactor: Referee strikeCount 계산 로직 간 filter comparing method 분리
sjiwon d71a429
refactor: ExceptionConstants class -> interface
sjiwon 56cf0e5
refactor: 사용자 Input I/O간 검증 순서 수정
sjiwon 991a5d9
refactor: hasSpace 메소드 위치 수정
sjiwon bdb2346
fix: UserTest간 new Baseball -> new User로 수정
sjiwon 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 |
|---|---|---|
|
|
@@ -104,3 +104,5 @@ | |
| ### `GameController` | ||
|
|
||
| - 게임 진행과 관련된 컨트롤러 | ||
|
|
||
| <br> | ||
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,9 @@ | ||
| package baseball; | ||
|
|
||
| import baseball.controller.GameController; | ||
|
|
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| // TODO: 프로그램 구현 | ||
| new GameController().run(); | ||
| } | ||
| } |
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,67 @@ | ||
| package baseball.controller; | ||
|
|
||
| import baseball.model.*; | ||
| import baseball.view.InputView; | ||
| import baseball.view.OutputView; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static baseball.model.GameProcessDecider.GAME_RESTART; | ||
| import static baseball.model.GameStatus.GAME_RUNNING; | ||
| import static baseball.model.GameStatus.GAME_TERMINATE; | ||
|
|
||
| public class GameController { | ||
| private static GameStatus gameStatus; | ||
| private Computer computer; | ||
| private User user; | ||
|
|
||
| public GameController() { | ||
| computer = new Computer(); | ||
| gameStatus = GAME_RUNNING; | ||
| } | ||
|
|
||
| public void run() { | ||
| // 게임 시작 | ||
| OutputView.printGameStart(); | ||
|
|
||
| while (gameStatus.isGameNotTerminated()) { | ||
| // User - Baseball 입력 | ||
| readUserBaseballInput(); | ||
|
|
||
| // 게임 결과 확인 | ||
| Result result = judgeGameByReferee(); | ||
| OutputView.printGameResult(result); | ||
|
|
||
| // 게임 클리어 확인 | ||
| checkGameClear(result); | ||
| } | ||
| } | ||
|
|
||
| public void readUserBaseballInput() { | ||
| List<Integer> userBaseballs = InputView.readUserBaseballInput(); | ||
| user = new User(userBaseballs); | ||
| } | ||
|
|
||
| private Result judgeGameByReferee() { | ||
| return Referee.judge(computer.getBaseballs(), user.getBaseballs()); | ||
| } | ||
|
|
||
| private void checkGameClear(final Result result) { | ||
| if (result.isGameClear()) { | ||
| OutputView.printGameClear(); | ||
| determineGameRestartOrEnd(); | ||
| } | ||
| } | ||
|
|
||
| private void determineGameRestartOrEnd() { | ||
| int userCommand = InputView.readUserRestartCommandInput(); | ||
| GameProcessDecider decider = GameProcessDecider.getDecider(userCommand); | ||
|
|
||
| if (decider == GAME_RESTART) { | ||
| computer = new Computer(); | ||
| gameStatus = GAME_RUNNING; | ||
| } else { | ||
| gameStatus = GAME_TERMINATE; | ||
| } | ||
| } | ||
| } | ||
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.
https://github.com/kgu-woowa/woowa-java-baseball/blob/ba99c7e7ad9b5457bf2937dd3b69bfc7066dbdb7/src/main/java/baseball/controller/GameController.java#L40-L43
위 코드를 보면 while문을 돌면서 readUserBaseballInput()에서 입력을 받을 때마다 User 객체를 생성하고
https://github.com/kgu-woowa/woowa-java-baseball/blob/ba99c7e7ad9b5457bf2937dd3b69bfc7066dbdb7/src/main/java/baseball/model/User.java#L8-L10
위 코드에서 User 객체를 만들 때마다 Baseballs 객체를 생성하게 되는데 이러면 사용자가 숫자를 입력 할 때마다 메모리를 먹게 될 것 같고
또 한 번의 게임에서 숫자 입력마다 사용자를 새로 생성하는 것은 요구사항에 안 좋게 보일 수 있을 거 같은데 어떻게 생각하시나요?
Uh oh!
There was an error while loading. Please reload this page.
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.
코드 구조상 게임을 클리어한 후 사용자가
재시작 [1] Command를 요청했을 경우 게임을 다시 시작하는데 여기서 다시 시작하는 부분은 요구사항 이해에 따라서 다르긴한데 저는완전히 새로운 게임으로 판단하였고 그에 따라서determineGameRestartOrEnd -> new Computer() / readUserBaseballInput -> new User(~~)로 초기화를 하는게 깔끔하다고 생각했습니다.메모리 관련 부분은 사실 Computer나 User나 그렇게 큰 리소스를 잡아먹는다고 생각하지 않고 내부에서 관리하는 List또한 어차피 필드 자체는 3개로 제한되기 때문에 이 부분이 메모리에 큰 영향을 준다고 생각은 하지 않습니다