-
Notifications
You must be signed in to change notification settings - Fork 0
baseBall6 리팩토링 #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
paka-jo
wants to merge
6
commits into
main
Choose a base branch
from
pakajo
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
6 commits
Select commit
Hold shift + click to select a range
75b4060
init : readme파일 추가 및 삭제 된 클래스
paka-jo 968df78
refactor: computer클래스 및 judgement클래스 aiPlayer 클래스로 변경 및 코드 리팩토링
paka-jo e7f1cce
refactor: BallCounting 클래스명 변경 및 리팩토링 ,사용자 정의 exception에서 IllegalArgu…
paka-jo 8d12a02
feat : computer 클래스 역할 분리
paka-jo 4480e15
init: README파일 피드백 내용 주석 추가 (코드는 변경 없음, 추후 비교 예정으로 변경x)
paka-jo 6384bd3
no message
paka-jo 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 |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| ## Player 클래스 (사용자로 부터 숫자를 입력받음) | ||
| ### 기능 | ||
| - `guess()`: 사용자 입력을 받아 숫자 리스트로 반환 | ||
|
|
||
| ## AiPlayer 클래스 (상대방) | ||
| ### 기능 | ||
| - `correct()` :랜덤한 3자리의 숫자를 반환 | ||
| - `checkBallsAndStrikes()` : 입력받은 사용자의 숫자에 대해 결과를 볼,스트라이크,낫싱으로 결과값 반환 | ||
|
|
||
| ### 상태값 | ||
| - `ballcounting : BallCounting` | ||
| - `strike : String` | ||
| - `ball : String` | ||
| - `nothing : String` | ||
|
|
||
| ## GameHost 클래스 | ||
| ### 기능 | ||
| - `baseballGame()` : 게임 시작 문구를 출력합니다 | ||
| - `end()` : 3스트라이크 시 게임 종료 문구를 출력합니다 | ||
| - `askRestart()` : 1입력시 종료, 2 입력 시 재시작을 합니다 | ||
|
|
||
| ## BallCounting 클래스 | ||
| ### 기능 | ||
| - `setCorrect` : aiPlayer가 출력한 값을 가져옵니다 | ||
| - `setGuess` : 사용자가 예측한 숫자를 가져옵니다 | ||
| - `getStrike()` : 같은 자리의 숫자가 일치할 시 해당 횟수에 따라 스트라이크를 출력합니다 | ||
| - `getBall()` : 다른 자리의 숫자가 일치할 시 해당 횟수에 따라 볼을 출력합니다 | ||
| - `getNothing()` : 같은 숫자가 전혀 없을 시 낫싱을 출력합니다 | ||
|
|
||
| ### 상태값 | ||
| - `guess : List<Integer> ` | ||
| - `correct : List<Integer> ` | ||
|
|
||
| ## BaseballGame 클래스 | ||
| ### 기능 | ||
| - `runGame()` : 게임을 진행합니다 | ||
|
|
||
| ### 상태값 | ||
| - `gameHost : GameHost` | ||
| - `aiPlayer : AiPlayer` | ||
| - `ballCounting :BallCounting` | ||
| - `player : Player` | ||
|
|
||
| ## ExceptionMessage | ||
| ### 기능 | ||
| - `checkInputLength` : player 입력 숫자가 3자리에 대한 예외사항 | ||
|
|
||
| ## 리팩토링에 대한 피드백 내용 | ||
| - 현재 마크다운 문서는 클래스 중심으로 되어 있음 -> 앞으로는 객체중심으로 작성 | ||
| - 클래스와 객체 대한 이해와 공부가 필요함 | ||
| - 연관 관계가 과함 | ||
| - 필드에 대해서 초기화를 할 때 생성자를 만들어서 초기화 해도 된다 | ||
| ex) ``` public AiPlayer(BallCounting ballCounting) { | ||
| this.ballCounting = ballCounting; | ||
| } ``` | ||
| -> ``` public AiPlayer() { | ||
| this.ballCounting = new BallCuonting(); | ||
| }``` | ||
| - 클래스 명은 동사X, 명사 (Play 클래스 = 동사임) | ||
| - 메서드명을 좀 더 명확하게! | ||
| ex) `GameHost`에서 메서드명 `start` -> `printStart`, `end` -> `printEnd`, | ||
| `AiPlayer`에서 `correct`-> `pickRandomNumber` | ||
| - `Setter`는 최대한 사용x | ||
| - static 메서드에 대해서 공부해보고 `BallCounting` 클래스에서 활용 + 필드 선언이 필요x | ||
| - 객체 다이어그램을 그리고 시작하는것도 좋음 |
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,49 @@ | ||
| package baseball; | ||
|
|
||
| import camp.nextstep.edu.missionutils.Randoms; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class AiPlayer { | ||
|
|
||
| private final BallCounting ballCounting; | ||
| private String strike; | ||
| private String ball; | ||
| private String nothing; | ||
|
|
||
| public AiPlayer(BallCounting ballCounting) { | ||
| this.ballCounting = ballCounting; | ||
| } | ||
|
|
||
| public List<Integer> correct() { | ||
|
|
||
| List<Integer> computer = new ArrayList<>(); | ||
| while (computer.size() < 3) { | ||
| int randomNumber = Randoms.pickNumberInRange(1, 9); | ||
| if (!computer.contains(randomNumber)) { | ||
| computer.add(randomNumber); | ||
| } | ||
| } | ||
| return computer; | ||
| } | ||
|
|
||
| public String checkBallsAndStrikes(List<Integer> correct,List<Integer> guess){ | ||
| List<Integer> numberOfStrike = ballCounting.getStrike(correct,guess); | ||
| List<Integer> numberOfBall = ballCounting.getBall(correct,guess); | ||
| strike =""; | ||
| ball = ""; | ||
| nothing =""; | ||
|
|
||
| if(numberOfStrike.size()>0){ | ||
| strike = numberOfStrike.size() + "스트라이크"; | ||
| } | ||
| if(numberOfBall.size() >0) { | ||
| ball = numberOfBall.size() + "볼"; | ||
| } | ||
| if(numberOfStrike.size() == 0 && numberOfBall.size() == 0){ | ||
| nothing = ballCounting.getNothing(); | ||
| } | ||
| return ball + " " + strike + nothing; | ||
| } | ||
| } | ||
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
This file was deleted.
Oops, something went wrong.
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,40 @@ | ||
| package baseball; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class BallCounting { | ||
|
|
||
| private List<Integer> correct; | ||
| private List<Integer> guess; | ||
|
|
||
| public void setCorrect(List<Integer> correct) { | ||
| this.correct = correct; | ||
| } | ||
| public void setGuess(List<Integer> guess) { | ||
| this.guess = guess; | ||
| } | ||
|
|
||
| public List<Integer> getStrike(List<Integer> correct,List<Integer> guess) { | ||
| List<Integer> sameNumber = new ArrayList<>(); | ||
| for(int i = 0; i <3; i++) { | ||
| if(correct.get(i).equals(guess.get(i)) ){ | ||
| sameNumber.add(guess.get(i)); | ||
| } | ||
| }return sameNumber; | ||
| } | ||
|
|
||
| public List<Integer> getBall(List<Integer> correct,List<Integer> guess) { | ||
| List<Integer> common = new ArrayList<>(correct); | ||
| common.retainAll(guess); | ||
| common.removeAll(getStrike(correct,guess)); | ||
| return common; | ||
| } | ||
|
|
||
| public String getNothing() { | ||
| return "낫싱"; | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
This file was deleted.
Oops, something went wrong.
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
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 @@ | ||
| package baseball; | ||
|
|
||
| import camp.nextstep.edu.missionutils.Console; | ||
|
|
||
| public class GameHost { | ||
|
|
||
| public void start() { | ||
| System.out.println("숫자 야구 게임을 시작합니다"); | ||
| } | ||
|
|
||
| public void end() { | ||
| System.out.println("3개의 숫자를 모두 맞히셨습니다! 게임 종료"); | ||
| } | ||
|
|
||
| public String askRestart() { | ||
| Start start = new Start(); | ||
| System.out.println("게임을 새로 시작하려면 1, 종료하려면 2를 입력하세요"); | ||
| int ask = Integer.parseInt(Console.readLine()); | ||
| if (ask == 1){ | ||
| start.runGame(); | ||
| } return ""; | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
|---|---|---|
|
|
@@ -20,5 +20,4 @@ public List<Integer> guess() { | |
| } | ||
| return user; | ||
| } | ||
|
|
||
| } | ||
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.
이건 구두로 말씀드리겠습니다!