-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordleState.java
More file actions
79 lines (62 loc) · 1.59 KB
/
WordleState.java
File metadata and controls
79 lines (62 loc) · 1.59 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
70
71
72
73
74
75
76
77
78
79
package wordle_gui;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class WordleState {
private int rowLength;
public int getRowLength() {
return rowLength;
}
public void setRowLength(int rowLength) {
this.rowLength = rowLength;
}
public int getAttemptsRemaining() {
return attemptsRemaining;
}
public void setAttemptsRemaining(int attemptsRemaining) {
this.attemptsRemaining = attemptsRemaining;
}
public int getAttempts() {
return attempts;
}
public void setAttempts(int attempts) {
this.attempts = attempts;
}
public String getWord() {
return word;
}
public void setWord(String word) {
this.word = word;
}
public List<String> getGuesses() {
return guesses;
}
public void setGuesses(List<String> guesses) {
this.guesses = guesses;
}
private int attemptsRemaining;
private int attempts;
private String word;
List<String> guesses;
public WordleState(String word) {
this.word = word;
this.rowLength = this.word.length();
this.attempts = 6;
this.attemptsRemaining = this.attempts;
this.guesses = new ArrayList<String>();
System.out.println(word);
}
public boolean isGameOver () {
return this.attemptsRemaining == 0 || didWin();
}
public boolean didWin() {
return this.guesses.contains(word); // if we have a correct guess we WIN
}
public void guess(String str) {
// check if our guess is not too long / short
if (str.length() == word.length()) {
this.guesses.add(str);
this.attemptsRemaining--; // used up a try
}
}
}