-
Notifications
You must be signed in to change notification settings - Fork 575
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
[숫자 야구 게임] 이은지 미션 제출합니다. #604
base: main
Are you sure you want to change the base?
Conversation
Feat : 난수 생성 클래스 구현 Feat : 입력 클래스 구현 Feat : 에러 관리 클래스 구현 Feat : 숫자 비교 클래스 구현 Feat : 게임 진행 클래스 구현
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.
고생하셨습니당
if (strike == 0 && ball == 0) { | ||
System.out.println("낫싱"); | ||
} else { | ||
System.out.println(ball + "볼 " + strike + "스트라이크"); | ||
} | ||
|
||
// 3 스트라이크인 경우 게임 종료 | ||
if (strike == 3) { | ||
printGameOverMessage(); | ||
gameOver = true; | ||
} else { | ||
gameOver = false; | ||
} |
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.
숫자 비교하는 메서드랑 분리하는게 좋을 것 같아요
List<Integer> randomNumber = computer.getRandomNumber(); | ||
player.playerInputNumber(); // 숫자 입력 | ||
List<Integer> playerNumber = player.getInputNumber(); |
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.
다른 곳에서 숫자를 만들고 매개변수로 넘겨주는건 어떨까요?
do { | ||
isDuplicate = false; | ||
for (int i = 0; i < 3; i++) { | ||
int num = Randoms.pickNumberInRange(1, 9); // 1 ~ 9 난수 생성 | ||
if (!numbers.contains(num)) { | ||
numbers.add(num); | ||
} else { | ||
isDuplicate = true; | ||
break; // 중복이 발생하면 break -> 다시 시도 | ||
} | ||
} | ||
|
||
if (isDuplicate) { | ||
numbers.clear(); | ||
} | ||
} while (isDuplicate || numbers.size() < 3); |
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.
depth
가 너무 깊은것 같아요 분리해줘요
public void resetRandomNumber() { | ||
this.randomNumber = generateRandomNumber(); | ||
} |
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.
generateNewRandomNumber()
는 어때요
public void play() { | ||
boolean continuePlaying = true; | ||
|
||
while (continuePlaying) { | ||
compareNumber.compareNumber(player, computer); | ||
|
||
if (compareNumber.isGameOver()) { | ||
System.out.println("게임을 새로 시작하려면 1, 종료하려면 2를 입력하세요."); | ||
String replayInput = player.inputReplay(); | ||
|
||
if ("1".equals(replayInput)) { | ||
// 게임 재시작 | ||
computer.resetRandomNumber(); // 새로운 난수 생성 | ||
} else if ("2".equals(replayInput)) { | ||
// 게임 종료 | ||
continuePlaying = false; | ||
} else { | ||
// 잘못된 입력 처리 | ||
System.out.println("잘못된 입력입니다. 게임을 종료합니다."); | ||
continuePlaying = false; | ||
} | ||
} | ||
} | ||
} |
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.
한 메서드안에 너무 많은게 들어가있는것 같아요
분리해줘요
import java.util.regex.Pattern; | ||
|
||
public class InputException { | ||
private static final String NOT_NUMBER = "숫자가 아닙니다."; |
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.
static final
을 붙이면 무슨일이 일어날까요
public Player() { | ||
this.inputNumber = new ArrayList<>(); | ||
} |
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.
생성자에서 이걸 해주는 이유가 궁금해요
public String inputReplay(){ | ||
String inputReplay = Console.readLine(); | ||
return inputReplay; | ||
} |
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.
이걸 Player
클래스에서 받는 이유가 궁금해요
No description provided.