-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathAlphabetGameController.java
More file actions
47 lines (38 loc) · 1.26 KB
/
AlphabetGameController.java
File metadata and controls
47 lines (38 loc) · 1.26 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
package leets.land.controller;
import leets.land.view.InputView;
public class AlphabetGameController implements GameController {
private final InputView inputView = new InputView();
@Override
public int generateRandomVal() {
int randomNum = (int) (Math.random() * 52);
if (randomNum < 26) {
return (char) ('a' + randomNum);
}
else {
return (char) ('A' + randomNum - 26);
}
}
@Override
public int updownGameStart(int targetAlphabet) {
char first = 'A';
char last = 'z';
int[] count = {0};
boolean isCorrect = false;
char inputAlphabet;
while(!isCorrect){
System.out.print("정답을 입력하세요(" + first + "~" + last + ") : ");
inputAlphabet = inputView.inputChar(first, last, count);
if(inputAlphabet == targetAlphabet){
System.out.println("정답입니다!");
isCorrect = true;
} else if (inputAlphabet<targetAlphabet) {
first = inputAlphabet;
System.out.println("UP");
} else {
last = inputAlphabet;
System.out.println("DOWN");
}
}
return count[0];
}
}