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
10 changes: 10 additions & 0 deletions src/main/java/com/example/baseball/BaseBallApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.baseball;

import com.example.baseball.game.BaseBallGame;

public class BaseBallApplication {
public static void main(String[] args) {
BaseBallGame baseBallGame = new BaseBallGame(null, null);
baseBallGame.run(null);
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/example/baseball/balls/Ball.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.baseball.balls;

/**
* 값 객체의 역할을 하는 클래스
*/
public class Ball {
private final int value;

public Ball(int value) {
this.value = value;
}

public boolean isMatch(Ball user) {
// TODO 값이 같은지 비교하는 로직을 구현한다.
return false;
}
}
24 changes: 24 additions & 0 deletions src/main/java/com/example/baseball/balls/Balls.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.baseball.balls;

import java.util.List;

/**
* Ball에 대한 로직을 담은 일급 컬렉션 클래스
*/
public class Balls {
private final List<Ball> balls;

public Balls(List<Ball> balls) {
this.balls = balls;
}

public boolean isStrike(Ball user, int idx) {
// TODO 스트라이크 여부를 판단하는 로직을 구현한다.
return false;
}

public boolean isBall(Ball user, int idx) {
// TODO 볼 여부를 판단하는 로직을 구현한다.
return false;
}
}
24 changes: 24 additions & 0 deletions src/main/java/com/example/baseball/balls/Pitching.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.baseball.balls;

/**
* 비교 연산 및 결과 값을 담는 클래스
*/
public class Pitching {
private final int strike;
private final int ball;

public Pitching(int strike, int ball) {
this.strike = strike;
this.ball = ball;
}

public static Pitching matches(Balls computer, Balls user) {
// TODO 스트라이크 및 볼을 연산하는 로직을 구현한다.
return null;
}

public boolean isStrike() {
// TODO 스트라이크 여부를 판단하는 로직을 구현한다.
return false;
}
}
38 changes: 38 additions & 0 deletions src/main/java/com/example/baseball/game/BaseBallGame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.example.baseball.game;

import com.example.baseball.balls.Balls;
import com.example.baseball.balls.Pitching;
import com.example.baseball.io.Input;
import com.example.baseball.io.Output;
import com.example.baseball.strategy.NumberGenerator;

public class BaseBallGame {
private final Input input;
private final Output output;

public BaseBallGame(Input input, Output output) {
this.input = input;
this.output = output;
}

/**
* 전체 게임의 트랜잭션을 책임지는 클래스
*/
public void run(NumberGenerator numberGenerator) {
// 야구 게임은 게임을 끝낼 때까지 반복이 가능

do {
// 1. 게임 시작
// 2. 컴퓨터(target) 숫자 생성
Balls computer = numberGenerator.throwing();
// 2.1 컴휴터가 생성한 숫자는 서로 다른 세 개 숫자로 이루어진다.
Pitching pitching = new Round(input, output)
.start(computer);
// 3. 사용자 숫자 입력
// 3.1 사용자가 입력한 숫자는 서로 다른 세 개 숫자로 이루어진다.
// 4. 사용자 숫자와 컴퓨터 숫자 비교
// 5. 사용자 숫자와 컴퓨터 숫자의 위치와 크기가 모두 같으면 게임 종료
output.print(pitching.toString());
} while(input.isReGame());
}
}
32 changes: 32 additions & 0 deletions src/main/java/com/example/baseball/game/Round.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.example.baseball.game;

import com.example.baseball.balls.Balls;
import com.example.baseball.balls.Pitching;
import com.example.baseball.io.Input;
import com.example.baseball.io.Output;

public class Round {
private final Input input;
private final Output output;

public Round(Input input, Output output) {
this.input = input;
this.output = output;
}

public Pitching start(Balls computer) {

Pitching pitching;
do {
// 3. 사용자 숫자 입력
Balls user = input.throwing();
// 4. 사용자 숫자와 컴퓨터 숫자 비교
pitching = Pitching.matches(computer, user);
// 5. 사용자 숫자와 컴퓨터 숫자의 위치와 크기가 모두 같으면 게임 종료
output.print(pitching.toString());

} while(!pitching.isStrike());

return pitching;
}
}
9 changes: 9 additions & 0 deletions src/main/java/com/example/baseball/io/Input.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.baseball.io;

import com.example.baseball.balls.Balls;

public interface Input {
boolean isReGame();

Balls throwing();
}
5 changes: 5 additions & 0 deletions src/main/java/com/example/baseball/io/Output.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.baseball.io;

public interface Output {
void print(String toString);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.baseball.strategy;

import com.example.baseball.balls.Balls;

@FunctionalInterface
public interface NumberGenerator {
Balls throwing();
}