-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordleModel.java
More file actions
36 lines (31 loc) · 1.1 KB
/
Copy pathWordleModel.java
File metadata and controls
36 lines (31 loc) · 1.1 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
package Wordle;
import java.util.Random;
public class WordleModel {
private String solutionWord;
private char[] solutionArray;
public WordleModel() {
String[] wordList = {"APPLE", "BANAN", "CARDS", "DOORS", "ELBOW", "FLUTE", "GRAPE", "HORSE", "IGLOO", "JUMPS"};
Random random = new Random();
int index = random.nextInt(wordList.length);
solutionWord = wordList[index];
solutionArray = solutionWord.toCharArray();
}
public String getSolutionWord() {
return solutionWord;
}
public char[] getSolutionArray() {
return solutionArray;
}
public int checkGuess(char[] guessArray) {
int correctPositionCount = 0;
int correctValueCount = 0;
for (int i = 0; i < solutionArray.length; i++) {
if (solutionArray[i] == guessArray[i]) {
correctPositionCount++;
} else if (solutionWord.indexOf(guessArray[i]) != -1) {
correctValueCount++;
}
}
return correctPositionCount * 10 + correctValueCount;
}
}