WEBVTT 1 00:00:00.119 --> 00:00:02.110 In this demo I'm going to run the 2 00:00:02.112 --> 00:00:05.001 completed adventure game programme in BlueJ. 3 00:00:05.110 --> 00:00:07.002 And I'm also going to show you how to run it 4 00:00:07.004 --> 00:00:09.221 as a user might without BlueJ. 5 00:00:10.119 --> 00:00:12.007 First I'll run in BlueJ. 6 00:00:12.009 --> 00:00:14.001 I'll right click on the Game Class 7 00:00:14.003 --> 00:00:16.008 which contains the main method. 8 00:00:16.221 --> 00:00:18.220 I'll call the main method 9 00:00:19.119 --> 00:00:21.114 and that opens the Terminal Window, 10 00:00:21.117 --> 00:00:22.227 shows the Welcome message 11 00:00:22.229 --> 00:00:25.224 and prompts for a player name. 12 00:00:30.006 --> 00:00:31.228 In the final development increment 13 00:00:32.001 --> 00:00:34.222 we added the ability to accept user input, 14 00:00:35.007 --> 00:00:37.007 to convert that input into commands 15 00:00:37.009 --> 00:00:38.224 and process those commands. 16 00:00:38.229 --> 00:00:40.114 So, now I'm going to 17 00:00:40.220 --> 00:00:42.221 type something at the command prompt. 18 00:00:43.000 --> 00:00:46.002 I'm going to type go west, that should be 19 00:00:46.110 --> 00:00:50.006 a valid command and we get some response to that. 20 00:00:52.223 --> 00:00:56.226 Let's try help and that shows me that 21 00:00:56.227 --> 00:01:00.225 the valid commands for the game are go, quit and help. 22 00:01:01.224 --> 00:01:04.225 So let's try something else, go north. 23 00:01:05.222 --> 00:01:07.117 And that tells me There's no door! so, 24 00:01:07.222 --> 00:01:10.227 the go command is valid but there's no exit 25 00:01:11.000 --> 00:01:14.000 to my current room that is called north. 26 00:01:15.117 --> 00:01:18.113 Now let's try something that isn't a valid command 27 00:01:18.117 --> 00:01:21.224 in this game, let's say run. 28 00:01:22.115 --> 00:01:24.007 And I get a message that shows that that 29 00:01:24.009 --> 00:01:25.226 wasn't a valid command. 30 00:01:26.003 --> 00:01:29.225 Finally let's finish the game by typing the command 31 00:01:30.007 --> 00:01:33.001 quit and the game finishes. 32 00:01:34.228 --> 00:01:36.006 That's all very well, 33 00:01:36.112 --> 00:01:38.228 but you wouldn't normally expect users of a programme 34 00:01:39.000 --> 00:01:40.112 to have to have BlueJ open 35 00:01:40.114 --> 00:01:41.229 in order to run the programme. 36 00:01:42.221 --> 00:01:44.223 The user will typically run a programme 37 00:01:44.227 --> 00:01:47.003 by clicking or tapping an icon 38 00:01:47.009 --> 00:01:48.119 or by typing a command 39 00:01:48.221 --> 00:01:50.116 at the system command prompt. 39 00:01:52.118 --> 00:01:55.008 This programme has a purely text based interface 40 00:01:55.110 --> 00:01:56.225 so it needs to be run in Windows 41 00:01:56.227 --> 00:01:58.009 from the command prompt. 42 00:01:59.002 --> 00:02:01.114 So I am going to close the Terminal Window down 43 00:02:01.118 --> 00:02:04.116 in BlueJ and show you how to do that. 44 00:02:07.009 --> 00:02:09.003 To run the programme outside BlueJ 45 00:02:09.005 --> 00:02:11.007 it's convenient to package all the classes 46 00:02:11.110 --> 00:02:14.110 in the BlueJ project into a single executable file 47 00:02:14.112 --> 00:02:18.006 called a Jar file and BlueJ provides an option for this 48 00:02:18.112 --> 00:02:20.000 Create Jar File. 49 00:02:20.220 --> 00:02:23.006 That prompts me for the Main class that's the class that 50 00:02:23.008 --> 00:02:25.117 contains the main method as the start point 51 00:02:25.119 --> 00:02:27.119 for the programme so in this case 52 00:02:27.224 --> 00:02:30.001 that's going to be the Game class. 53 00:02:30.117 --> 00:02:32.116 I don't need any of these other options 54 00:02:32.220 --> 00:02:34.228 so I'll click continue 55 00:02:35.112 --> 00:02:37.118 and then I just need to save the jar file 56 00:02:37.220 --> 00:02:40.006 in a convenient place in the file system. 57 00:02:40.221 --> 00:02:44.229 I will give it a name adventure. 58 00:02:46.002 --> 00:02:48.110 And click Create. 59 00:02:51.006 --> 00:02:53.004 I've now opened a Windows command prompt 60 00:02:53.006 --> 00:02:55.006 in the folder where I saved the Jar file 61 00:02:55.110 --> 00:02:57.003 so I'm ready to run the programme. 62 00:02:57.118 --> 00:02:58.224 To run a Java programme 63 00:02:58.226 --> 00:03:01.001 I have to type the command java 64 00:03:01.226 --> 00:03:04.002 and I packaged the programme as a Jar file 65 00:03:04.004 --> 00:03:07.112 so I need to use the option -jar 66 00:03:07.227 --> 00:03:11.118 and then type the name of the Jar file itself. 67 00:03:12.229 --> 00:03:14.008 And that starts the programme 68 00:03:14.110 --> 00:03:16.226 and shows the welcome message as before. 69 00:03:18.003 --> 00:03:20.225 And I interact with it exactly as I did 70 00:03:20.227 --> 00:03:22.004 when I ran from BlueJ. 71 00:03:22.008 --> 00:03:24.119 I can enter a Player name 72 00:03:25.003 --> 00:03:27.228 and then I can start typing commands. 73 00:03:28.005 --> 00:03:30.009 I'm just going to type exactly the same commands 74 00:03:30.111 --> 00:03:31.009 as I did before 75 00:03:31.114 --> 00:03:34.113 and I should get exactly the same response. 76 00:03:35.222 --> 00:03:40.228 Let's try help, go north 77 00:03:41.221 --> 00:03:44.112 then an invalid command 78 00:03:44.221 --> 00:03:46.221 and finally the quit command 79 00:03:46.224 --> 00:03:49.008 which should terminate the programme 80 00:03:49.114 --> 00:03:52.000 and I'm back at the command prompt. 81 00:03:54.225 --> 00:03:55.116 So this demo 82 00:03:55.118 --> 00:03:58.114 my Jar file was in my current command prompt folder 83 00:03:59.001 --> 00:04:02.110 and I was able just to specify the name of the Jar file. 84 00:04:02.224 --> 00:04:05.008 If the Jar file was somewhere else in the file system 85 00:04:05.111 --> 00:04:08.113 I would have had to put the full path to the Jar file here. 86 00:04:11.111 --> 00:04:12.007 It's worth noting 87 00:04:12.009 --> 00:04:14.113 that this demo was done on a Windows computer 88 00:04:14.116 --> 00:04:16.003 but you can run a Java programme 89 00:04:16.005 --> 00:04:18.110 from a command prompt in exactly the same way 90 00:04:18.112 --> 00:04:21.226 on other systems such as a Mac or a Linux computer.