2012-03-18 5 views
0

나는 스윙이있는 슬롯 머신을 만들고 있습니다. 후속 코드 확인 결과를 할당한다 :이클립스 - 슬롯 머신, if와 else가 int 값을 잘못 올리는 경우

// Reset win amount 
    winAmount = 0; 

    // Checks for winning combinations and increases corresponding values 
    if (num[0]==num[1] && num[1]==num[2]){ 
     winAmount = 4; 
     coinsWon = coinsWon + winAmount; 
     txtWinMessage.setText("Jackpot! You have won " + winAmount + " !"); 
     txtCoinsWon.setText(coinsWon + " "); 

     // A text field for testing - so i can see the math it does 
     textField_6.setText(coinsWon + " " + winAmount + "/0 = 1"); 
    } else if (num[0]==num[1] || num[0]==num[2] || num[1]==num[2]){ 
     winAmount = 1; 
     coinsWon = coinsWon + winAmount; 
     txtWinMessage.setText("You Have Won " + winAmount); 
     txtCoinsWon.setText(coinsWon + " "); 

     // A text field for testing - so i can see the math it does 
     textField_6.setText(coinsWon + " " + winAmount + "/0 = 1"); 
    } else { 
     txtWinMessage.setText("Sorry, try again"); 

     // A text field for testing - so i can see the math it does 
     textField_6.setText("Went to else. coinsWon = " + coinsWon); 
    } 
의 num [0], NUM [1] 및 NUM [2] 비트를 통해 생성

: I 가지고

private void setIcon(int i) { 
    num[i] = random.nextInt(8); 
    slots[i].setIcon(new ImageIcon(getClass().getResource("images/slotIcon" + num[i] + ".png"))); 
    counter++; 
    if(counter > 50) { 
     winAmount = 0; 
     getResults(); 
    } 
} 

테스팅 분야 num [i]가 올바르게 할당되고 ImageIcon이 num [i]에 따라 올바르게 설정되었음을 보여주세요. 결과 수학에 문제가 발생하더라도. IF 부분으로 가면 coinsWon에 +4를 더한다. 만약 coinsWon에 +1을 더하면 ELSE에 가면 가끔 ELSE에 가면 가끔씩 아무 것도 추가하지 않지만 때로는 + 1 동전에 +2 또는 +2. 하지만 winAmount가 1이되기 때문에가 아니라 동전이 분명한 이유없이 더 큰 숫자로 변경되기 때문에 ...

아이디어가 있으십니까?

+2

마지막 단락을 다시 사용할 수 있습니까? –

+0

기본적으로, 만약 else {section에 가면 coinsWon은 여전히 ​​증가합니다. – Lynce

+4

디버깅을 제안합니다. –

답변

0

아마도 디버깅 중이며 "표현식"부분을보고 수정하는 문장이 있습니까? 그런 경우 코드가 분리 된 스레드에서 임의로 코드 실행 전후에 평가되므로 결과가 홀수 일

관련 문제