-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameStats.java
78 lines (68 loc) · 2.39 KB
/
GameStats.java
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
70
71
72
73
74
75
76
77
78
import java.io.Serializable;
import java.util.*;
public class GameStats implements Serializable {
String[] words, masks, wordsToTry;
int tries, sessionId, gamesQty;
boolean running, winner;
boolean[] winStates;
public GameStats(int session_id, int gamesQty){
this.sessionId = session_id;
this.tries = 0;
this.gamesQty = gamesQty;
this.winStates = new boolean[this.gamesQty];
this.words = this.getWords();
this.masks = this.initMasks();
this.wordsToTry = this.initWordsToTry();
this.running = true;
this.winner = false;
for (int i = 0; i < this.gamesQty; i++) {
this.winStates[i] = false;
}
}
public void setWordsToTry(String[] wordsToTry) {
this.wordsToTry = wordsToTry;
}
public boolean didIWin(){
return winner;
}
public String[] getWords(){
String[] words = new String[this.gamesQty];
for (int i = 0; i < this.gamesQty; i++) {
words[i] = newWord();
}
return words;
}
public String[] initMasks(){
String[] masks = new String[this.gamesQty];
for (int i = 0; i < this.gamesQty; i++) {
masks[i] = "0".repeat(5);
}
return masks;
}
public String[] initWordsToTry(){
String[] wordsToTry = new String[this.gamesQty];
for (int i = 0; i < this.gamesQty; i++) {
wordsToTry[i] = "-".repeat(5);
}
return wordsToTry;
}
public String toString(){
return (
"Game State:\n" +
"-> session:\t" + Integer.toString(this.sessionId) + "\n" +
"-> tries:\t" + Integer.toString(this.tries) + "\n" +
"-> running:\t" + Boolean.toString(this.running) + "\n" +
"-> winner:\t" + Boolean.toString(this.winner) + "\n" +
"-> words:\t" + Arrays.toString(this.words) + "\n" +
"-> wordsToTry:\t" + Arrays.toString(this.wordsToTry) + "\n" +
"-> masks:\t" + Arrays.toString(this.masks) + "\n" +
"-> winStates:\t" + Arrays.toString(this.winStates)
);
}
private String newWord(){
String[] wordBank = {"besta", "radio", "dente", "enjoo", "pingo", "vulgo", "cache", "oscar", "brejo", "russo"};
Random rand = new Random();
int idx = rand.nextInt(wordBank.length);
return wordBank[idx];
}
}