forked from bark20/java-bridge
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathInputView.java
More file actions
59 lines (53 loc) · 1.62 KB
/
InputView.java
File metadata and controls
59 lines (53 loc) · 1.62 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
59
package bridge;
import camp.nextstep.edu.missionutils.Console;
import static bridge.BridgeValidator.*;
/**
* 사용자로부터 입력을 받는 역할을 한다.
*/
public class InputView {
/**
* 다리의 길이를 입력받는다.
*/
public int readBridgeSize() {
while(true) {
try {
String bridgeSize = Console.readLine();
int size = Integer.parseInt(bridgeSize);
validateBridgeSize(size);
return size;
} catch (NumberFormatException e) {
System.out.println("[ERROR] 다리 길이는 숫자로 입력해야 합니다.");
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
}
}
}
/**
* 사용자가 이동할 칸을 입력받는다.
*/
public String readMoving() {
while (true) {
try {
String moving = Console.readLine();
validateMoving(moving);
return moving;
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
}
}
}
/**
* 사용자가 게임을 다시 시도할지 종료할지 여부를 입력받는다.
*/
public String readGameCommand() {
while (true) {
try {
String gameCommand = Console.readLine();
validateGameCommand(gameCommand);
return gameCommand;
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
}
}
}
}