WEBVTT 1 00:00:00.227 --> 00:00:02.117 The Command class allows an object 2 00:00:02.119 --> 00:00:04.119 to be created that represents the action 3 00:00:04.221 --> 00:00:06.228 that the player wants to take during a turn. 4 00:00:08.009 --> 00:00:10.008 In this demo I'm going to create a couple 5 00:00:10.110 --> 00:00:12.221 of Command objects and see what they look like. 6 00:00:14.112 --> 00:00:16.111 So let's create a Command object. 7 00:00:17.111 --> 00:00:20.117 In the game a command can consist of two words 8 00:00:20.227 --> 00:00:23.006 known as the commandWord and the secondWord 9 00:00:23.221 --> 00:00:24.221 all one word. 10 00:00:25.113 --> 00:00:28.110 And the Command object can represent either situation. 11 00:00:30.009 --> 00:00:31.008 I'm going to start by 12 00:00:31.110 --> 00:00:33.112 creating a command that has two words. 13 00:00:33.119 --> 00:00:35.220 So I need to provide two parameters 14 00:00:35.222 --> 00:00:38.116 for the constructor representing those two words. 15 00:00:39.005 --> 00:00:41.223 It doesn't actually matter what those words are, 16 00:00:41.225 --> 00:00:43.118 at the moment, the command itself 17 00:00:43.222 --> 00:00:46.224 doesn't have any sense of what is or isn't 18 00:00:46.226 --> 00:00:49.008 a valid command that makes sense in the game. 19 00:00:49.224 --> 00:00:52.224 Checking for valid commands is done somewhere else. 20 00:00:53.008 --> 00:00:57.001 So let's just choose a couple of words 21 00:01:01.229 --> 00:01:05.009 and ok to that. 22 00:01:05.118 --> 00:01:08.113 And the object should be created in the object bench 23 00:01:08.119 --> 00:01:09.226 and there it is. 24 00:01:10.116 --> 00:01:12.008 Let's inspect the object 25 00:01:12.228 --> 00:01:15.224 and I see that it's failed by simply the two words 26 00:01:15.226 --> 00:01:18.113 that I entered when the object was created. 27 00:01:20.004 --> 00:01:22.003 Let's look at the methods. 28 00:01:23.110 --> 00:01:26.116 It has getAMethods for the two fields 29 00:01:28.110 --> 00:01:30.114 and it has a a couple of other methods. 30 00:01:31.113 --> 00:01:34.111 hasSecondWord is going to return true 31 00:01:34.118 --> 00:01:37.228 if the object has a second word 32 00:01:38.112 --> 00:01:40.227 and the one that I created did have two words 33 00:01:40.229 --> 00:01:44.113 so that should return true, which it does. 34 00:01:46.229 --> 00:01:49.115 The last method is called isUnknown 35 00:01:49.225 --> 00:01:51.110 and I want to look at the code for that 36 00:01:51.113 --> 00:01:53.114 before I try calling the method. 37 00:01:54.117 --> 00:01:58.113 So here's the method and that simply returns true 38 00:01:59.007 --> 00:02:01.112 if the commandWord, the first word, 39 00:02:01.115 --> 00:02:03.003 equals the question mark 40 00:02:03.005 --> 00:02:05.007 it will return false if the commandWord 41 00:02:05.009 --> 00:02:07.227 is anything other than a question mark. 42 00:02:09.223 --> 00:02:12.114 So that should for this command that should return 43 00:02:12.117 --> 00:02:14.110 false because the commandWord 44 00:02:14.118 --> 00:02:17.118 wasn't a question mark and indeed it does. 45 00:02:20.111 --> 00:02:22.119 I said when I created the Command object 46 00:02:22.222 --> 00:02:24.009 that the Command class itself 47 00:02:24.112 --> 00:02:25.223 doesn't have a way of checking 48 00:02:25.226 --> 00:02:27.110 whether the words that I entered 49 00:02:27.112 --> 00:02:29.225 make sense as valid commands in the game. 50 00:02:31.000 --> 00:02:33.004 However, when you create a Command object 51 00:02:33.006 --> 00:02:35.221 it is possible to store in that object 52 00:02:36.004 --> 00:02:38.111 the fact that it is an invalid command 53 00:02:38.220 --> 00:02:41.224 and have this reported using the isUnknown method. 54 00:02:42.007 --> 00:02:44.118 Let's create an invalid command. 55 00:02:46.114 --> 00:02:50.222 All I have to do to do that is create a command 56 00:02:50.228 --> 00:02:54.115 with a question mark commandWord 57 00:02:54.228 --> 00:02:59.118 and any other command word we want. 58 00:03:02.002 --> 00:03:05.113 So this time our command if we 59 00:03:06.005 --> 00:03:10.112 call isUnknown should return true. 60 00:03:12.226 --> 00:03:14.225 It may seem a bit strange at the moment 61 00:03:14.227 --> 00:03:17.225 that a command object can't check when it's created, 62 00:03:17.227 --> 00:03:19.007 whether or not it's valid 63 00:03:19.114 --> 00:03:22.115 but it can store the fact of being invalid. 64 00:03:23.006 --> 00:03:25.116 This should make more sense shortly when you see 65 00:03:25.118 --> 00:03:28.006 how commands are actually created in the game. 66 00:03:30.007 --> 00:03:32.111 For now though I'm going to finish this demo 67 00:03:32.113 --> 00:03:34.009 by creating one more Command object 68 00:03:34.112 --> 00:03:38.002 in this case the command with just one word. 69 00:03:39.117 --> 00:03:44.002 So, I need to supply the commandWord as before 70 00:03:44.118 --> 00:03:46.113 but I don't want it to have a secondWord 71 00:03:46.116 --> 00:03:48.114 so I'm just going to put null 72 00:03:48.117 --> 00:03:51.006 in here so there's no second word. 73 00:03:53.007 --> 00:03:56.118 And if I Inspect the object you can see 74 00:03:56.222 --> 00:04:00.110 that the second word field is indeed null 75 00:04:01.003 --> 00:04:04.227 and now if I call the hasSecondWord method 76 00:04:05.113 --> 00:04:07.221 that returns false. 77 00:04:11.002 --> 00:04:13.004 So the Command class is very simple 78 00:04:13.009 --> 00:04:14.223 but it does allow us to represent 79 00:04:14.225 --> 00:04:17.119 commands that have either one word or two words 80 00:04:18.004 --> 00:04:21.116 and are either valid or invalid commands. 81 00:04:23.002 --> 00:04:24.226 However, the Command class itself 82 00:04:24.228 --> 00:04:25.229 doesn't have knowledge 83 00:04:26.001 --> 00:04:28.009 of the valid command words for this game. 84 00:04:28.228 --> 00:04:30.118 That knowledge, as you'll see shortly, 85 00:04:30.221 --> 00:04:33.002 is within another class in the programme.