-
Notifications
You must be signed in to change notification settings - Fork 0
/
WSMouseListener.java
executable file
·106 lines (93 loc) · 2.64 KB
/
WSMouseListener.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
/**
* This class implements the MouseListener to handle events from each individual letter
* @author Michelle Perz
*/
public class WSMouseListener implements MouseListener {
private Letter[][] labels;
private WordBoard wordBoard;
private Letter thisLabel;
/**
* Constructor for the MouseListener
* @param thisLabel the Letter object we're currently working on
* @param labels all the Letter objects in the system
* @param wordBoard the current WordBoard we want to modify things on
*/
public WSMouseListener(Letter thisLabel, Letter[][] labels, WordBoard wordBoard) {
this.thisLabel = thisLabel;
this.labels = labels;
this.wordBoard = wordBoard;
}
/* (non-Javadoc)
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
*/
@Override
public void mouseClicked(MouseEvent e) {
thisLabel.toggleClicked(); //Set this as clicked
switch (wordBoard.checkWord(thisLabel.getValue())) {
case -1:
//Run through all the labels, set the background to false
if (wordBoard.stackLength() > 1) {
for (int i = 0; i < labels.length; i++) {
for (int j = 0; j < labels.length; j++) {
labels[i][j].setClicked(false);
}
}
}
break;
case 0:
///User does nothing
break;
case 1:
//Word solved, make it green and strike through
Word word = wordBoard.getWordOnStack();
int[] startPos = word.getPosition();
int startPosX = startPos[0];
int startPosY = startPos[1];
for (int i = 0; i < word.getLength(); i++) {
switch (word.getDirection()) {
case 0:
labels[startPosX][i + startPosY].setSolvedByUser();
break;
case 1:
labels[i + startPosX][startPosY].setSolvedByUser();
break;
case 2:
labels[i + startPosX][i + startPosY].setSolvedByUser();
break;
}
}
wordBoard.strikeThrough(word);
break;
}
}
/* (non-Javadoc)
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
*/
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
*/
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
*/
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
*/
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
}