1
00:00:05,560 --> 00:00:07,300
So in this video, we're gonna start

2
00:00:07,300 --> 00:00:09,340
talking about an object-orientated term

3
00:00:09,340 --> 00:00:12,110
called inheritance, or called inheritance,

4
00:00:12,110 --> 00:00:16,090
and specifically how that applies to Python programming.

5
00:00:16,090 --> 00:00:17,550
So I'm gonna start off by explaining

6
00:00:17,550 --> 00:00:18,970
what inheritance is,

7
00:00:18,970 --> 00:00:20,740
and then we'll move into some coding

8
00:00:20,740 --> 00:00:23,530
to go through some examples of inheritance,

9
00:00:23,530 --> 00:00:25,310
and inheritance in Python,

10
00:00:25,310 --> 00:00:26,930
and also gonna give you an overview

11
00:00:26,930 --> 00:00:29,580
of the benefits it can bring to your code.

12
00:00:29,580 --> 00:00:33,750
So let's swing over to a slide and go through that.

13
00:00:34,600 --> 00:00:36,080
Okay, so let's talk about

14
00:00:36,080 --> 00:00:39,490
a real world example of inheritance.

15
00:00:39,490 --> 00:00:42,020
Now, different types of objects in the real world

16
00:00:42,020 --> 00:00:46,530
can have a certain amount in common with each other.

17
00:00:46,530 --> 00:00:51,490
For example, a seagull, a crow, and an eagle are all birds,

18
00:00:51,490 --> 00:00:54,170
and so are ostriches and penguins.

19
00:00:54,170 --> 00:00:55,300
So in other words, they share

20
00:00:55,300 --> 00:00:57,960
their being-a-bird trait, so to speak.

21
00:00:57,960 --> 00:00:59,660
They all have a beak and wings,

22
00:00:59,660 --> 00:01:01,850
things that they inherit by virtue

23
00:01:01,850 --> 00:01:03,520
of them being birds.

24
00:01:06,060 --> 00:01:08,820
Another example is Monopoly, the board game,

25
00:01:08,820 --> 00:01:12,490
Blackjack the card game, and Halo the computer game.

26
00:01:12,490 --> 00:01:14,100
They're all inherently games,

27
00:01:14,100 --> 00:01:15,730
so again, they share that trait,

28
00:01:15,730 --> 00:01:17,740
the trait of being a game.

29
00:01:17,740 --> 00:01:19,770
But they're also different as well.

30
00:01:19,770 --> 00:01:21,940
Now, while they do share similarities,

31
00:01:21,940 --> 00:01:24,090
they are different in their own right.

32
00:01:24,090 --> 00:01:26,410
And as I mentioned, Monopoly is a board game,

33
00:01:26,410 --> 00:01:28,570
Blackjack is a card game, and of course,

34
00:01:28,570 --> 00:01:30,320
Halo is a video game.

35
00:01:32,120 --> 00:01:34,940
So the point here is that they share similar properties,

36
00:01:34,940 --> 00:01:36,660
being a game in this case,

37
00:01:36,660 --> 00:01:39,400
but also they've got differences as well.

38
00:01:39,400 --> 00:01:41,190
Now, for example, Halo, being a video game,

39
00:01:41,190 --> 00:01:42,770
as I mentioned, and it works

40
00:01:42,770 --> 00:01:45,290
on a video game console or a computer.

41
00:01:45,290 --> 00:01:47,320
Likewise, Blackjack is a card game,

42
00:01:47,320 --> 00:01:49,000
and Monopoly is a board game,

43
00:01:49,000 --> 00:01:51,400
but of course they can still work on a computer.

44
00:01:51,400 --> 00:01:56,390
There's a computer version of both of those games.

45
00:01:56,390 --> 00:01:59,460
Now, getting back to the birds example,

46
00:01:59,460 --> 00:02:01,540
now our birds do share a lot of traits.

47
00:02:01,540 --> 00:02:03,420
They all have feathers, for example,

48
00:02:03,420 --> 00:02:07,140
and that's one of the things that makes them birds.

49
00:02:07,140 --> 00:02:10,910
So what we can do is, we can define a base class

50
00:02:10,910 --> 00:02:13,030
that objects are based on in Python,

51
00:02:13,030 --> 00:02:14,270
things that are common for classes

52
00:02:14,270 --> 00:02:16,750
that derive from the base class.

53
00:02:16,750 --> 00:02:18,090
And then we can allow a class

54
00:02:18,090 --> 00:02:21,450
to define the unique characteristics of itself.

55
00:02:21,450 --> 00:02:23,660
So in other words, we have a base class,

56
00:02:23,660 --> 00:02:25,810
then something that inherits from that

57
00:02:25,810 --> 00:02:29,980
to make it something else again, making it unique.

58
00:02:31,710 --> 00:02:34,140
Now, the base class in this example here is bird.

59
00:02:34,140 --> 00:02:37,650
You can see, you can see the bird example in the image.

60
00:02:37,650 --> 00:02:41,780
And from that, all the birds inherit a beak and wings.

61
00:02:41,780 --> 00:02:43,260
But each type of bird also has things

62
00:02:43,260 --> 00:02:45,360
that make it different from the others.

63
00:02:45,360 --> 00:02:48,490
Now, eagles have incredibly good eyesight, for example.

64
00:02:48,490 --> 00:02:49,530
Now while you may be pleased

65
00:02:49,530 --> 00:02:52,210
if you spot a MacDonald's from 400 metres,

66
00:02:52,210 --> 00:02:54,670
eagles can literally see things two miles away.

67
00:02:54,670 --> 00:02:56,500
They can see a rabbit two miles away,

68
00:02:56,500 --> 00:02:58,500
which is pretty amazing.

69
00:03:00,510 --> 00:03:03,440
So all our birds inherit some base properties

70
00:03:03,440 --> 00:03:04,990
from their base class,

71
00:03:04,990 --> 00:03:08,120
which is often referred to as the superclass.

72
00:03:08,120 --> 00:03:09,970
Now they also inherit methods,

73
00:03:09,970 --> 00:03:12,240
so all our birds can walk and eat,

74
00:03:12,240 --> 00:03:14,720
but the individual bird classes also have

75
00:03:14,720 --> 00:03:17,760
their own unique properties and methods.

76
00:03:17,760 --> 00:03:19,800
So in this case, penguins can swim,

77
00:03:19,800 --> 00:03:22,720
and ostriches can run, for example.

78
00:03:24,660 --> 00:03:26,540
Now these individual bird classes

79
00:03:26,540 --> 00:03:29,100
are referred to as subclasses.

80
00:03:29,100 --> 00:03:31,430
So crow is a subclass of bird,

81
00:03:31,430 --> 00:03:34,620
which makes bird a superclass of crow.

82
00:03:34,620 --> 00:03:37,250
Now the idea of subclassing can be taken further,

83
00:03:37,250 --> 00:03:39,990
so we could add subclasses of bird,

84
00:03:39,990 --> 00:03:43,330
such as flying bird and flightless bird.

85
00:03:45,410 --> 00:03:47,910
Now, eagle is a subclass of flying bird,

86
00:03:47,910 --> 00:03:50,990
and ostrich is a subclass of flightless bird.

87
00:03:50,990 --> 00:03:53,980
In our example, eagles, crows, and gulls

88
00:03:53,980 --> 00:03:58,140
inherit the ability to fly from the flying bird superclass.

89
00:04:00,540 --> 00:04:03,020
Ostriches and penguins aren't inheriting anything

90
00:04:03,020 --> 00:04:06,200
from their flightless bird superclass in this example,

91
00:04:06,200 --> 00:04:08,420
but they still inherit their beaks and wings

92
00:04:08,420 --> 00:04:10,700
from the bird superclass.

93
00:04:10,700 --> 00:04:12,510
Now, ostriches have a run method,

94
00:04:12,510 --> 00:04:14,440
and penguins have a swim method,

95
00:04:14,440 --> 00:04:17,190
so a class can introduce other properties and methods

96
00:04:17,190 --> 00:04:20,600
in addition to the ones that it inherits.

97
00:04:22,590 --> 00:04:25,910
So a class can have more than one superclass in a hierarchy,

98
00:04:25,910 --> 00:04:27,420
like in this slide.

99
00:04:27,420 --> 00:04:29,930
Now in Python, classes can inherit directly

100
00:04:29,930 --> 00:04:31,720
from several superclasses,

101
00:04:31,720 --> 00:04:34,250
which is known as multiple inheritance.

102
00:04:34,250 --> 00:04:37,180
Now, many programming languages don't allow this,

103
00:04:37,180 --> 00:04:39,140
so the class structure ends up being

104
00:04:39,140 --> 00:04:43,320
strictly hierarchical, as I've shown here.

105
00:04:43,320 --> 00:04:44,840
Java classes, for example,

106
00:04:44,840 --> 00:04:46,690
can have more than one superclass,

107
00:04:46,690 --> 00:04:49,190
but it has to be hierarchical.

108
00:04:51,200 --> 00:04:53,890
Now, Python does allow multiple inheritance,

109
00:04:53,890 --> 00:04:56,050
but I strongly recommend you avoid it

110
00:04:56,050 --> 00:04:57,570
until you're really comfortable

111
00:04:57,570 --> 00:04:59,970
with classes and inheritance.

112
00:04:59,970 --> 00:05:01,130
And once you're really comfortable

113
00:05:01,130 --> 00:05:02,570
with classes and inheritance,

114
00:05:02,570 --> 00:05:05,640
I recommend you avoid multiple inheritance. (chuckles)

115
00:05:05,640 --> 00:05:07,410
Seriously, though, I do recommend you

116
00:05:07,410 --> 00:05:10,200
really look at avoiding multiple inheritance.

117
00:05:10,200 --> 00:05:13,300
Now the sphinx may have inherited the head of a human,

118
00:05:13,300 --> 00:05:16,680
the body of a lion, and the wings of a bird,

119
00:05:16,680 --> 00:05:19,670
but you don't see many sphinxes wandering around.

120
00:05:19,670 --> 00:05:22,370
So if nature's decided that multiple inheritance,

121
00:05:22,370 --> 00:05:25,120
is a bad idea, who am I to argue?

122
00:05:28,220 --> 00:05:30,310
Seriously though, having said that,

123
00:05:30,310 --> 00:05:34,010
multiple inheritance can be an extremely powerful tool

124
00:05:34,010 --> 00:05:36,780
when used correctly, but I'm not going to cover

125
00:05:36,780 --> 00:05:38,670
multiple inheritance in this course,

126
00:05:38,670 --> 00:05:41,370
but what I will do is mention it now and then

127
00:05:41,370 --> 00:05:44,010
to point out places where you could really

128
00:05:44,010 --> 00:05:45,340
hit some of the pitfalls,

129
00:05:45,340 --> 00:05:47,560
if you decided to use multiple inheritance

130
00:05:47,560 --> 00:05:51,730
or a multiple inheritance relationship in the future.

131
00:05:54,020 --> 00:05:56,730
So coming back to our examples here,

132
00:05:56,730 --> 00:05:59,370
flying bird is a subclass of bird,

133
00:05:59,370 --> 00:06:02,380
and eagle is a subclass of flying bird.

134
00:06:02,380 --> 00:06:04,830
Now eagle is also a subclass of bird,

135
00:06:04,830 --> 00:06:08,020
because its immediate superclass, flying bird,

136
00:06:08,020 --> 00:06:10,030
is a subclass of bird.

137
00:06:10,030 --> 00:06:12,470
So just to labour the point one more time,

138
00:06:12,470 --> 00:06:15,740
flying bird is a superclass of the three classes

139
00:06:15,740 --> 00:06:19,910
eagle, crow, and gull, and it's also a subclass of bird.

140
00:06:23,530 --> 00:06:25,320
So you might be asking at this point,

141
00:06:25,320 --> 00:06:26,500
"Tim, why should I bother to go

142
00:06:26,500 --> 00:06:28,770
"through all this level of complexity?"

143
00:06:28,770 --> 00:06:30,770
Well, in answer to that, firstly,

144
00:06:30,770 --> 00:06:32,760
it allows you to write code once,

145
00:06:32,760 --> 00:06:35,050
and then for that code to be used automatically

146
00:06:35,050 --> 00:06:36,590
by other classes.

147
00:06:36,590 --> 00:06:38,590
Now, if we created an eagle object,

148
00:06:38,590 --> 00:06:41,200
it would automatically get beak and wing,

149
00:06:41,200 --> 00:06:42,650
and wings properties,

150
00:06:42,650 --> 00:06:45,100
together with any methods that we'd created,

151
00:06:45,100 --> 00:06:47,660
or we had created, in the bird class,

152
00:06:47,660 --> 00:06:49,260
and that's without us having to write

153
00:06:49,260 --> 00:06:51,600
any code in the eagle class.

154
00:06:54,300 --> 00:06:55,450
So this leave you to define

155
00:06:55,450 --> 00:06:58,000
the unique characteristics of a class,

156
00:06:58,000 --> 00:07:00,000
rather than having to reinvent the wheel

157
00:07:00,000 --> 00:07:02,580
each time you create a new class.

158
00:07:02,580 --> 00:07:04,740
So in other words, you can write that code once,

159
00:07:04,740 --> 00:07:06,830
put that code in the super class,

160
00:07:06,830 --> 00:07:11,590
and then any class that extends or inherits from that class,

161
00:07:11,590 --> 00:07:13,270
they're the same thing effectively,

162
00:07:13,270 --> 00:07:15,180
is going to be able to take advantage

163
00:07:15,180 --> 00:07:16,850
of the properties or methods

164
00:07:16,850 --> 00:07:19,390
that are defined in the superclass.

165
00:07:19,390 --> 00:07:21,530
All right, so that's our overview of inheritance.

166
00:07:21,530 --> 00:07:23,420
Let's go back to the code

167
00:07:23,420 --> 00:07:27,590
and start working at an example in our game project.

168
00:07:29,690 --> 00:07:32,060
All right, so we're gonna continue with the game project

169
00:07:32,060 --> 00:07:33,730
that we created in the previous video,

170
00:07:33,730 --> 00:07:35,470
just to make sure that,

171
00:07:35,470 --> 00:07:37,560
so make sure you've got that class,

172
00:07:37,560 --> 00:07:39,140
that project open.

173
00:07:39,140 --> 00:07:41,610
Now, we're going to open the project pane,

174
00:07:41,610 --> 00:07:45,080
and we're going to create a superclass called enemy.

175
00:07:45,080 --> 00:07:46,730
And this'll be the base class

176
00:07:46,730 --> 00:07:49,280
for all the things our players will have to fight

177
00:07:49,280 --> 00:07:51,220
in this fictional game.

178
00:07:51,220 --> 00:07:52,840
So I'm gonna right-click on the project here,

179
00:07:52,840 --> 00:07:55,220
and we're gonna create a new Python file.

180
00:07:55,220 --> 00:07:57,200
Select Python file, we're gonna call this enemy,

181
00:07:57,200 --> 00:08:00,320
making sure it's a lowercase E at the start there.

182
00:08:00,320 --> 00:08:03,010
And click on okay, or press enter.

183
00:08:03,010 --> 00:08:05,130
And we're gonna work on this class now.

184
00:08:05,130 --> 00:08:06,530
Now we're gonna store hit points

185
00:08:06,530 --> 00:08:08,450
and also the number of lives,

186
00:08:08,450 --> 00:08:10,950
and we're gonna need to initialise the attributes for those.

187
00:08:10,950 --> 00:08:12,560
And we should also give the enemy a name.

188
00:08:12,560 --> 00:08:16,720
So let's start with a class definition, class enemy.

189
00:08:18,510 --> 00:08:22,510
And we'll do a def, parameter constructor, init.

190
00:08:23,980 --> 00:08:25,860
And we're going to include some extra parameters,

191
00:08:25,860 --> 00:08:27,610
so name equals enemy,

192
00:08:29,250 --> 00:08:32,830
and hit underscore points is equal to zero,

193
00:08:34,850 --> 00:08:37,020
and lives is equal to one.

194
00:08:40,270 --> 00:08:43,770
Then we're gonna do self.name equals name,

195
00:08:46,570 --> 00:08:50,770
self.hit underscore points equals hit points.

196
00:08:50,770 --> 00:08:53,520
And then self.lives equals lives.

197
00:08:56,340 --> 00:08:58,100
So this is a superclass,

198
00:08:58,100 --> 00:09:01,040
and any class that extends this class or inherits,

199
00:09:01,040 --> 00:09:03,780
or inherits from this class, enemy,

200
00:09:03,780 --> 00:09:07,380
should always have name, hit points, and lives attributes,

201
00:09:07,380 --> 00:09:10,020
and in the game scenario, it's probably quite reasonable

202
00:09:10,020 --> 00:09:14,240
to assume that any enemy would have those attributes.

203
00:09:14,240 --> 00:09:16,560
But let's also add a method,

204
00:09:16,560 --> 00:09:18,970
which we'll call take damage.

205
00:09:20,420 --> 00:09:23,020
So we're gonna do a def, take underscore damage,

206
00:09:23,020 --> 00:09:24,930
to create a new method.

207
00:09:25,780 --> 00:09:29,370
And it's going to have one parameter, damage.

208
00:09:29,370 --> 00:09:32,290
And we're gonna do remaining points

209
00:09:34,790 --> 00:09:38,960
is equal to self.hit underscore points, take damage.

210
00:09:41,110 --> 00:09:44,550
Then we're gonna put if, remaining points,

211
00:09:44,550 --> 00:09:47,860
is greater than or equal to zero,

212
00:09:47,860 --> 00:09:51,610
then we're gonna do self.hit underscore points

213
00:09:51,610 --> 00:09:54,130
equals remaining points,

214
00:09:54,130 --> 00:09:55,550
then we're gonna print a message.

215
00:09:55,550 --> 00:09:59,300
Print, I took, placement field points damage,

216
00:10:03,120 --> 00:10:07,290
and have, in another replacement field, left.format.

217
00:10:08,890 --> 00:10:13,050
We're going to do damage comma self.hit underscore points.

218
00:10:15,420 --> 00:10:19,350
And we're gonna have an else there, else,

219
00:10:19,350 --> 00:10:21,680
self.lives minus equals one.

220
00:10:24,220 --> 00:10:27,140
So what we're doing here is we're subtracting the damage

221
00:10:27,140 --> 00:10:29,470
from the number of hit points that the enemy has,

222
00:10:29,470 --> 00:10:32,260
and then checking to see if they've still got any left

223
00:10:32,260 --> 00:10:34,590
after that damage is inflicted.

224
00:10:34,590 --> 00:10:37,200
Now if the number remaining is zero or more,

225
00:10:37,200 --> 00:10:39,310
we update the hit points and print a message

226
00:10:39,310 --> 00:10:41,000
showing how much damage was taken,

227
00:10:41,000 --> 00:10:43,700
and also how many hit points are still left.

228
00:10:43,700 --> 00:10:46,170
But if, however, their hit points drop below zero,

229
00:10:46,170 --> 00:10:48,490
then we take a life off instead.

230
00:10:48,490 --> 00:10:49,750
Now we should probably check to see

231
00:10:49,750 --> 00:10:51,320
if we've got any lives left,

232
00:10:51,320 --> 00:10:53,280
but we're demonstrating concepts here,

233
00:10:53,280 --> 00:10:55,210
we're not creating a full game.

234
00:10:55,210 --> 00:10:56,650
This could be a useful exercise

235
00:10:56,650 --> 00:10:58,560
for you to try it yourself, though,

236
00:10:58,560 --> 00:10:59,780
to make sure you've understood

237
00:10:59,780 --> 00:11:02,220
what we've covered in this tutorial.

238
00:11:02,220 --> 00:11:04,470
All right, so we've got a basic class here.

239
00:11:04,470 --> 00:11:07,360
We're storing the name, hit points, and lives,

240
00:11:07,360 --> 00:11:09,780
and we've got a constructor where we can set,

241
00:11:09,780 --> 00:11:13,670
where we do set the initial value of those attributes.

242
00:11:13,670 --> 00:11:15,220
So I'm gonna add another method,

243
00:11:15,220 --> 00:11:16,770
which is basically a copy of this

244
00:11:16,770 --> 00:11:19,960
string method from the player class.

245
00:11:19,960 --> 00:11:21,670
Even though I could probably just copy it and change it,

246
00:11:21,670 --> 00:11:24,170
I'll just type it in, 'cause it's fairly short.

247
00:11:24,170 --> 00:11:25,630
So underscore underscore string,

248
00:11:25,630 --> 00:11:28,630
underscore underscore, self,

249
00:11:28,630 --> 00:11:30,730
and then we're gonna return,

250
00:11:30,730 --> 00:11:33,660
and it's going to be name, colon,

251
00:11:33,660 --> 00:11:35,940
starting your left replacement field,

252
00:11:35,940 --> 00:11:39,020
which is left curly brace, zero.name,

253
00:11:40,270 --> 00:11:44,640
right curly brace, comma, lives, colon, space,

254
00:11:44,640 --> 00:11:47,060
left curly brace, zero.lives,

255
00:11:47,980 --> 00:11:52,360
right curly brace, comma, space, hit points,

256
00:11:52,360 --> 00:11:56,530
colon, space, left curly brace, zero.hit underscore points,

257
00:11:57,630 --> 00:12:00,130
right curly brace.format self.

258
00:12:03,640 --> 00:12:06,140
Okay, so that's actually it.

259
00:12:06,140 --> 00:12:08,410
So okay, and we're using this to print out the attributes,

260
00:12:08,410 --> 00:12:10,200
so we don't have to keep writing long print statements

261
00:12:10,200 --> 00:12:12,370
to check that everything's working.

262
00:12:12,370 --> 00:12:14,400
Okay, so that stuff, that's similar to stuff

263
00:12:14,400 --> 00:12:17,440
I've already covered in earlier videos in this section.

264
00:12:17,440 --> 00:12:18,910
Now, we're not going to actually

265
00:12:18,910 --> 00:12:21,520
create enemy objects directly,

266
00:12:21,520 --> 00:12:23,760
although we could do that if we wanted to.

267
00:12:23,760 --> 00:12:27,570
But this is really just for use as a base class,

268
00:12:27,570 --> 00:12:29,680
so that all the specific enemies

269
00:12:29,680 --> 00:12:31,560
have these basic properties.

270
00:12:31,560 --> 00:12:33,340
So think about like a bird class.

271
00:12:33,340 --> 00:12:35,170
You don't get animals that are just birds.

272
00:12:35,170 --> 00:12:37,520
They're a particular type of bird.

273
00:12:37,520 --> 00:12:39,850
So I'm gonna create one enemy, enemy object,

274
00:12:39,850 --> 00:12:41,780
just to test the class, though,

275
00:12:41,780 --> 00:12:44,260
to make sure that everything's working

276
00:12:44,260 --> 00:12:46,330
before we go extending the class.

277
00:12:46,330 --> 00:12:49,080
So I'll go back to the main file.

278
00:12:50,380 --> 00:12:51,780
We're gonna delete all the code, now,

279
00:12:51,780 --> 00:12:53,750
that we've used to test the player class.

280
00:12:53,750 --> 00:12:56,430
So let's just delete all of that.

281
00:12:56,430 --> 00:12:58,700
Then we'll start on line five.

282
00:12:58,700 --> 00:13:02,870
And line five we're gonna type from enemy, import enemy.

283
00:13:07,220 --> 00:13:09,820
Then we're gonna do random underscore monster

284
00:13:09,820 --> 00:13:12,570
is equal to Enemy, capital E.

285
00:13:12,570 --> 00:13:16,230
And we'll just say, we'll call it basic enemy,

286
00:13:16,230 --> 00:13:17,900
then pass 12 for the number of hit points,

287
00:13:17,900 --> 00:13:20,130
and one for the number of lives.

288
00:13:20,130 --> 00:13:23,580
Then we're gonna print the random monster,

289
00:13:23,580 --> 00:13:24,420
then we're gonna do

290
00:13:24,420 --> 00:13:28,000
random monster.take underscore damage four,

291
00:13:29,170 --> 00:13:31,940
then we're gonna print random monster.

292
00:13:31,940 --> 00:13:33,200
Okay.

293
00:13:33,200 --> 00:13:37,190
Let's just run that and see if it's gonna work for us.

294
00:13:37,190 --> 00:13:39,510
And see, we've created the basic enemy,

295
00:13:39,510 --> 00:13:42,310
lives one, hit points 12, took four points of damage

296
00:13:42,310 --> 00:13:44,120
and they've got eight points left,

297
00:13:44,120 --> 00:13:45,280
eight hit points left,

298
00:13:45,280 --> 00:13:48,790
and we got confirmation at the second printout.

299
00:13:48,790 --> 00:13:50,010
All right, so let's take the,

300
00:13:50,010 --> 00:13:52,750
or let's test the take damage method a bit more.

301
00:13:52,750 --> 00:13:56,220
Let's see what happens when the hit points drop below zero.

302
00:13:56,220 --> 00:13:57,360
And actually, I'll clean this up completely

303
00:13:57,360 --> 00:13:59,520
and put this back onto line one.

304
00:13:59,520 --> 00:14:03,390
We don't need a player at all for now.

305
00:14:03,390 --> 00:14:06,030
So let's add a couple of extra lines here.

306
00:14:06,030 --> 00:14:08,690
So we'll do another eight there.

307
00:14:09,550 --> 00:14:11,250
It should take it to zero hit points,

308
00:14:11,250 --> 00:14:12,750
and then we'll do another one that takes another nine,

309
00:14:12,750 --> 00:14:14,250
just to see what happens.

310
00:14:14,250 --> 00:14:16,500
So let's actually run this.

311
00:14:17,670 --> 00:14:20,220
And you can see, we've got a basic enemy 12,

312
00:14:20,220 --> 00:14:22,520
lost four points, eight left,

313
00:14:22,520 --> 00:14:25,680
it had eight and then lost eight to have zero left.

314
00:14:25,680 --> 00:14:27,010
And then we've just got the printouts.

315
00:14:27,010 --> 00:14:29,810
The lives, you can see there, has dropped down to zero.

316
00:14:29,810 --> 00:14:31,210
So that's working fine.

317
00:14:31,210 --> 00:14:33,320
I do suggest you always test all the paths

318
00:14:33,320 --> 00:14:34,600
throughout your code.

319
00:14:34,600 --> 00:14:36,650
So if you put in some conditions like we did,

320
00:14:36,650 --> 00:14:39,320
when we check for the hit points dropping to below zero,

321
00:14:39,320 --> 00:14:40,790
they'll make sure you use data

322
00:14:40,790 --> 00:14:43,750
that will test the alternative path

323
00:14:43,750 --> 00:14:44,960
to make sure it works as well as

324
00:14:44,960 --> 00:14:48,330
the path you're assuming will work most of the time.

325
00:14:48,330 --> 00:14:50,290
All right, so I'm gonna finish the video here.

326
00:14:50,290 --> 00:14:51,590
In the next video, we're going to start

327
00:14:51,590 --> 00:14:52,990
getting into the good stuff.

328
00:14:52,990 --> 00:14:55,470
We're going to start inheriting from that class,

329
00:14:55,470 --> 00:14:57,450
and this is where it's going to be getting interesting.

330
00:14:57,450 --> 00:14:59,960
So I will see you in the next video.

