-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathRacingGame.java
More file actions
58 lines (46 loc) · 1.5 KB
/
RacingGame.java
File metadata and controls
58 lines (46 loc) · 1.5 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package game;
import controller.GameController;
import exception.GameInputException;
import view.InputView;
public class RacingGame {
// private static RacingGame defaultRacingGame;
private final InputView inputView;
private final GameInputException gameInputException;
private final GameController gameController;
public RacingGame() {
inputView = new InputView();
gameInputException = new GameInputException();
gameController = new GameController();
}
/*public static RacingGame getInstance() {
if(defaultRacingGame == null) {
defaultRacingGame = new RacingGame();
}
return defaultRacingGame;
}*/
public void run() {
String[] names = preHandleNames();
int count = preHandleCount();
gameController.raceSet(names);
gameController.race(count);
gameController.raceResult();
}
private String[] preHandleNames() {
String input = inputView.inputCarNames();
String[] names = input.split(",");
gameInputException.validateNameLength(names);
return names;
}
private int preHandleCount() {
String input = inputView.inputRaceCount();
gameInputException.validateNumber(input);
gameInputException.validateNumberZero(input);
return Integer.parseInt(input);
}
public void close() {
gameController.close();
gameInputException.close();
inputView.close();
//defaultRacingGame = null;
}
}