@@ -57,7 +57,7 @@ public class GUI extends JFrame
57
57
//tries status
58
58
private final JLabel triesLabel =new JLabel ("Try 0 / 6" );
59
59
//tries counter
60
- private int tries =1 ;
60
+ private int tries =0 ;
61
61
//'words left' status
62
62
private final JLabel wordsLeftLabel =new JLabel ();
63
63
//[?] button that shows the help message
@@ -79,7 +79,12 @@ private void initBoard()
79
79
private String getWord (int line )
80
80
{
81
81
StringBuilder sb =new StringBuilder ();
82
- for (int i =0 ;i !=5 ;i ++) sb .append (board [line ][i ].getText ());
82
+ for (int i =0 ;i !=5 ;i ++)
83
+ {
84
+ if (!board [line ][i ].getText ().equals ("_" ))
85
+ sb .append (board [line ][i ].getText ());
86
+ else return null ;
87
+ }
83
88
return sb .toString ().toLowerCase ();
84
89
}
85
90
@@ -166,6 +171,7 @@ public boolean dispatchKeyEvent(KeyEvent e)
166
171
//if ArrayList has only one word, that word is the result
167
172
else if (answerWordsList .size ()==1 )
168
173
{
174
+ triesLabel .setText ("Try " + ++tries + " / " +"6" );
169
175
System .out .println ("only one word left: " +answerWordsList .get (0 ));
170
176
JOptionPane .showMessageDialog (null ,
171
177
"The word we are finding is:\n \n · " +answerWordsList .get (0 )+"\n \n The program will reset" ,
@@ -180,8 +186,8 @@ else if(answerWordsList.size()==1)
180
186
letterIndexColumn =0 ;
181
187
numberIndexLine ++;
182
188
letterIndexLine ++;
183
- triesLabel .setText ("Try " + tries + " / " +"6" );
184
- tries ++;
189
+ triesLabel .setText ("Try " + ++ tries + " / " +"6" );
190
+ // tries++;
185
191
}
186
192
//if the last line is reached, the game is over
187
193
if (numberIndexLine ==6 )
0 commit comments