-4
我正在做一個hang子手遊戲,如果我猜字母的錯誤字母,我在正確的標籤上加1,但是這個代碼在正確的時候加1到正確的。我怎樣才能解決這個問題?初學Hang子手遊戲
public class Form extends javax.swing.JFrame {
String FindWord = "apple";
int w = 0;
}
private void attemptSignActionPerformed(java.awt.event.ActionEvent evt) {
int charPos = 1;
String letter = aLetter.getText();
charPos = FindWord.indexOf(letter);
myMessage.setText("position is " + charPos);
if (charPos == 0) Char0.setText(letter);
if (charPos == 1) Char1.setText(letter);
if (charPos == 2) Char2.setText(letter);
if (charPos == 3) Char3.setText(letter);
if (charPos == 4) Char4.setText(letter);
if (charPos == 5) Char5.setText(letter);
charPos = FindWord.indexOf(letter, charPos + 1);
if (charPos == 0) Char0.setText(letter);
if (charPos == 1) Char1.setText(letter);
if (charPos == 2) Char2.setText(letter);
if (charPos == 3) Char3.setText(letter);
if (charPos == 4) Char4.setText(letter);
if (charPos == 5) Char5.setText(letter);
下面是我在與
if (charPos == -1) {
w++;
inCorrect.setText(Integer.toString(w));
}
}
麻煩我只想加1到不正確的時候我猜字母不是單詞「蘋果」的部分。
爲了您的利益:[在很少的幾行中的hangman的java實現](http://stackoverflow.com/a/22269413/256196) – Bohemian 2014-12-08 03:38:22