1
00:00:04,700 --> 00:00:07,099
This short video is a challenge to give

2
00:00:07,099 --> 00:00:08,719
you a chance to practice some of what

3
00:00:08,719 --> 00:00:11,269
we've done so far. So the first part of

4
00:00:11,269 --> 00:00:12,769
the challenge is to modify the show

5
00:00:12,769 --> 00:00:15,440
function in the Player class, so that it

6
00:00:15,440 --> 00:00:17,540
also prints the details for the weapon

7
00:00:17,540 --> 00:00:19,369
that the players have. Now as well as

8
00:00:19,369 --> 00:00:21,470
printing the Players name, lives, level

9
00:00:21,470 --> 00:00:23,869
and score, it should also print the name

10
00:00:23,869 --> 00:00:25,759
of their weapon, as well as the damage

11
00:00:25,759 --> 00:00:28,430
that that weapon inflicts. Now use the

12
00:00:28,430 --> 00:00:30,800
modified show function in main, to print

13
00:00:30,800 --> 00:00:32,870
out tim's details, including the weapon,

14
00:00:32,870 --> 00:00:35,480
instead of just the weapon. So in other

15
00:00:35,480 --> 00:00:37,100
words, instead of just printing tim dot

16
00:00:37,100 --> 00:00:39,980
weapon.name, use the modified show

17
00:00:39,980 --> 00:00:42,320
function. Now as a hint, review the

18
00:00:42,320 --> 00:00:44,210
video on String concatenation and

19
00:00:44,210 --> 00:00:46,670
interpolation, to remind yourself how to

20
00:00:46,670 --> 00:00:48,980
include more complex expressions in a

21
00:00:48,980 --> 00:00:52,010
string. Now for the second part of the

22
00:00:52,010 --> 00:00:54,020
challenge, modify the code in the main

23
00:00:54,020 --> 00:00:56,390
function, so that louise gets the sword

24
00:00:56,390 --> 00:00:59,630
before tim replaces it with a spear. So

25
00:00:59,630 --> 00:01:01,670
the point here is to give Louise the

26
00:01:01,670 --> 00:01:04,938
same sword that Tim had, not to create a

27
00:01:04,938 --> 00:01:07,250
new one. And use the show function to

28
00:01:07,250 --> 00:01:09,469
display the details for louise, to check

29
00:01:09,469 --> 00:01:11,389
the your code's working. So that's it -

30
00:01:11,389 --> 00:01:12,889
that's the challenge. Pause the video

31
00:01:12,889 --> 00:01:14,420
here and see how you go at the challenge,

32
00:01:14,420 --> 00:01:18,189
and I'll see you when you get back.

33
00:01:18,189 --> 00:01:20,810
So there's very rarely one way to write

34
00:01:20,810 --> 00:01:22,729
code, so your solution may well be

35
00:01:22,729 --> 00:01:25,189
different to mine. The real test is that

36
00:01:25,189 --> 00:01:27,439
the weapon details are displayed when

37
00:01:27,439 --> 00:01:29,780
you call the show function. So for my

38
00:01:29,780 --> 00:01:31,759
solution, I'm going to include the two

39
00:01:31,759 --> 00:01:33,470
properties of the weapon in the output

40
00:01:33,470 --> 00:01:34,850
string. So I'm gonna go back to the

41
00:01:34,850 --> 00:01:36,920
Player class. I'm gonna come down here

42
00:01:36,920 --> 00:01:39,439
below score. I'm going to type

43
00:01:39,439 --> 00:01:42,500
weapon : then the dollar sign, left and

44
00:01:42,500 --> 00:01:47,149
right curly braces, weapon.name. Then

45
00:01:47,149 --> 00:01:48,560
on the next line, it's going to be

46
00:01:48,560 --> 00:01:49,970
damaged, so damage :

47
00:01:49,970 --> 00:01:52,549
dollar sign left and right curly braces,

48
00:01:52,549 --> 00:01:57,350
weapon.damageInflicted. Now remember

49
00:01:57,350 --> 00:01:59,030
that we need to enclose more complex

50
00:01:59,030 --> 00:02:01,189
expressions in curly braces, as I've done

51
00:02:01,189 --> 00:02:03,259
here. So if you try that without the

52
00:02:03,259 --> 00:02:05,179
curly braces, it'll actually print out

53
00:02:05,179 --> 00:02:07,849
the dot name as a literal string. So the

54
00:02:07,849 --> 00:02:10,038
code, for example, on line 14, without

55
00:02:10,038 --> 00:02:12,170
the curly braces - you'll get a dot with

56
00:02:12,170 --> 00:02:14,569
the characters n a m e printed out

57
00:02:14,569 --> 00:02:16,940
instead. Alright, so now that we've done

58
00:02:16,940 --> 00:02:18,560
that, in our main function - let's go back

59
00:02:18,560 --> 00:02:20,599
to that - and what we want to do is

60
00:02:20,599 --> 00:02:22,220
replace the println statements with a

61
00:02:22,220 --> 00:02:24,410
call to tim's show function. So let's do

62
00:02:24,410 --> 00:02:25,040
that first.

63
00:02:25,040 --> 00:02:27,079
So this is the one down here now, as you can

64
00:02:27,079 --> 00:02:28,880
see on line 25. So I'm going to comment

65
00:02:28,880 --> 00:02:31,549
that line 25 out, then on the next

66
00:02:31,549 --> 00:02:34,870
line, I'm going to do a tim.dot show.

67
00:02:34,870 --> 00:02:37,220
So let's run the program to make sure

68
00:02:37,220 --> 00:02:41,299
that it's actually working. Now if you

69
00:02:41,299 --> 00:02:43,489
get this situation pop up - well you can see

70
00:02:43,489 --> 00:02:45,350
what's happened here and it's not actually

71
00:02:45,350 --> 00:02:48,920
printing out the full values, and it seems

72
00:02:48,920 --> 00:02:50,780
to be not taking the changes that we've

73
00:02:50,780 --> 00:02:52,880
made - make sure that you do go back and

74
00:02:52,880 --> 00:02:58,639
do a Clean Project, and go back and make

75
00:02:58,639 --> 00:03:02,030
the module again. And then go back and

76
00:03:02,030 --> 00:03:04,940
right-click here and select Run Main

77
00:03:04,940 --> 00:03:07,220
kt. That should fix it generally, and you

78
00:03:07,220 --> 00:03:08,450
can see it has done that now - we're

79
00:03:08,450 --> 00:03:10,790
seeing the new code output. So it appears to

80
00:03:10,790 --> 00:03:13,340
have been cached - or the previous version

81
00:03:13,340 --> 00:03:15,260
of running the code was cached - and by

82
00:03:15,260 --> 00:03:16,670
doing it this way, we're clearing it out

83
00:03:16,670 --> 00:03:18,859
and making sure that we're running the

84
00:03:18,859 --> 00:03:19,970
latest version, and you can see the

85
00:03:19,970 --> 00:03:20,930
output is showing there on the screen.

86
00:03:20,930 --> 00:03:23,000
We've got the revised show function

87
00:03:23,000 --> 00:03:24,380
which is also working at the top, if we

88
00:03:24,380 --> 00:03:26,269
scroll up as well, the weapon and the

89
00:03:26,269 --> 00:03:27,950
damage, and that clearly wasn't working

90
00:03:27,950 --> 00:03:29,760
before we made the change.

91
00:03:29,760 --> 00:03:31,110
But the change we're looking at here, is

92
00:03:31,110 --> 00:03:33,360
tim has got weapon, sword and damage

93
00:03:33,360 --> 00:03:35,879
showing. Alright, so that's the first part

94
00:03:35,879 --> 00:03:37,920
of the challenge. The second part of the

95
00:03:37,920 --> 00:03:39,120
challenge; what we can do is we can

96
00:03:39,120 --> 00:03:40,980
assign, or we should assign, tim's

97
00:03:40,980 --> 00:03:43,680
weapon to louise, but before tim picks up

98
00:03:43,680 --> 00:03:45,870
the spear. So the code for that, we're

99
00:03:45,870 --> 00:03:47,549
going to come down here, after the tim dot

100
00:03:47,549 --> 00:03:51,510
show line. We're going to type louise dot

101
00:03:51,510 --> 00:03:57,629
weapon is equal to tim.weapon, and

102
00:03:57,629 --> 00:04:00,900
on the next line, louise.show. 

103
00:04:00,900 --> 00:04:02,450
I'll just make a bit of space there.

104
00:04:02,450 --> 00:04:04,500
Alright, so you can think of this as

105
00:04:04,500 --> 00:04:07,590
louise taking the sword from tim. So

106
00:04:07,590 --> 00:04:09,540
we're assigning tim's weapon to louise's

107
00:04:09,540 --> 00:04:12,209
weapon property on line 28, and then

108
00:04:12,209 --> 00:04:15,060
obviously, line 29 is showing it. Now it's

109
00:04:15,060 --> 00:04:16,858
important to do that before assigning

110
00:04:16,858 --> 00:04:19,199
the spear to tim. It won't work if we try

111
00:04:19,199 --> 00:04:21,120
to do it the other way around, because

112
00:04:21,120 --> 00:04:22,560
there'll be no reference to the sword,

113
00:04:22,560 --> 00:04:25,380
once tim gets the spear. So let's just

114
00:04:25,380 --> 00:04:26,580
try running this to make sure that it

115
00:04:26,580 --> 00:04:30,960
works. And again, you can see that we've

116
00:04:30,960 --> 00:04:32,580
got these funny caching issues, which may

117
00:04:32,580 --> 00:04:34,530
or may not come up for you. We can't see

118
00:04:34,530 --> 00:04:36,030
any output showing from louise, so we

119
00:04:36,030 --> 00:04:37,260
can actually just try running it here

120
00:04:37,260 --> 00:04:42,180
first. That doesn't do any good. We can

121
00:04:42,180 --> 00:04:45,780
just try doing a clean again. We can

122
00:04:45,780 --> 00:04:48,780
make the module again. It's frustrating

123
00:04:48,780 --> 00:04:51,300
having to do this - I hope Google will fix

124
00:04:51,300 --> 00:04:52,940
this soon. We'll try running it again, and

125
00:04:52,940 --> 00:04:54,900
this time we're getting the right output -

126
00:04:54,900 --> 00:04:56,190
you can see we're getting louise's

127
00:04:56,190 --> 00:04:57,599
output showing on the screen there, now.

128
00:04:57,599 --> 00:04:59,550
And again, you can see in this case, that

129
00:04:59,550 --> 00:05:03,240
we've got tim showing the sword. Louise

130
00:05:03,240 --> 00:05:05,160
is now seeing, we're seeing the sword

131
00:05:05,160 --> 00:05:06,630
for louise, then we're getting the

132
00:05:06,630 --> 00:05:08,340
output of the spear only and that's

133
00:05:08,340 --> 00:05:09,150
because, at the moment, we're just

134
00:05:09,150 --> 00:05:12,690
printing the weapon.name on line 32. So

135
00:05:12,690 --> 00:05:14,520
we could fix that as well. Let's do that -

136
00:05:14,520 --> 00:05:18,720
let's comment that out - and we'll put tim

137
00:05:18,720 --> 00:05:22,500
show. We'll run that and see whether

138
00:05:22,500 --> 00:05:26,220
that works for us, and unfortunately it

139
00:05:26,220 --> 00:05:27,419
doesn't work again. We're not really having much

140
00:05:27,419 --> 00:05:30,620
fun with his are we? So we'll actually,

141
00:05:30,620 --> 00:05:35,650
clean again, we'll make the module. We'll

142
00:05:35,650 --> 00:05:39,830
try running it again, and that's better. Now

143
00:05:39,830 --> 00:05:41,060
you can see we've got the output, and

144
00:05:41,060 --> 00:05:43,009
this time we've got the first one - the

145
00:05:43,009 --> 00:05:44,990
first line, which was this output line

146
00:05:44,990 --> 00:05:47,419
here, on line 26. We're seeing tim's got

147
00:05:47,419 --> 00:05:50,479
the sword. Then the output on line 29 is

148
00:05:50,479 --> 00:05:52,550
louise output, and then finally, the

149
00:05:52,550 --> 00:05:55,280
output on line 33, we've seen the weapon

150
00:05:55,280 --> 00:05:57,560
and the damage as well. Alright, so

151
00:05:57,560 --> 00:05:59,509
that's the challenge solved. Now there

152
00:05:59,509 --> 00:06:00,770
are other ways you could have solved

153
00:06:00,770 --> 00:06:02,840
this; you may have created a new sword

154
00:06:02,840 --> 00:06:04,430
variable, for example, and assigned

155
00:06:04,430 --> 00:06:06,560
tim's weapon to that first. That would

156
00:06:06,560 --> 00:06:08,539
also work, and as long as louise has

157
00:06:08,539 --> 00:06:10,669
the sword when you run the program, then

158
00:06:10,669 --> 00:06:12,889
Congratulations. Alrighty, so that's

159
00:06:12,889 --> 00:06:14,210
the challenge completed. So I'm going to

160
00:06:14,210 --> 00:06:16,460
stop this video here. In the next video,

161
00:06:16,460 --> 00:06:18,440
we're going to let our players have more

162
00:06:18,440 --> 00:06:20,569
than one instance of an object - some loot

163
00:06:20,569 --> 00:06:22,370
that they'll be picking up. So I'll see

164
00:06:22,370 --> 00:06:25,060
you in the next video.

