In this demo I'm going to run the
completed adventure game programme in BlueJ.
And I'm also going to show you how to run it
as a user might without BlueJ.
First I'll run in BlueJ.
I'll right click on the Game Class
which contains the main method.
I'll call the main method
and that opens the Terminal Window,
shows the Welcome message
and prompts for a player name.
In the final development increment
we added the ability to accept user input,
to convert that input into commands
and process those commands.
So, now I'm going to
type something at the command prompt.
I'm going to type go west, that should be
a valid command and we get some response to that.
Let's try help and that shows me that
the valid commands for the game are go, quit and help.
So let's try something else, go north.
And that tells me There's no door! so,
the go command is valid but there's no exit
to my current room that is called north.
Now let's try something that isn't a valid command
in this game, let's say run.
And I get a message that shows that that
wasn't a valid command.
Finally let's finish the game by typing the command
quit and the game finishes.
That's all very well,
but you wouldn't normally expect users of a programme
to have to have BlueJ open
in order to run the programme.
The user will typically run a programme
by clicking or tapping an icon
or by typing a command
at the system command prompt.
This programme has a purely text based interface
so it needs to be run in Windows
from the command prompt.
So I am going to close the Terminal Window down
in BlueJ and show you how to do that.
To run the programme outside BlueJ
it's convenient to package all the classes
in the BlueJ project into a single executable file
called a Jar file and BlueJ provides an option for this
Create Jar File.
That prompts me for the Main class that's the class that
contains the main method as the start point
for the programme so in this case
that's going to be the Game class.
I don't need any of these other options
so I'll click continue
and then I just need to save the jar file
in a convenient place in the file system.
I will give it a name adventure.
And click Create.
I've now opened a Windows command prompt
in the folder where I saved the Jar file
so I'm ready to run the programme.
To run a Java programme
I have to type the command java
and I packaged the programme as a Jar file
so I need to use the option -jar
and then type the name of the Jar file itself.
And that starts the programme
and shows the welcome message as before.
And I interact with it exactly as I did
when I ran from BlueJ.
I can enter a Player name
and then I can start typing commands.
I'm just going to type exactly the same commands
as I did before
and I should get exactly the same response.
Let's try help, go north
then an invalid command
and finally the quit command
which should terminate the programme
and I'm back at the command prompt.
So this demo
my Jar file was in my current command prompt folder
and I was able just to specify the name of the Jar file.
If the Jar file was somewhere else in the file system
I would have had to put the full path to the Jar file here.
It's worth noting
that this demo was done on a Windows computer
but you can run a Java programme
from a command prompt in exactly the same way
on other systems such as a Mac or a Linux computer.