Skip to content

Commit d6aeca3

Browse files
committed
fix some bugs
1 parent 67ad422 commit d6aeca3

File tree

1 file changed

+10
-4
lines changed
  • src/main/java/vip/floatationdevice/wordlehelper

1 file changed

+10
-4
lines changed

src/main/java/vip/floatationdevice/wordlehelper/GUI.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class GUI extends JFrame
5757
//tries status
5858
private final JLabel triesLabel=new JLabel("Try 0 / 6");
5959
//tries counter
60-
private int tries=1;
60+
private int tries=0;
6161
//'words left' status
6262
private final JLabel wordsLeftLabel=new JLabel();
6363
//[?] button that shows the help message
@@ -79,7 +79,12 @@ private void initBoard()
7979
private String getWord(int line)
8080
{
8181
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+
}
8388
return sb.toString().toLowerCase();
8489
}
8590

@@ -166,6 +171,7 @@ public boolean dispatchKeyEvent(KeyEvent e)
166171
//if ArrayList has only one word, that word is the result
167172
else if(answerWordsList.size()==1)
168173
{
174+
triesLabel.setText("Try " + ++tries + " / "+"6");
169175
System.out.println("only one word left: "+answerWordsList.get(0));
170176
JOptionPane.showMessageDialog(null,
171177
"The word we are finding is:\n\n · "+answerWordsList.get(0)+"\n\nThe program will reset",
@@ -180,8 +186,8 @@ else if(answerWordsList.size()==1)
180186
letterIndexColumn=0;
181187
numberIndexLine++;
182188
letterIndexLine++;
183-
triesLabel.setText("Try "+tries+" / "+"6");
184-
tries++;
189+
triesLabel.setText("Try " + ++tries + " / "+"6");
190+
//tries++;
185191
}
186192
//if the last line is reached, the game is over
187193
if(numberIndexLine==6)

0 commit comments

Comments
 (0)