after a long time i came back to java and i try to write a short game about random numbers
The game should look like that:
- A Text box appears which asks for the difficulty (Done)
- A random number appears according to the difficulty (Stuck)
- A Textbox says "You Won, roll Again?" or "You Lose, roll Again" in both cases a loop is needed thats starts at 2. (no clue...)
Im currently stuck at 2. i can generate a random number but after i choose the difficulty nothing happens
here's the code :
package randomnumbergame;
import java.awt.Component;
import javax.swing.JOptionPane;
public class RandomNumberGame {
double n;
double e;
double h;
Component frame = null;
String answer = null;
public static void main(String[] args) {
String[] options = new String[] {"Easy", "Normal", "Hard"};
JOptionPane.showOptionDialog(null, "What Difficulty do you want ?", "Difficulty",
JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE,
null, options, options[0]);
Object answer = null; }
{
if ("Hard".equals(answer)) {
n = Math.random();
long n3 = Math.round(Math.random()*99999);
System.out.println (n3);
JOptionPane.showMessageDialog(frame, n3 ,"Your randomly generated Number is:" , JOptionPane.PLAIN_MESSAGE) ;
}else if ("Normal".equals(answer)) {
h = Math.random();
long n4 = Math.round(Math.random()*9999);
System.out.println (n4);
JOptionPane.showMessageDialog(frame, n4 ,"Your randomly generated Number is:" , JOptionPane.PLAIN_MESSAGE) ;
}else if ("Easy".equals(answer)) {
e = Math.random();
long e4 = Math.round(Math.random()*999);
System.out.println (e4);
JOptionPane.showMessageDialog(frame, e4 ,"Your randomly generated Number is:" , JOptionPane.PLAIN_MESSAGE) ;
}
}
}
what is wrong with it ? I looked trought several Questions here but i couldn't figure it out.
Aucun commentaire:
Enregistrer un commentaire