-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathGame.java
More file actions
67 lines (55 loc) · 1.82 KB
/
Copy pathGame.java
File metadata and controls
67 lines (55 loc) · 1.82 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
60
61
62
63
64
65
66
67
package baseball.Model;
import camp.nextstep.edu.missionutils.Randoms;
import java.util.ArrayList;
import java.util.List;
public class Game {
private final List<Integer> answerNumbers = new ArrayList<>();
private boolean GameStatus;
private final boolean Playing = true;
private final boolean End = false;
private final String RESTART = "1";
private final String QUIT = "2";
public Game(){
this.setAnswerNumbers();
this.GameStatus = Playing;
}
public void setAnswerNumbers(){
while (this.answerNumbers.size() < 3) {
int randomNumber = Randoms.pickNumberInRange(1, 9);
if (!this.answerNumbers.contains(randomNumber)) {
this.answerNumbers.add(randomNumber);
}
}
}
public String makeGameResult(List<Integer> inputNumbers) {
GameResult gameResult = new GameResult(this.answerNumbers, inputNumbers);
applyResult(gameResult.getStrikes());
return gameResult.resultToString();
}
public void applyResult(int strike) {
if (strike == 3) {
this.GameStatus = End;
}
}
public boolean gamestatus() {
return this.GameStatus;
}
public boolean isRestart(String input) {
if (input.equals(RESTART)) {
return true;
} else if (input.equals(QUIT)) {
return false;
} else {
throw new IllegalArgumentException();
}
}
public List<Integer> stringToIntList(String String) { //입력값을 List로 변경
List<Integer> intList = new ArrayList<>();
for (int i = 0; i < String.length(); i++) {
char digitChar = String.charAt(i);
int digitInt = Character.getNumericValue(digitChar);
intList.add(digitInt);
}
return intList;
}
}