-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameController.java
More file actions
69 lines (62 loc) · 2.45 KB
/
GameController.java
File metadata and controls
69 lines (62 loc) · 2.45 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
68
69
// import java.lang.Math;
// import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
public class GameController {
public static final String YELLOW = "\u001B[33m";
public static final String RED = "\u001B[31m";
private String[] args;
private String secretCode;
private int rounds;
public GameController(String[] args) {
this.args = args;
}
public String getSecretCode() {
return this.secretCode;
}
public int getRounds() {
return this.rounds;
}
public void initialize() {
if (this.args.length > 1){
ArrayList<String> option_list = new ArrayList<String>();
option_list.addAll(Arrays.asList(this.args));
Iterator<String> itr = null;
itr = option_list.listIterator();
while (itr.hasNext()) {
String option = itr.next();
if (option.equals("-t")) {
try {
this.rounds = Integer.parseInt(itr.next());
if(this.rounds < 0 && -15 < this.rounds) {
this.rounds *= -1;
System.out.printf(YELLOW + "Rounds number set: %d (not -%d)\n", this.rounds, this.rounds);
} else if(this.rounds > 15 || this.rounds < 1){
System.out.println(RED + "Rounds cannot be more then 15 or less then 1 (15 ≥ rounds ≥ 1)");
this.rounds = 10;
}
} catch (Exception e) {
System.out.println(YELLOW + "You should type number of rounds! (-t)\n");
};
}
if (option.equals("-c")) {
String code = itr.next();
if(GameFunctions.wrongInput(code)) {
System.out.printf(RED + "Error in setting secret code: ( -c %s )\n" +
"Secret code set automatic by 'generator'\n", code);
this.secretCode = GameFunctions.getSecretCode();
} else {
this.secretCode = code;
}
}
}
}
if (this.secretCode == null) {
this.secretCode = GameFunctions.getSecretCode();
}
if (this.rounds == 0) {
this.rounds = 10;
}
}
}