코드/문제가 있지만 사용자가 4 개의 정답을 얻을 때까지 Hi/Lo 카드 게임을 실행하려고하는 게임을 설계하고 있습니다. 사용자가 "Higher", "Lower"또는 "Equal"이라고 말하면 카드 번호는 마지막 'cardGenerated'번호를 비교 한 번호입니다.자바에서 이름을 숫자로 설정하는 방법
지금은 사용자가 보지 못하거나 알지 못하는 숫자와 비교하여 옳고 그름을 알지 못합니다. 난 내가 한 수있는 출력을 선호 거라고하지만 난 그냥 showOptionDialog 출력에 'nextCard'변수를 추가 할 수 있습니다 알고, 그래서 프로그램의 인쇄 경우 :
는"The Card pulled is the 9
Is the next card Higher, Lower or Equal?"
출력 다음 번호/카드 번호입니다 사용자가 이전 숫자 (9)와 (과) 비교했다는 의미입니다. 또한
,
내가 상수를 설정,하지만 난 그게 잭, 퀸, 킹, ACE, 무엇을 인쇄, 그것을 확인하는 방법을 잘 그래서 대신, 13, 12, 11 일 인쇄 아니에요 아니.
import java.util.Random;
import javax.swing.JOptionPane;
public class HiLo {
public static final int JACK = 11;
public static final int QUEEN = 12;
public static final int KING = 13;
public static final int ACE = 1;
public static void main(String[] args) {
int correctGuesses = 0;
Random generator = new Random();
int currentCard;
int nextCard = generator.nextInt(KING+1);
while (correctGuesses < 4)
{
currentCard = nextCard;
nextCard = generator.nextInt(KING+1);
Object[] options = {"Higher",
"Lower",
"Equal"};
int Input = JOptionPane.showOptionDialog(null,
"The Card pulled is the " + currentCard +
" \nis the next card Higher, Lower or Equal?",
"HiLo Card Game",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE,
null, options, options[0]);
if (nextCard > currentCard && Input == JOptionPane.YES_OPTION)
{
correctGuesses++;
}
else if (nextCard > currentCard && Input == JOptionPane.NO_OPTION)
{
correctGuesses = 0;
}
else if (nextCard > currentCard && Input == JOptionPane.CANCEL_OPTION)
{
correctGuesses = 0;
}
else if (nextCard < currentCard && Input == JOptionPane.YES_OPTION)
{
correctGuesses = 0;
}
else if (nextCard < currentCard && Input == JOptionPane.NO_OPTION)
{
correctGuesses++;
}
else if (nextCard < currentCard && Input == JOptionPane.CANCEL_OPTION)
{
correctGuesses = 0;
}
else if (nextCard == currentCard && Input == JOptionPane.YES_OPTION)
{
correctGuesses = 0;
}
else if (nextCard == currentCard && Input == JOptionPane.NO_OPTION)
{
correctGuesses = 0;
}
else if (nextCard == currentCard && Input == JOptionPane.CANCEL_OPTION)
{
correctGuesses++;
}
}
JOptionPane.showMessageDialog(null, "Congratulations, You guessed correctly 4 times"
+ "\nthe Last Card was the " + nextCard + " resart to play again");
}
}
http://stackoverflow.com/help/how-to-ask –
correctGuesses '보다'0 '쓸 수있는 쉬운 방법이 있습니다 - correctGuesses' – Deltharis
제가 알고있는 바로 그게 제가 생각한 최초의 수학적 방법이었습니다. 나는 그것을 correctGuesses = 0으로 만들 수 있다는 것을 압니다. 하지만 난 그걸 바꾸지 않았어. 그 순간에 내 큰 문제 중 하나가 아니기 때문에. – roughosing