Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions docs/README.md
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
- 객체 다이어그램을 그리고 시작하는것도 좋음
49 changes: 49 additions & 0 deletions src/main/java/baseball/AiPlayer.java
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 ="";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이건 구두로 말씀드리겠습니다!

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;
}
}
5 changes: 1 addition & 4 deletions src/main/java/baseball/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
public class Application {

public static void main(String[] args) {

Start start = new Start();
start.button();
start.runGame();
}


}
52 changes: 0 additions & 52 deletions src/main/java/baseball/BallCount.java

This file was deleted.

40 changes: 40 additions & 0 deletions src/main/java/baseball/BallCounting.java
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 "낫싱";
}
}



37 changes: 0 additions & 37 deletions src/main/java/baseball/Computer.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/baseball/ExceptionMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class ExceptionMessage {

public void checkInputLength(String[] input) {
if (input.length != 3) {
throw new InputException("3자리 숫자를 입력하셔야됩니다");
throw new IllegalArgumentException("3자리 숫자를 입력하셔야됩니다");
}
}
}
23 changes: 23 additions & 0 deletions src/main/java/baseball/GameHost.java
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 "";
}
}
8 changes: 0 additions & 8 deletions src/main/java/baseball/InputException.java

This file was deleted.

38 changes: 0 additions & 38 deletions src/main/java/baseball/Judgement.java

This file was deleted.

1 change: 0 additions & 1 deletion src/main/java/baseball/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ public List<Integer> guess() {
}
return user;
}

}
Loading