Im trying to design a game that plays the Hi/Lo card game until the user gets 4 correct answers in a row, although theres a problem with the code.. I dont know how to make it so the card number that pops up once the user states "Higher", "Lower" or "Equal" is the number that they were comparing the last 'cardGenerated' number to.
Right now its comparing it to a number that the user doesnt see or is unknown to, so they dont know wether they were right or wrong. I know i can just add the 'nextCard' variable into the showOptionDialog output although i'd prefer to just have one number being output, so if the program prints:
"The Card pulled is the 9
Is the next card Higher, Lower or Equal?"
the next number/card outputted is the number that the user was comparing the previous number(9) to.
Also,
I have set the constants, but I'm not sure how to make it so instead of printing 11, 12, 13, 1, it prints JACK, QUEEN, KING, ACE, and what not.
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" );
}
}