WEBVTT 1 00:00:02.471 --> 00:00:04.212 So in this video, we're gonna start 2 00:00:04.212 --> 00:00:06.253 talking about an object-orientated term 3 00:00:06.253 --> 00:00:09.024 called inheritance, or called inheritance, 4 00:00:09.024 --> 00:00:13.003 and specifically how that applies to Python programming. 5 00:00:13.003 --> 00:00:14.464 So I'm gonna start off by explaining 6 00:00:14.464 --> 00:00:15.883 what inheritance is, 7 00:00:15.883 --> 00:00:17.653 and then we'll move into some coding 8 00:00:17.653 --> 00:00:20.443 to go through some examples of inheritance, 9 00:00:20.443 --> 00:00:22.223 and inheritance in Python, 10 00:00:22.223 --> 00:00:23.843 and also gonna give you an overview 11 00:00:23.843 --> 00:00:26.499 of the benefits it can bring to your code. 12 00:00:26.499 --> 00:00:30.666 So let's swing over to a slide and go through that. 13 00:00:31.510 --> 00:00:32.998 Okay, so let's talk about 14 00:00:32.998 --> 00:00:36.408 a real world example of inheritance. 15 00:00:36.408 --> 00:00:38.933 Now, different types of objects in the real world 16 00:00:38.933 --> 00:00:43.443 can have a certain amount in common with each other. 17 00:00:43.443 --> 00:00:48.407 For example, a seagull, a crow, and an eagle are all birds, 18 00:00:48.407 --> 00:00:51.089 and so are ostriches and penguins. 19 00:00:51.089 --> 00:00:52.219 So in other words, they share 20 00:00:52.219 --> 00:00:54.873 their being-a-bird trait, so to speak. 21 00:00:54.873 --> 00:00:56.571 They all have a beak and wings, 22 00:00:56.571 --> 00:00:58.763 things that they inherit by virtue 23 00:00:58.763 --> 00:01:00.430 of them being birds. 24 00:01:02.971 --> 00:01:05.730 Another example is Monopoly, the board game, 25 00:01:05.730 --> 00:01:09.403 Blackjack the card game, and Halo the computer game. 26 00:01:09.403 --> 00:01:11.011 They're all inherently games, 27 00:01:11.011 --> 00:01:12.643 so again, they share that trait, 28 00:01:12.643 --> 00:01:14.653 the trait of being a game. 29 00:01:14.653 --> 00:01:16.685 But they're also different as well. 30 00:01:16.685 --> 00:01:18.853 Now, while they do share similarities, 31 00:01:18.853 --> 00:01:21.005 they are different in their own right. 32 00:01:21.005 --> 00:01:23.323 And as I mentioned, Monopoly is a board game, 33 00:01:23.323 --> 00:01:25.483 Blackjack is a card game, and of course, 34 00:01:25.483 --> 00:01:27.233 Halo is a video game. 35 00:01:29.039 --> 00:01:31.855 So the point here is that they share similar properties, 36 00:01:31.855 --> 00:01:33.575 being a game in this case, 37 00:01:33.575 --> 00:01:36.314 but also they've got differences as well. 38 00:01:36.314 --> 00:01:38.101 Now, for example, Halo, being a video game, 39 00:01:38.101 --> 00:01:39.682 as I mentioned, and it works 40 00:01:39.682 --> 00:01:42.208 on a video game console or a computer. 41 00:01:42.208 --> 00:01:44.232 Likewise, Blackjack is a card game, 42 00:01:44.232 --> 00:01:45.912 and Monopoly is a board game, 43 00:01:45.912 --> 00:01:48.312 but of course they can still work on a computer. 44 00:01:48.312 --> 00:01:53.306 There's a computer version of both of those games. 45 00:01:53.306 --> 00:01:56.375 Now, getting back to the birds example, 46 00:01:56.375 --> 00:01:58.451 now our birds do share a lot of traits. 47 00:01:58.451 --> 00:02:00.331 They all have feathers, for example, 48 00:02:00.331 --> 00:02:04.052 and that's one of the things that makes them birds. 49 00:02:04.052 --> 00:02:07.820 So what we can do is, we can define a base class 50 00:02:07.820 --> 00:02:09.940 that objects are based on in Python, 51 00:02:09.940 --> 00:02:11.180 things that are common for classes 52 00:02:11.180 --> 00:02:13.662 that derive from the base class. 53 00:02:13.662 --> 00:02:15.002 And then we can allow a class 54 00:02:15.002 --> 00:02:18.367 to define the unique characteristics of itself. 55 00:02:18.367 --> 00:02:20.574 So in other words, we have a base class, 56 00:02:20.574 --> 00:02:22.723 then something that inherits from that 57 00:02:22.723 --> 00:02:26.890 to make it something else again, making it unique. 58 00:02:28.623 --> 00:02:31.054 Now, the base class in this example here is bird. 59 00:02:31.054 --> 00:02:34.567 You can see, you can see the bird example in the image. 60 00:02:34.567 --> 00:02:38.695 And from that, all the birds inherit a beak and wings. 61 00:02:38.695 --> 00:02:40.176 But each type of bird also has things 62 00:02:40.176 --> 00:02:42.275 that make it different from the others. 63 00:02:42.275 --> 00:02:45.405 Now, eagles have incredibly good eyesight, for example. 64 00:02:45.405 --> 00:02:46.445 Now while you may be pleased 65 00:02:46.445 --> 00:02:49.120 if you spot a MacDonald's from 400 metres, 66 00:02:49.120 --> 00:02:51.585 eagles can literally see things two miles away. 67 00:02:51.585 --> 00:02:53.417 They can see a rabbit two miles away, 68 00:02:53.417 --> 00:02:55.417 which is pretty amazing. 69 00:02:57.426 --> 00:03:00.355 So all our birds inherit some base properties 70 00:03:00.355 --> 00:03:01.907 from their base class, 71 00:03:01.907 --> 00:03:05.038 which is often referred to as the superclass. 72 00:03:05.038 --> 00:03:06.886 Now they also inherit methods, 73 00:03:06.886 --> 00:03:09.158 so all our birds can walk and eat, 74 00:03:09.158 --> 00:03:11.638 but the individual bird classes also have 75 00:03:11.638 --> 00:03:14.678 their own unique properties and methods. 76 00:03:14.678 --> 00:03:16.716 So in this case, penguins can swim, 77 00:03:16.716 --> 00:03:19.633 and ostriches can run, for example. 78 00:03:21.576 --> 00:03:23.457 Now these individual bird classes 79 00:03:23.457 --> 00:03:26.016 are referred to as subclasses. 80 00:03:26.016 --> 00:03:28.343 So crow is a subclass of bird, 81 00:03:28.343 --> 00:03:31.534 which makes bird a superclass of crow. 82 00:03:31.534 --> 00:03:34.168 Now the idea of subclassing can be taken further, 83 00:03:34.168 --> 00:03:36.908 so we could add subclasses of bird, 84 00:03:36.908 --> 00:03:40.241 such as flying bird and flightless bird. 85 00:03:42.320 --> 00:03:44.829 Now, eagle is a subclass of flying bird, 86 00:03:44.829 --> 00:03:47.901 and ostrich is a subclass of flightless bird. 87 00:03:47.901 --> 00:03:50.892 In our example, eagles, crows, and gulls 88 00:03:50.892 --> 00:03:55.059 inherit the ability to fly from the flying bird superclass. 89 00:03:57.452 --> 00:03:59.930 Ostriches and penguins aren't inheriting anything 90 00:03:59.930 --> 00:04:03.110 from their flightless bird superclass in this example, 91 00:04:03.110 --> 00:04:05.332 but they still inherit their beaks and wings 92 00:04:05.332 --> 00:04:07.610 from the bird superclass. 93 00:04:07.610 --> 00:04:09.420 Now, ostriches have a run method, 94 00:04:09.420 --> 00:04:11.350 and penguins have a swim method, 95 00:04:11.350 --> 00:04:14.100 so a class can introduce other properties and methods 96 00:04:14.100 --> 00:04:17.517 in addition to the ones that it inherits. 97 00:04:19.505 --> 00:04:22.829 So a class can have more than one superclass in a hierarchy, 98 00:04:22.829 --> 00:04:24.339 like in this slide. 99 00:04:24.339 --> 00:04:26.848 Now in Python, classes can inherit directly 100 00:04:26.848 --> 00:04:28.639 from several superclasses, 101 00:04:28.639 --> 00:04:31.166 which is known as multiple inheritance. 102 00:04:31.166 --> 00:04:34.099 Now, many programming languages don't allow this, 103 00:04:34.099 --> 00:04:36.059 so the class structure ends up being 104 00:04:36.059 --> 00:04:40.239 strictly hierarchical, as I've shown here. 105 00:04:40.239 --> 00:04:41.750 Java classes, for example, 106 00:04:41.750 --> 00:04:43.608 can have more than one superclass, 107 00:04:43.608 --> 00:04:46.108 but it has to be hierarchical. 108 00:04:48.119 --> 00:04:50.808 Now, Python does allow multiple inheritance, 109 00:04:50.808 --> 00:04:52.968 but I strongly recommend you avoid it 110 00:04:52.968 --> 00:04:54.488 until you're really comfortable 111 00:04:54.488 --> 00:04:56.880 with classes and inheritance. 112 00:04:56.880 --> 00:04:58.040 And once you're really comfortable 113 00:04:58.040 --> 00:04:59.480 with classes and inheritance, 114 00:04:59.480 --> 00:05:02.550 I recommend you avoid multiple inheritance. (chuckles) 115 00:05:02.550 --> 00:05:04.324 Seriously, though, I do recommend you 116 00:05:04.324 --> 00:05:07.111 really look at avoiding multiple inheritance. 117 00:05:07.111 --> 00:05:10.210 Now the sphinx may have inherited the head of a human, 118 00:05:10.210 --> 00:05:13.591 the body of a lion, and the wings of a bird, 119 00:05:13.591 --> 00:05:16.580 but you don't see many sphinxes wandering around. 120 00:05:16.580 --> 00:05:19.280 So if nature's decided that multiple inheritance, 121 00:05:19.280 --> 00:05:22.030 is a bad idea, who am I to argue? 122 00:05:25.138 --> 00:05:27.224 Seriously though, having said that, 123 00:05:27.224 --> 00:05:30.920 multiple inheritance can be an extremely powerful tool 124 00:05:30.920 --> 00:05:33.694 when used correctly, but I'm not going to cover 125 00:05:33.694 --> 00:05:35.584 multiple inheritance in this course, 126 00:05:35.584 --> 00:05:38.286 but what I will do is mention it now and then 127 00:05:38.286 --> 00:05:40.927 to point out places where you could really 128 00:05:40.927 --> 00:05:42.255 hit some of the pitfalls, 129 00:05:42.255 --> 00:05:44.474 if you decided to use multiple inheritance 130 00:05:44.474 --> 00:05:48.641 or a multiple inheritance relationship in the future. 131 00:05:50.936 --> 00:05:53.646 So coming back to our examples here, 132 00:05:53.646 --> 00:05:56.286 flying bird is a subclass of bird, 133 00:05:56.286 --> 00:05:59.297 and eagle is a subclass of flying bird. 134 00:05:59.297 --> 00:06:01.746 Now eagle is also a subclass of bird, 135 00:06:01.746 --> 00:06:04.937 because its immediate superclass, flying bird, 136 00:06:04.937 --> 00:06:06.946 is a subclass of bird. 137 00:06:06.946 --> 00:06:09.387 So just to labour the point one more time, 138 00:06:09.387 --> 00:06:12.657 flying bird is a superclass of the three classes 139 00:06:12.657 --> 00:06:16.824 eagle, crow, and gull, and it's also a subclass of bird. 140 00:06:20.440 --> 00:06:22.238 So you might be asking at this point, 141 00:06:22.238 --> 00:06:23.419 "Tim, why should I bother to go 142 00:06:23.419 --> 00:06:25.688 "through all this level of complexity?" 143 00:06:25.688 --> 00:06:27.688 Well, in answer to that, firstly, 144 00:06:27.688 --> 00:06:29.677 it allows you to write code once, 145 00:06:29.677 --> 00:06:31.968 and then for that code to be used automatically 146 00:06:31.968 --> 00:06:33.504 by other classes. 147 00:06:33.504 --> 00:06:35.505 Now, if we created an eagle object, 148 00:06:35.505 --> 00:06:38.112 it would automatically get beak and wing, 149 00:06:38.112 --> 00:06:39.565 and wings properties, 150 00:06:39.565 --> 00:06:42.011 together with any methods that we'd created, 151 00:06:42.011 --> 00:06:44.579 or we had created, in the bird class, 152 00:06:44.579 --> 00:06:46.179 and that's without us having to write 153 00:06:46.179 --> 00:06:48.512 any code in the eagle class. 154 00:06:51.214 --> 00:06:52.368 So this leave you to define 155 00:06:52.368 --> 00:06:54.913 the unique characteristics of a class, 156 00:06:54.913 --> 00:06:56.915 rather than having to reinvent the wheel 157 00:06:56.915 --> 00:06:59.496 each time you create a new class. 158 00:06:59.496 --> 00:07:01.656 So in other words, you can write that code once, 159 00:07:01.656 --> 00:07:03.746 put that code in the super class, 160 00:07:03.746 --> 00:07:08.505 and then any class that extends or inherits from that class, 161 00:07:08.505 --> 00:07:10.184 they're the same thing effectively, 162 00:07:10.184 --> 00:07:12.096 is going to be able to take advantage 163 00:07:12.096 --> 00:07:13.765 of the properties or methods 164 00:07:13.765 --> 00:07:16.304 that are defined in the superclass. 165 00:07:16.304 --> 00:07:18.445 All right, so that's our overview of inheritance. 166 00:07:18.445 --> 00:07:20.335 Let's go back to the code 167 00:07:20.335 --> 00:07:24.502 and start working at an example in our game project. 168 00:07:26.607 --> 00:07:28.978 All right, so we're gonna continue with the game project 169 00:07:28.978 --> 00:07:30.648 that we created in the previous video, 170 00:07:30.648 --> 00:07:32.386 just to make sure that, 171 00:07:32.386 --> 00:07:34.477 so make sure you've got that class, 172 00:07:34.477 --> 00:07:36.058 that project open. 173 00:07:36.058 --> 00:07:38.528 Now, we're going to open the project pane, 174 00:07:38.528 --> 00:07:41.998 and we're going to create a superclass called enemy. 175 00:07:41.998 --> 00:07:43.648 And this'll be the base class 176 00:07:43.648 --> 00:07:46.197 for all the things our players will have to fight 177 00:07:46.197 --> 00:07:48.138 in this fictional game. 178 00:07:48.138 --> 00:07:49.759 So I'm gonna right-click on the project here, 179 00:07:49.759 --> 00:07:52.138 and we're gonna create a new Python file. 180 00:07:52.138 --> 00:07:54.115 Select Python file, we're gonna call this enemy, 181 00:07:54.115 --> 00:07:57.239 making sure it's a lowercase E at the start there. 182 00:07:57.239 --> 00:07:59.926 And click on okay, or press enter. 183 00:07:59.926 --> 00:08:02.047 And we're gonna work on this class now. 184 00:08:02.047 --> 00:08:03.449 Now we're gonna store hit points 185 00:08:03.449 --> 00:08:05.367 and also the number of lives, 186 00:08:05.367 --> 00:08:07.868 and we're gonna need to initialise the attributes for those. 187 00:08:07.868 --> 00:08:09.471 And we should also give the enemy a name. 188 00:08:09.471 --> 00:08:13.638 So let's start with a class definition, class enemy. 189 00:08:15.428 --> 00:08:19.428 And we'll do a def, parameter constructor, init. 190 00:08:20.894 --> 00:08:22.774 And we're going to include some extra parameters, 191 00:08:22.774 --> 00:08:24.524 so name equals enemy, 192 00:08:26.166 --> 00:08:29.749 and hit underscore points is equal to zero, 193 00:08:31.768 --> 00:08:33.935 and lives is equal to one. 194 00:08:37.185 --> 00:08:40.685 Then we're gonna do self.name equals name, 195 00:08:43.480 --> 00:08:47.689 self.hit underscore points equals hit points. 196 00:08:47.689 --> 00:08:50.439 And then self.lives equals lives. 197 00:08:53.250 --> 00:08:55.019 So this is a superclass, 198 00:08:55.019 --> 00:08:57.953 and any class that extends this class or inherits, 199 00:08:57.953 --> 00:09:00.699 or inherits from this class, enemy, 200 00:09:00.699 --> 00:09:04.299 should always have name, hit points, and lives attributes, 201 00:09:04.299 --> 00:09:06.939 and in the game scenario, it's probably quite reasonable 202 00:09:06.939 --> 00:09:11.150 to assume that any enemy would have those attributes. 203 00:09:11.150 --> 00:09:13.470 But let's also add a method, 204 00:09:13.470 --> 00:09:15.887 which we'll call take damage. 205 00:09:17.331 --> 00:09:19.930 So we're gonna do a def, take underscore damage, 206 00:09:19.930 --> 00:09:21.847 to create a new method. 207 00:09:22.691 --> 00:09:26.289 And it's going to have one parameter, damage. 208 00:09:26.289 --> 00:09:29.206 And we're gonna do remaining points 209 00:09:31.708 --> 00:09:35.875 is equal to self.hit underscore points, take damage. 210 00:09:38.028 --> 00:09:41.468 Then we're gonna put if, remaining points, 211 00:09:41.468 --> 00:09:44.775 is greater than or equal to zero, 212 00:09:44.775 --> 00:09:48.529 then we're gonna do self.hit underscore points 213 00:09:48.529 --> 00:09:51.048 equals remaining points, 214 00:09:51.048 --> 00:09:52.468 then we're gonna print a message. 215 00:09:52.468 --> 00:09:56.218 Print, I took, placement field points damage, 216 00:10:00.035 --> 00:10:04.202 and have, in another replacement field, left.format. 217 00:10:05.800 --> 00:10:09.967 We're going to do damage comma self.hit underscore points. 218 00:10:12.334 --> 00:10:16.265 And we're gonna have an else there, else, 219 00:10:16.265 --> 00:10:18.598 self.lives minus equals one. 220 00:10:21.134 --> 00:10:24.054 So what we're doing here is we're subtracting the damage 221 00:10:24.054 --> 00:10:26.385 from the number of hit points that the enemy has, 222 00:10:26.385 --> 00:10:29.177 and then checking to see if they've still got any left 223 00:10:29.177 --> 00:10:31.506 after that damage is inflicted. 224 00:10:31.506 --> 00:10:34.115 Now if the number remaining is zero or more, 225 00:10:34.115 --> 00:10:36.226 we update the hit points and print a message 226 00:10:36.226 --> 00:10:37.915 showing how much damage was taken, 227 00:10:37.915 --> 00:10:40.611 and also how many hit points are still left. 228 00:10:40.611 --> 00:10:43.083 But if, however, their hit points drop below zero, 229 00:10:43.083 --> 00:10:45.405 then we take a life off instead. 230 00:10:45.405 --> 00:10:46.664 Now we should probably check to see 231 00:10:46.664 --> 00:10:48.239 if we've got any lives left, 232 00:10:48.239 --> 00:10:50.197 but we're demonstrating concepts here, 233 00:10:50.197 --> 00:10:52.127 we're not creating a full game. 234 00:10:52.127 --> 00:10:53.567 This could be a useful exercise 235 00:10:53.567 --> 00:10:55.477 for you to try it yourself, though, 236 00:10:55.477 --> 00:10:56.697 to make sure you've understood 237 00:10:56.697 --> 00:10:59.138 what we've covered in this tutorial. 238 00:10:59.138 --> 00:11:01.386 All right, so we've got a basic class here. 239 00:11:01.386 --> 00:11:04.277 We're storing the name, hit points, and lives, 240 00:11:04.277 --> 00:11:06.695 and we've got a constructor where we can set, 241 00:11:06.695 --> 00:11:10.586 where we do set the initial value of those attributes. 242 00:11:10.586 --> 00:11:12.135 So I'm gonna add another method, 243 00:11:12.135 --> 00:11:13.687 which is basically a copy of this 244 00:11:13.687 --> 00:11:16.877 string method from the player class. 245 00:11:16.877 --> 00:11:18.584 Even though I could probably just copy it and change it, 246 00:11:18.584 --> 00:11:21.085 I'll just type it in, 'cause it's fairly short. 247 00:11:21.085 --> 00:11:22.548 So underscore underscore string, 248 00:11:22.548 --> 00:11:25.540 underscore underscore, self, 249 00:11:25.540 --> 00:11:27.641 and then we're gonna return, 250 00:11:27.641 --> 00:11:30.571 and it's going to be name, colon, 251 00:11:30.571 --> 00:11:32.856 starting your left replacement field, 252 00:11:32.856 --> 00:11:35.939 which is left curly brace, zero.name, 253 00:11:37.189 --> 00:11:41.558 right curly brace, comma, lives, colon, space, 254 00:11:41.558 --> 00:11:43.975 left curly brace, zero.lives, 255 00:11:44.898 --> 00:11:49.279 right curly brace, comma, space, hit points, 256 00:11:49.279 --> 00:11:53.446 colon, space, left curly brace, zero.hit underscore points, 257 00:11:54.544 --> 00:11:57.044 right curly brace.format self. 258 00:12:00.557 --> 00:12:03.058 Okay, so that's actually it. 259 00:12:03.058 --> 00:12:05.325 So okay, and we're using this to print out the attributes, 260 00:12:05.325 --> 00:12:07.115 so we don't have to keep writing long print statements 261 00:12:07.115 --> 00:12:09.281 to check that everything's working. 262 00:12:09.281 --> 00:12:11.314 Okay, so that stuff, that's similar to stuff 263 00:12:11.314 --> 00:12:14.354 I've already covered in earlier videos in this section. 264 00:12:14.354 --> 00:12:15.826 Now, we're not going to actually 265 00:12:15.826 --> 00:12:18.434 create enemy objects directly, 266 00:12:18.434 --> 00:12:20.674 although we could do that if we wanted to. 267 00:12:20.674 --> 00:12:24.485 But this is really just for use as a base class, 268 00:12:24.485 --> 00:12:26.594 so that all the specific enemies 269 00:12:26.594 --> 00:12:28.476 have these basic properties. 270 00:12:28.476 --> 00:12:30.257 So think about like a bird class. 271 00:12:30.257 --> 00:12:32.086 You don't get animals that are just birds. 272 00:12:32.086 --> 00:12:34.438 They're a particular type of bird. 273 00:12:34.438 --> 00:12:36.761 So I'm gonna create one enemy, enemy object, 274 00:12:36.761 --> 00:12:38.696 just to test the class, though, 275 00:12:38.696 --> 00:12:41.178 to make sure that everything's working 276 00:12:41.178 --> 00:12:43.248 before we go extending the class. 277 00:12:43.248 --> 00:12:45.998 So I'll go back to the main file. 278 00:12:47.298 --> 00:12:48.693 We're gonna delete all the code, now, 279 00:12:48.693 --> 00:12:50.667 that we've used to test the player class. 280 00:12:50.667 --> 00:12:53.341 So let's just delete all of that. 281 00:12:53.341 --> 00:12:55.613 Then we'll start on line five. 282 00:12:55.613 --> 00:12:59.780 And line five we're gonna type from enemy, import enemy. 283 00:13:04.138 --> 00:13:06.738 Then we're gonna do random underscore monster 284 00:13:06.738 --> 00:13:09.480 is equal to Enemy, capital E. 285 00:13:09.480 --> 00:13:13.149 And we'll just say, we'll call it basic enemy, 286 00:13:13.149 --> 00:13:14.810 then pass 12 for the number of hit points, 287 00:13:14.810 --> 00:13:17.040 and one for the number of lives. 288 00:13:17.040 --> 00:13:20.498 Then we're gonna print the random monster, 289 00:13:20.498 --> 00:13:21.331 then we're gonna do 290 00:13:21.331 --> 00:13:24.914 random monster.take underscore damage four, 291 00:13:26.080 --> 00:13:28.859 then we're gonna print random monster. 292 00:13:28.859 --> 00:13:30.119 Okay. 293 00:13:30.119 --> 00:13:34.108 Let's just run that and see if it's gonna work for us. 294 00:13:34.108 --> 00:13:36.428 And see, we've created the basic enemy, 295 00:13:36.428 --> 00:13:39.228 lives one, hit points 12, took four points of damage 296 00:13:39.228 --> 00:13:41.039 and they've got eight points left, 297 00:13:41.039 --> 00:13:42.199 eight hit points left, 298 00:13:42.199 --> 00:13:45.700 and we got confirmation at the second printout. 299 00:13:45.700 --> 00:13:46.920 All right, so let's take the, 300 00:13:46.920 --> 00:13:49.669 or let's test the take damage method a bit more. 301 00:13:49.669 --> 00:13:53.138 Let's see what happens when the hit points drop below zero. 302 00:13:53.138 --> 00:13:54.279 And actually, I'll clean this up completely 303 00:13:54.279 --> 00:13:56.438 and put this back onto line one. 304 00:13:56.438 --> 00:14:00.303 We don't need a player at all for now. 305 00:14:00.303 --> 00:14:02.941 So let's add a couple of extra lines here. 306 00:14:02.941 --> 00:14:05.608 So we'll do another eight there. 307 00:14:06.469 --> 00:14:08.160 It should take it to zero hit points, 308 00:14:08.160 --> 00:14:09.669 and then we'll do another one that takes another nine, 309 00:14:09.669 --> 00:14:11.160 just to see what happens. 310 00:14:11.160 --> 00:14:13.410 So let's actually run this. 311 00:14:14.587 --> 00:14:17.130 And you can see, we've got a basic enemy 12, 312 00:14:17.130 --> 00:14:19.436 lost four points, eight left, 313 00:14:19.436 --> 00:14:22.599 it had eight and then lost eight to have zero left. 314 00:14:22.599 --> 00:14:23.920 And then we've just got the printouts. 315 00:14:23.920 --> 00:14:26.727 The lives, you can see there, has dropped down to zero. 316 00:14:26.727 --> 00:14:28.127 So that's working fine. 317 00:14:28.127 --> 00:14:30.239 I do suggest you always test all the paths 318 00:14:30.239 --> 00:14:31.519 throughout your code. 319 00:14:31.519 --> 00:14:33.565 So if you put in some conditions like we did, 320 00:14:33.565 --> 00:14:36.238 when we check for the hit points dropping to below zero, 321 00:14:36.238 --> 00:14:37.704 they'll make sure you use data 322 00:14:37.704 --> 00:14:40.668 that will test the alternative path 323 00:14:40.668 --> 00:14:41.874 to make sure it works as well as 324 00:14:41.874 --> 00:14:45.244 the path you're assuming will work most of the time. 325 00:14:45.244 --> 00:14:47.205 All right, so I'm gonna finish the video here. 326 00:14:47.205 --> 00:14:48.505 In the next video, we're going to start 327 00:14:48.505 --> 00:14:49.905 getting into the good stuff. 328 00:14:49.905 --> 00:14:52.385 We're going to start inheriting from that class, 329 00:14:52.385 --> 00:14:54.369 and this is where it's going to be getting interesting. 330 00:14:54.369 --> 00:14:56.879 So I will see you in the next video.