-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordleController.java
More file actions
44 lines (37 loc) · 1.38 KB
/
Copy pathWordleController.java
File metadata and controls
44 lines (37 loc) · 1.38 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
package Wordle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class WordleController {
private WordleModel model;
private WordleView view;
public WordleController(WordleModel model, WordleView view) {
this.model = model;
this.view = view;
view.addCheckButtonListener(new CheckButtonListener());
view.addNewButtonListener(new NewButtonListener());
view.addSolutionButtonListener(new SolutionButtonListener());
}
class CheckButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
char[] guessArray = view.getGuessArray();
int result = model.checkGuess(guessArray);
view.updateGraphics(result);
view.updateLabel(result);
if (result == model.getSolutionArray().length * 10) {
view.showWinMessage();
view.disableComponents();
}
}
}
class NewButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
view.resetComponents();
}
}
class SolutionButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
view.showSolution(model.getSolutionWord());
view.disableComponents();
}
}
}