Ano*_*non 0 java for-loop increment game-engine
我在增加我的计数器方面遇到了一些困难.不是递增它而是不断地打印1并且不将数字加在一起.我尝试使用另一个变量来累计计数器,但没有运气.任何想法,为什么它不增加?
码:
tf.addActionListener(new ActionListener() {
int wrong = 0;
int right = 0;
@Override
public void actionPerformed(ActionEvent e) {// enter key
JTextField tf = (JTextField) e.getSource();
letter = tf.getText();
tf.setText("");
// tf.requestFocus();
jlLetsUsed.setText(jlLetsUsed.getText() + letter + " ");// sets
char[] jlabelText = jlLines.getText().toCharArray();// converts
char userEnteredChar = letter.charAt(0);
System.out.println(wordList[level]);
if (!wordList[level].contains(letter)) {
wrong++;
if (wrong == 6) {
JOptionPane.showMessageDialog(frame,
"He's dead, game over." + "\n"
+ "The word was " + wordList[level]
+ ".", "You Lost",
JOptionPane.INFORMATION_MESSAGE, ic);
GameStructure restart = new GameStructure();
level = (int) (Math.random() * 64);// generate new
// random word
restart.window();
}
return;
}
int i = 0;
for (i = 0; i < wordList[level].length(); i++) {
if (wordList[level].charAt(i) == userEnteredChar) {
jlabelText[3 * i] = ' ';
jlabelText[3 * i + 1] = userEnteredChar;
right++;
}// end if
}// end for
jlLines.setText(String.valueOf(jlabelText));
if (jlabelText.length / 3 == right) {
JOptionPane.showMessageDialog(frame, "You got the word!.",
"You Lost", JOptionPane.INFORMATION_MESSAGE, ic);
GameStructure restart = new GameStructure();
level = (int) (Math.random() * 64);// generate new
// random word
restart.window();
}
}// end actionPerformed method
});
Run Code Online (Sandbox Code Playgroud)
我的猜测是你希望right打印你猜对了的次数,但看起来好像你打电话
int right = 0;
Run Code Online (Sandbox Code Playgroud)
每次你猜.
尝试加载一个至少有两个相同字母的单词,并猜测那封信.我敢打赌,在这种情况下你会看到这个数字达到2.
如果你想在每次猜到正确的字母时增加一个数字,那么你必须在猜测范围之外宣布它.
| 归档时间: |
|
| 查看次数: |
110 次 |
| 最近记录: |