For my school project I am creating a game like Bad Apples for iPhone (not my personal choice but it isn’t the problem).
The game needs to have two versions, the first one in console and the second one in JavaFX. But I wanted to go a little further with that. I want to add arguments that the user can add to the terminal when launching the game, for example
java -jar BadApplesClone.jar –height=10 –width=10 –numPieces=5
And then I will handle all the values introduced and change the variables.
I am using OpenJDK6, and so I am doing like this for now :
for (int i=0; i<args.length; i++)
{
if (args[i].equals("--help"))
throw new UnsupportedOperationException("Not yet implemented");
if (args[i].equals("--largura"))
throw new UnsupportedOperationException("Not yet implemented");
if (args[i].equals("--altura"))
throw new UnsupportedOperationException("Not yet implemented");
if (args[i].equals("--pecas_inicio"))
throw new UnsupportedOperationException("Not yet implemented");
if (args[i].equals("--javafx"))
{
JavaFX javaFX = new JavaFX(ALTURA, LARGURA, PECAS_INICIO);
javaFX.initJogo();
}
}
But I don’t know how to handle the values like –width=10.. I have thought of an enum, but I don’t really know how to do that.
Can anyone explain me a way to achieve this?
To answer the question you actually asked …
Some of the elements of your args array are of the form “–SOMETHING=ANOTHER”.
So, first thing you need is:
The second problem is to parse off the ANOTHER.
is the place to start with that.