-
Notifications
You must be signed in to change notification settings - Fork 11
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
[202101947 김민지] 1주차 미션을 제출합니다. #3
Open
alsswl
wants to merge
46
commits into
CNU-Likelion:main
Choose a base branch
from
alsswl:alsswl
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 41 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
a49f8f3
feat : 주석으로 구현 틀 짜기
alsswl 8924109
feat : 서로 다른 3가지 수 랜덤으로 뽑기
alsswl 7aa2912
feat : 사용자에게 수 입력받기
alsswl 2dafced
feat : 사용자가 입력을 잘못하면 에러를 발생시킨다
alsswl 42cecec
feat : 입력받은 수를 LinkedList에 넣는다.
alsswl 3866d09
fix : 게임을 지속하기 위한 while문 추가 및 인덴트를 위한 메소드 생성
alsswl 2cbdccf
feat : 스트라이크 수를 세는 기능
alsswl 6292127
feat : 세 수를 모두 맞히면 재시작 여부를 묻고 이에 대한 기능을 수행
alsswl 8c54335
feat : strike와 ball의 결과에 따라 출력하기
alsswl 81aabfd
refactor : 출력 기능 메서드로 분리
alsswl 4fb6534
fix : main에서 결과 출력하는 부분 수정
alsswl 94593a6
feat : scanner으로 변경
alsswl 459f1a3
feat : 주석으로 구현 틀 짜기
alsswl a2c14bc
feat : 서로 다른 3가지 수 랜덤으로 뽑기
alsswl 004e19a
feat : 사용자에게 수 입력받기
alsswl dc3c2ca
feat : 사용자가 입력을 잘못하면 에러를 발생시킨다
alsswl 79911e4
feat : 입력받은 수를 LinkedList에 넣는다.
alsswl 6e73064
fix : 게임을 지속하기 위한 while문 추가 및 인덴트를 위한 메소드 생성
alsswl 1026b35
feat : 스트라이크 수를 세는 기능
alsswl 87ec4f2
feat : 세 수를 모두 맞히면 재시작 여부를 묻고 이에 대한 기능을 수행
alsswl 2da4e46
feat : strike와 ball의 결과에 따라 출력하기
alsswl c0a578a
refactor : 출력 기능 메서드로 분리
alsswl b5f2fd9
fix : main에서 결과 출력하는 부분 수정
alsswl 114fc9d
feat : scanner으로 변경
alsswl b868e94
fix : 패키지 수정
alsswl 4e7fa40
fix : 패키지 변경
alsswl e60084a
docs : readme파일 생성
alsswl 408a526
refactor : 불필요한 import 삭제
alsswl 70a5a42
refactor : 불필요한 주석 삭제
alsswl c397ac5
refactor : main에 있던 기능 메서드화
alsswl e1c2845
refactor : 메서드 순서 변경
alsswl cb39f03
refactor : 클래스로 메서드 기능별로 묶기
alsswl b58338c
refector : 클래스 순서 정렬 및 클래스 첫줄 공백 추가
alsswl 9f9e85b
refactor : 클래스별로 파일 분리하기
alsswl cb3ae81
refactor : 메서드 순서 정렬
alsswl 4e8f918
docs : readme파일 작성
alsswl 01aed61
refactor : 클래스 객체지향적으로 수정
alsswl 60aed13
refactor : addNumToList와 getUserNum 합치기
alsswl dfba9b2
refactor : 게임 재시작 여부, 입력 재시작 여부 나타내는 변수명 수정
alsswl cb7ef2b
refactor : 결과 출력 코드 단순화
alsswl 49d1b0f
feat : 접근제한자 수정
alsswl 40dc83b
refactor : 매직넘버 수정
alsswl d3906d4
refactor : userNum 간결화
alsswl 641ad01
refactor : baseballnumber과 hint의 역할 분리
alsswl 660509d
refactor : BaseBallNumber과 Hint의 자체적인 변수 설정, setter생성
alsswl e41f391
docs : readme파일 수정
alsswl 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 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 @@ | ||
#이제까지는 협업을 한 적이 없어서 내가 원하는 대로 나만 알아보도록 코드를 만들어도 문제될 것이 없어서 많은 것들을 지키지 않았었는데, 이번에 코멘트를 받아보니까 내가 아직 알지 못하는 규칙들이 너무 많아서 이를 더 자세히 공부하고, 앞으로는 나의 코드를 객관적으로 보는 능력을 길러야 할 것 같다. #백엔드 분들이 PR한 것들을 보니까 잘하시는 분들이 좀 계신거같다. 나도 저렇게 구현하고 싶다는 욕심이 생겼다. 앞으로 열심히 해야겠다! |
This file contains 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,61 @@ | ||
package baseball; | ||
|
||
import java.util.*; | ||
import mallang.missionutils.*; | ||
|
||
public class Application { | ||
|
||
private static int askFinish() { | ||
System.out.println("3개의 숫자를 모두 맞히셨습니다! 게임 종료"); | ||
System.out.println("게임을 새로 시작하려면 1, 종료하려면 2를 입력하세요."); | ||
return Integer.parseInt(Console.readLine()); | ||
} | ||
|
||
private static int endOrAgain(int again) { | ||
int ifOneContinueGameSet = 1; | ||
if (again == 1) { | ||
ifOneContinueGameSet = 1; | ||
} else if (again == 2) { | ||
System.out.println("게임종료"); | ||
ifOneContinueGameSet = 0; | ||
} else { | ||
throw new IllegalArgumentException(); | ||
} | ||
return ifOneContinueGameSet; | ||
} | ||
|
||
public static void main(String[] args) { | ||
//TODO: 숫자 야구 게임 구현 | ||
|
||
Hint hint = new Hint(); | ||
BaseballNumber baseballNumber = new BaseballNumber(); | ||
|
||
List<Integer> randomNum; | ||
List<Integer> userNum; | ||
|
||
int ifOneContinueGameSet = 1; | ||
int ifOneContinueUserSet = 1; | ||
|
||
while (ifOneContinueGameSet == 1) { | ||
randomNum = new ArrayList<>(); | ||
baseballNumber.pickNum(randomNum); | ||
|
||
while (ifOneContinueUserSet == 1) { | ||
int strike = 0; | ||
int ball = 0; | ||
|
||
userNum = new ArrayList<>(); | ||
|
||
userNum = baseballNumber.getUserNum(); | ||
|
||
strike = hint.countStrike(randomNum, userNum); | ||
ball = hint.countBall(userNum, randomNum); | ||
|
||
ifOneContinueUserSet = hint.printAnswer(strike, ball); | ||
} | ||
|
||
int again = askFinish(); | ||
ifOneContinueGameSet = endOrAgain(again); | ||
ifOneContinueUserSet = 1; | ||
} | ||
} | ||
} |
This file contains 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,33 @@ | ||
package baseball; | ||
|
||
import java.util.*; | ||
import mallang.missionutils.*; | ||
|
||
public class BaseballNumber { | ||
|
||
public void pickNum(List<Integer> randomNum) { | ||
while (randomNum.size() != 3) { | ||
int ranNum = Randoms.pickNumberInRange(1, 9); | ||
if (!randomNum.contains(ranNum)) { | ||
randomNum.add(ranNum); | ||
} | ||
} | ||
} | ||
|
||
public List<Integer> getUserNum() { | ||
System.out.printf("숫자를 입력해주세요"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. System.out BaseballNumber의 역할은 뭐라고 생각하시나요? |
||
String[] userArr = Console.readLine().split(""); | ||
checkUserNum(userArr); | ||
List<Integer> userNum = new ArrayList<>(); | ||
userNum.add(Integer.parseInt(userArr[0])); | ||
userNum.add(Integer.parseInt(userArr[1])); | ||
userNum.add(Integer.parseInt(userArr[2])); | ||
return userNum; | ||
} | ||
|
||
public void checkUserNum(String[] userArr) { | ||
if (userArr.length != 3) { | ||
throw new IllegalArgumentException(); | ||
} | ||
} | ||
} |
This file contains 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,52 @@ | ||
package baseball; | ||
|
||
import java.util.*; | ||
|
||
public class Hint { | ||
|
||
public int countStrike(List<Integer> randomNum, List<Integer> userNum) { | ||
int cnt = 0; | ||
for (int i = 0; i < 3; i++) { | ||
if (randomNum.get(i) == userNum.get(i)) { | ||
cnt++; | ||
} | ||
} | ||
return cnt; | ||
} | ||
|
||
public int countBall(List<Integer> userNum, List<Integer> randomNum) { | ||
int cnt = 0; | ||
for (int i = 0; i < 3; i++) { | ||
cnt += checkBall(i, userNum, randomNum); | ||
} | ||
return cnt; | ||
} | ||
|
||
public int checkBall(int index, List<Integer> userNum, List<Integer> randomNum) { | ||
if (randomNum.contains(userNum.get(index))) { | ||
if (index != randomNum.indexOf(userNum.get(index))) { | ||
return 1; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
public int printAnswer(int strike, int ball) { | ||
int ifOneContinueUserSet = 1; | ||
|
||
if (ball != 0) { | ||
System.out.printf("%d볼 ", ball); | ||
} | ||
if (strike != 0) { | ||
System.out.printf("%d스트라이크", strike); | ||
if (strike == 3) | ||
ifOneContinueUserSet = 0; | ||
} | ||
if (ball == 0 && strike == 0) { | ||
System.out.printf("낫싱"); | ||
} | ||
System.out.println(); | ||
|
||
return ifOneContinueUserSet; | ||
} | ||
} |
This file contains 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
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.