-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathModel.java
More file actions
34 lines (28 loc) · 872 Bytes
/
Model.java
File metadata and controls
34 lines (28 loc) · 872 Bytes
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
package racingcar;
import camp.nextstep.edu.missionutils.Randoms;
import java.util.ArrayList;
import java.util.List;
public class Model {
List<String> carNames = new ArrayList<>();
List<String> carProgress = new ArrayList<>();
int frequency = 0;
public List<String> initCarProgress(int length) {
for (int i = 0; i < length; i++) {
carProgress.add("");
}
return carProgress;
}
public boolean move() {
int random = Randoms.pickNumberInRange(0, 9);
return random >= 4;
}
public void gameProgress(List<String> carNames, List<String> carProgress) {
for (int i = 0; i < carNames.size(); i++) {
String progress = carProgress.get(i);
if (move()) {
progress += '-';
carProgress.set(i, progress);
}
}
}
}