-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathProgressState.java
More file actions
39 lines (34 loc) · 1.16 KB
/
ProgressState.java
File metadata and controls
39 lines (34 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package state;
import model.BaseballNumber;
import model.Game;
import model.GameResult;
import view.Inputview;
import view.OutputView;
public class ProgressState implements GameState{
private final BaseballNumber answer;
private final Inputview inputview;
private final OutputView outputView;
public ProgressState(BaseballNumber baseballNumber){
this.answer = baseballNumber;
this.inputview = new Inputview();
this.outputView = new OutputView();
}
@Override
public void handle(Game game){
outputView.printInputGuide();
String input = inputview.readNumber();
playOneTurn(input, game);
}
private void playOneTurn(String input, Game game){
try {
BaseballNumber userNumber = new BaseballNumber(input);
GameResult gameResult = answer.compare(userNumber);
outputView.printResult(gameResult.getMessage());
if(!gameResult.isThreeStrike()) return;
outputView.printGameEnd();
game.changeState(new GameOverState());
} catch (IllegalArgumentException e){
outputView.printError(e.getMessage());
}
}
}