WEBVTT

00:01.030 --> 00:10.690
In this lecture I want to get the Gheen sort of set up and have everything drawing so you start with

00:10.690 --> 00:11.740
getting everything set up.

00:11.830 --> 00:15.150
So we're going to need two players

00:18.060 --> 00:23.000
overseas or player type and here to

00:27.780 --> 00:32.600
and we're going to do the initialize the player.

00:33.150 --> 00:34.200
We didn't actually

00:36.830 --> 00:45.620
didn't actually break it down in the top down design but I didn't do it because we were doing it right

00:45.620 --> 00:46.000
away.

00:46.020 --> 00:48.850
So initialize

00:51.730 --> 01:03.830
we're in one it was going to name him Player 1.

01:04.260 --> 01:05.960
It's where

01:13.590 --> 01:14.260
to

01:17.240 --> 01:19.370
like so.

01:19.460 --> 01:20.870
So it's

01:25.260 --> 01:30.030
a lead function declaration this year.

01:30.880 --> 01:39.230
And we're going to pass by reference because right change the player's state in here we're going to

01:39.230 --> 01:41.600
need a concert char.

01:41.600 --> 01:44.240
Star player

01:47.100 --> 01:53.650
and we're gonna have to string copy it into the player's array.

01:53.660 --> 01:55.900
So we're going to Sturckow.

01:56.220 --> 02:02.210
And by the way if we you should include the utils so that we have it.

02:02.220 --> 02:03.780
I've already done that here.

02:04.230 --> 02:11.190
But if you haven't you should pause the video and include the utils in your project.

02:11.500 --> 02:15.840
So string.

02:16.070 --> 02:20.830
So we have that.

02:21.000 --> 02:32.230
Now let's implement this.

02:32.380 --> 02:36.050
So how are we going to do this.

02:36.070 --> 02:43.240
So let's say if player name is not equal to no pointer

02:47.730 --> 02:55.300
is to use string copy.

02:55.410 --> 03:05.420
And in fact we should probably also check to see and read the story when player name is greater than

03:05.420 --> 03:05.950
zero.

03:08.140 --> 03:15.350
And if that's true then we're going to copy it into our player name array.

03:18.460 --> 03:18.730
So

03:23.260 --> 03:32.330
in now we want to actually set all the ships correctly for the player.

03:32.470 --> 03:33.280
OK.

03:33.480 --> 03:47.040
So to do this we will say say player datt Shep's zero.

03:47.650 --> 03:48.940
So be the

03:51.620 --> 03:55.850
was going to be the aircraft I guess.

03:56.040 --> 03:58.630
So type

04:01.640 --> 04:02.690
reaching for this

04:12.930 --> 04:17.130
kind of carrier

04:20.000 --> 04:21.740
where ships

04:24.030 --> 04:24.820
0

04:27.560 --> 04:27.850
teach

04:30.340 --> 04:34.730
size should be your

04:37.780 --> 04:42.130
carrier size.

04:43.400 --> 04:44.720
Merda chips

04:47.120 --> 04:47.620
of

04:50.460 --> 04:52.420
Rouche.

04:53.120 --> 05:01.170
So the position and the orientation of this doesn't matter at the start.

05:01.170 --> 05:01.600
Right.

05:01.670 --> 05:06.080
It's a Roekel zero and seeing things here

05:10.420 --> 05:13.720
you call them

05:16.820 --> 05:20.140
ships hero

05:23.420 --> 05:25.460
station again doesn't matter.

05:26.520 --> 05:30.180
Because we're going to set them all in our set up.

05:30.310 --> 05:36.680
So and we have to do this a bunch of times right now do it for each aircraft carrier.

05:36.690 --> 05:44.280
So it would be nicer if we actually had it for each ship or should say no aircraft carrier would be

05:44.280 --> 05:45.790
nice if we had a function to do.

05:45.810 --> 05:51.000
So let's actually make a function and so it's a national as

05:54.380 --> 05:56.020
ship.

05:56.140 --> 06:14.390
And it will actually take the ship by reference and it will take the ship's size and the type.

06:14.520 --> 06:14.860
Right.

06:14.900 --> 06:19.550
That's the only Those are really only two things that really mattered and what just kind of set them

06:19.550 --> 06:21.270
all to be like this.

06:21.660 --> 06:24.500
So to copy this

06:30.650 --> 06:33.990
to or she's going to copy this whole thing

06:37.100 --> 06:45.130
cut it in and so instead of pulling to ships zero of this ship

06:50.040 --> 06:50.410
that

07:16.930 --> 07:26.570
and now all they have to do is just set the type and size ship type.

07:26.670 --> 07:32.360
So in this space ship site it's.

07:32.570 --> 07:39.380
So now when it's initialized player instead of just kind of directly doing it we'll just call the function

07:39.380 --> 07:41.570
because we have to do it for each ship so.

07:42.070 --> 07:47.590
And it will be in it in this ship.

07:47.790 --> 07:53.180
Ship's zero.

07:57.040 --> 07:59.700
Ear.

08:00.100 --> 08:02.510
It's in the

08:06.210 --> 08:06.730
carrier

08:09.600 --> 08:13.590
K and we just need to do this for each one.

08:16.790 --> 08:17.090
So

08:21.640 --> 08:25.650
ships of one will be our battleship

08:36.510 --> 08:43.040
and of to the cruiser

08:54.090 --> 08:55.350
three or destroyer

09:09.760 --> 09:10.620
or submarine

09:26.850 --> 09:27.590
and that's it.

09:27.600 --> 09:33.040
So that will now initialize all our other players.

09:33.120 --> 09:34.830
So we only have two.

09:35.070 --> 09:36.910
So that should be good.

09:37.350 --> 09:41.130
So let's right the main kind of lube.

09:41.400 --> 09:57.350
You know I do this is a name in with the players want it to and while want to do a

10:05.750 --> 10:07.170
copy this

10:09.740 --> 10:10.720
is peer

10:13.980 --> 10:18.670
turns nothing you will pass by reference

10:21.480 --> 10:22.610
here.

10:24.200 --> 10:24.940
Day.

10:25.250 --> 10:28.030
And we want to do that said

10:33.820 --> 10:44.130
Lillian that many times shouldn't be too magical what we how we implement that.

10:44.150 --> 10:45.450
So let's just implement.

10:45.470 --> 10:47.870
Want to play again right now just the way

10:50.210 --> 10:56.450
so is your input.

10:59.070 --> 11:06.850
This and will have comments char input.

11:12.970 --> 11:14.770
Yes or no.

11:15.180 --> 11:16.220
Did before

11:18.770 --> 11:20.390
it was input.

11:20.440 --> 11:38.060
It's of course to get character and would you like to play again and slash and that's And will the error

11:38.060 --> 11:49.710
string so it's actually to find it's years and when it's just fine it various their context should just

11:55.160 --> 11:56.360
here straight

12:00.130 --> 12:01.550
but error

12:06.620 --> 12:08.390
as I get

12:21.580 --> 12:37.820
past there and say valid input and two and remember are lower case and upper case stuff did for so and

12:38.150 --> 12:44.970
will turn input equal to Y.

12:45.890 --> 12:49.360
So there's what I want to play again.

12:50.460 --> 12:51.610
So in either way.

12:51.610 --> 12:53.900
So we're actually done with the main now.

12:53.980 --> 12:58.160
And all we have to do is concentrate on play again.

12:58.180 --> 13:05.980
So let's let's do the kind of set up for.

13:05.990 --> 13:08.840
But we won't do the entirety of set up or.

13:09.270 --> 13:21.200
I don't think this lecture will do the dry it so let's start at.

13:21.460 --> 13:33.190
So I have to set up words for player 1 and set up order for player to

13:36.490 --> 13:39.350
and that's all we're going to get.

13:39.520 --> 13:46.520
In this lecture footplate game so he said it's

13:52.610 --> 13:53.980
here.

13:54.100 --> 14:04.330
So here we're going to make void's your attorney thing and I guess we'll pass it by reference.

14:04.540 --> 14:08.160
Well OK.

14:08.830 --> 14:10.580
It was our declaration

14:13.400 --> 14:14.560
in down here.

14:14.600 --> 14:17.960
Well actually it's some of it.

14:18.140 --> 14:21.560
All.

14:21.640 --> 14:27.550
So how did this work.

14:27.790 --> 14:33.030
See set up or so clear the board.

14:33.100 --> 14:35.690
So that's the first thing to do.

14:36.970 --> 14:41.270
So again we'll have another function called clipboards

14:43.990 --> 14:52.900
or boards of player and she passed comments actually no need to change.

14:52.940 --> 14:55.280
So that's the reference again

14:58.040 --> 15:00.340
here boards

15:02.670 --> 15:05.490
and how will this work.

15:05.560 --> 15:14.140
So all we have to do is say for our equals zero for that row.

15:14.280 --> 15:17.750
Ours is less than the board size right.

15:19.060 --> 15:21.030
Size or you just find that's

15:23.680 --> 15:25.750
and go through all the column s

15:28.970 --> 15:30.520
so board size

15:37.080 --> 15:40.770
and what we have to do is clear the board.

15:40.770 --> 15:45.070
So if we access the start with the board.

15:45.450 --> 15:51.360
So the gas board of R and C should be Jiechi none right.

15:52.700 --> 15:57.580
So this will set every element in this 2d array to be G-d not.

15:57.620 --> 16:07.910
So the player effectively hasn't guessed here yet is what this is saying and like Likewise the shipboard

16:10.460 --> 16:17.710
here this should be actually the ship type.

16:17.710 --> 16:20.110
This is a ship part this whole thing.

16:20.720 --> 16:26.600
And the ship type should be as not.

16:26.770 --> 16:33.640
Right because there's no this really means there is no ship here at this location.

16:34.190 --> 16:40.180
And also there's two elements to this array structure.

16:40.280 --> 16:45.300
So is hit is false right.

16:45.910 --> 16:50.650
Nothing was hit here and there's no there's nothing here in first place.

16:51.040 --> 16:52.860
So that'll clear the boards.

16:52.880 --> 16:54.210
That's what that means.

16:55.350 --> 17:06.110
And if you go back you set up boards to clear boards of the player

17:09.450 --> 17:11.520
right now is the very first step.

17:11.520 --> 17:24.430
We said we appear and then we essentially loop through all the ships and then draw the board each time.

17:24.620 --> 17:31.190
Given the current ship and then place all that right.

17:31.340 --> 17:38.900
So I think what we'll do for the rest of this lecture is just draw the board and we'll skip kind of

17:39.020 --> 17:40.520
the rest of it for now.

17:40.880 --> 17:44.490
So what we're going to do is clear the boards and then just draw the board.

17:44.600 --> 17:47.890
So draw forward it's

17:50.720 --> 17:56.130
player.

17:56.290 --> 17:57.470
Is this

18:00.870 --> 18:03.490
here knock or turn or anything.

18:03.610 --> 18:04.980
Just draw function.

18:07.950 --> 18:14.400
And in this case now we're never going to change it so I can put Konst where I can change the player

18:14.400 --> 18:15.310
as we drive.

18:15.550 --> 18:16.910
OK.

18:17.230 --> 18:24.740
In here it's a drop or it's.

18:24.840 --> 18:27.390
So how will this work.

18:27.390 --> 18:39.980
So what I want to do is have the I want the columns all marked and the rows are marked so the rows go

18:39.980 --> 18:47.270
from 8 to J and the columns go from 1 to 10 and I want to have both boards kind of display next to each

18:47.270 --> 18:47.830
other.

18:49.940 --> 18:50.780
So

18:53.680 --> 19:01.960
this one is going to be a little bit hand-wavy won't really break it down in terms of the explanation

19:02.050 --> 19:13.090
exactly but I'm just going to use star typing wreathing we need and I'll sort of explain after or explain

19:13.090 --> 19:14.210
a little bit on the way.

19:14.220 --> 19:15.750
Mostly when after.

19:15.760 --> 19:24.540
So essentially what I want to do is draw the columns row.

19:24.670 --> 19:30.110
So this is all the kind of one to 10 for each one.

19:30.190 --> 19:38.760
So you don't even have this function but you'll see in a minute and then draw the

19:42.930 --> 19:43.570
gain

19:51.330 --> 19:57.090
and you'll see why did this.

19:57.290 --> 19:57.710
You know

20:02.750 --> 20:05.130
and I'm going to go through all the rose

20:17.570 --> 20:21.630
and you're going to need a separator line.

20:27.060 --> 20:27.400
Or

20:31.850 --> 20:38.140
it's then you're probably encouraged in what I'm doing here but just just try to follow follow along

20:38.410 --> 20:42.350
and you'll see exactly how this works.

20:42.370 --> 20:44.050
It all kind of come together.

20:47.970 --> 21:00.900
Normally when you're doing drawing it's very error prone and usually takes a few iterations get it correct.

21:02.220 --> 21:02.820
So

21:06.910 --> 21:07.650
here

21:14.100 --> 21:23.470
ch.

21:23.800 --> 21:24.330
Yes

21:28.460 --> 21:30.810
there.

21:30.880 --> 21:36.310
So essentially what I'm doing is draw a separate line which will kind of look like

21:39.850 --> 21:42.040
it looks like this to you.

21:43.780 --> 21:50.810
So it'll kind of look like this except for each three dashes we'll have another plus.

21:50.880 --> 21:54.410
So each cell will look like this.

21:59.720 --> 22:05.080
And does it look like an empty cell on the board.

22:05.210 --> 22:05.900
OK.

22:05.900 --> 22:11.900
So they'll have three spaces in the middle space will actually draw something to represent like the

22:11.900 --> 22:14.290
ship or whether it was hit or not.

22:14.430 --> 22:15.390
OK.

22:15.440 --> 22:16.030
So

22:18.840 --> 22:21.290
that's what I'm doing here.

22:24.100 --> 22:27.350
And these are all functions of that it's like.

22:27.500 --> 22:29.010
Ouch and all

22:32.010 --> 22:37.270
in half to try another separate line for the last separator.

22:42.390 --> 22:42.660
CH

22:47.190 --> 22:48.600
one more step.

22:54.540 --> 22:56.140
In another and

23:01.640 --> 23:05.830
and up here.

23:05.880 --> 23:09.800
So let's start drawing kind of lines and stuff.

23:09.810 --> 23:10.570
So

23:15.610 --> 23:22.250
right for let's say Boyd separator line

23:25.850 --> 23:57.320
this see how much.

23:57.500 --> 24:08.570
So this will essentially just make all the kind of all the cells essentially for all of the columns

24:09.430 --> 24:13.180
they and the next one

24:18.540 --> 24:19.140
rule

24:28.400 --> 24:30.410
is pretty similar.

24:34.400 --> 24:37.820
See Ciro's this or size

24:40.880 --> 24:44.190
plus an

24:46.990 --> 24:49.930
things this will actually draw the name of the thing.

24:55.310 --> 24:55.860
It's

25:06.680 --> 25:17.040
answer that deals with those most of it and I would just need a few more functions which is in fact

25:17.450 --> 25:21.260
let's show what this looks like right now.

25:25.560 --> 25:28.850
It's the first

25:42.110 --> 25:48.770
Roger.

25:48.860 --> 25:50.300
So you can see

25:54.990 --> 25:58.610
it's not quite right.

25:59.120 --> 26:12.960
So haven't done all of the kind of the vertical bars for each one and these are not centered correctly.

26:14.380 --> 26:17.490
But that will be easy to fix.

26:18.070 --> 26:20.030
Let's continue on with the East.

26:20.150 --> 26:25.070
It's this simpler.

26:25.370 --> 26:31.100
So it's those two and those I didn't have to declare these functions.

26:31.100 --> 26:36.160
They didn't really just have to be above where you use them.

26:36.620 --> 26:46.250
So I will actually declare them above anyway but just so you know you don't have to declare every function.

26:46.250 --> 26:50.100
You just need to define them before you use them.

26:50.150 --> 26:58.920
Essentially wise was possible plane to you so your void

27:02.830 --> 27:03.600
draw

27:07.490 --> 27:08.600
or

27:14.740 --> 27:15.680
change it.

27:15.720 --> 27:16.100
CH

27:19.420 --> 27:22.120
In true.

27:22.390 --> 27:29.230
So this will actually fill in what goes here essentially and all rows.

27:29.980 --> 27:38.770
So char name routine row plus a

27:42.850 --> 27:44.600
because the row.

27:44.790 --> 27:51.120
For example if it is 0 0 plus a is a and then one plus a is b.

27:51.160 --> 27:51.670
Right.

27:56.240 --> 27:57.000
In

28:00.330 --> 28:09.110
this and then will go through all the columns C zero.

28:09.180 --> 28:11.140
So this order is

28:14.560 --> 28:27.100
plus and will say see out space and then what we want right now I'm going to print out another space

28:27.130 --> 28:34.630
but this is this is going to change this part because we want is whatever is the representation of that

28:34.630 --> 28:36.360
ship.

28:37.090 --> 28:39.760
And show you exactly what I mean this second

28:43.340 --> 28:48.030
this way.

28:48.310 --> 28:53.470
And similarly for the gas I'm actually going to copy

28:55.880 --> 28:56.390
this

28:59.120 --> 29:04.400
void drawer and I guess sporter

29:08.820 --> 29:09.610
the player

29:14.330 --> 29:14.560
in the

29:20.420 --> 29:21.180
K.

29:21.440 --> 29:22.280
So

29:27.020 --> 29:34.970
now once again.

29:35.200 --> 29:37.190
And I said OK.

29:37.750 --> 29:44.170
So see how this almost looks like what we want right.

29:44.630 --> 29:54.900
So you'll see each there is a a a b c f g h i j for each row.

29:55.080 --> 29:57.050
And so this will be kind of the

30:00.050 --> 30:08.650
this will be kind of the player ship board and this will be his guess word.

30:08.990 --> 30:09.350
OK.

30:09.360 --> 30:20.070
So that's why I met whatsoe'er what I meant with them being next to each other at an early age change.

30:21.700 --> 30:26.080
SCHROCK Holmes So how come this is not working.

30:34.250 --> 30:35.450
Missed something.

30:38.870 --> 30:40.480
Toothpastes here.

30:44.100 --> 30:45.370
Toothpastes here.

30:46.860 --> 30:49.810
Three spaces two spaces

30:52.480 --> 30:55.640
Jesus.

30:55.880 --> 30:58.230
And then again they're real.

30:58.490 --> 30:59.900
So this is two spaces.

30:59.900 --> 31:00.930
This is two spaces.

31:00.930 --> 31:03.100
This is one space.

31:03.860 --> 31:08.280
So you'll notice I'm drawing both players boards.

31:08.300 --> 31:18.720
So what we need to do now is I need to fill in what the representation of each ship will be.

31:18.730 --> 31:19.080
OK.

31:19.100 --> 31:29.520
So if I have an aircraft carrier down here basically or what I want to see is a right and it's hit then

31:29.520 --> 31:36.020
it's going to be a like if it's at here star a.

31:36.560 --> 31:40.440
And then that's that's why I chose the names that I did for the

31:43.440 --> 31:53.360
ships because you'll notice that none of these start with the same character a b c d s.

31:53.470 --> 31:57.670
Ok so I did that on purpose actually.

31:58.470 --> 32:10.170
So let's actually get the representation for the ships so that

32:17.180 --> 32:19.310
so strong this

32:22.000 --> 32:32.000
will say char get the ship in station counts.

32:32.210 --> 32:32.860
We're

32:36.840 --> 32:44.210
in and I'll pass it the row.

32:44.570 --> 32:46.140
So this second

32:52.730 --> 32:59.190
row you know it the column and if it hits

33:02.000 --> 33:08.840
the player dock ship board because we're checking the ship board because as the whether it's hit or

33:08.840 --> 33:19.700
not intromission column dot is hit then we're going to return a star character.

33:19.820 --> 33:25.620
This is going to represent hit.

33:27.340 --> 33:33.190
And then here if player dot ship board

33:36.100 --> 33:46.730
row and column ship type you get up you could probably also use a switch statement if you want.

33:47.280 --> 33:49.770
Not going either.

33:52.620 --> 33:53.080
You're

33:58.430 --> 34:05.190
and return it's in a k a A for aircraft carrier.

34:05.300 --> 34:07.370
If player docked ship or

34:10.760 --> 34:12.560
row and column

34:15.600 --> 34:16.470
ship type

34:19.240 --> 34:21.590
is the bell ship

34:25.170 --> 34:32.940
to turn it be it will be if player ship word

34:36.490 --> 34:41.150
to cone ship type

34:44.180 --> 34:46.420
it's the cruiser

34:51.110 --> 34:56.070
Hurn see if played

35:00.610 --> 35:02.060
call them

35:09.170 --> 35:14.340
the destroyer.

35:14.660 --> 35:23.100
Turn the and if you're down to ship word

35:25.830 --> 35:26.820
in on

35:31.320 --> 35:33.970
type as teams

35:40.390 --> 35:41.800
turn as

35:44.340 --> 35:48.340
and otherwise we're going to return empty.

35:49.890 --> 35:51.120
So it's not there.

35:51.160 --> 35:54.240
Essentially.

35:54.410 --> 36:00.650
So this will take care of drawing on our ships once we place them we have placed them yet.

36:00.920 --> 36:05.370
So it was set up boards.

36:05.360 --> 36:11.590
It's not done yet but we will do that in the next lecture.

36:11.630 --> 36:15.890
But there's one more function we need to take care of and that is

36:18.860 --> 36:22.770
I guess get gets representation.

36:24.650 --> 36:31.890
Gas station at is where

36:34.640 --> 36:39.650
you home.

36:40.100 --> 36:41.370
Laird Yes.

36:41.460 --> 36:48.250
Ord row and column this will be a lot easier on us.

36:48.310 --> 36:48.770
It's

36:51.420 --> 36:56.520
then all return again that star.

36:57.200 --> 36:58.640
Otherwise if

37:01.380 --> 37:05.480
the player gets bored.

37:05.600 --> 37:06.350
Ro

37:09.180 --> 37:11.490
Cohen is a miss

37:14.760 --> 37:26.370
and will return a zero I guess or no lower case as we haven't guessed there is space.

37:28.880 --> 37:32.950
No it's G.T. missed

37:40.530 --> 37:42.140
missed OK.

37:44.280 --> 37:51.750
So that will do it for the drawing functions.

37:52.140 --> 37:54.440
But we still have to actually call the

37:57.640 --> 38:04.980
representations of this one and get this ship or ship repens representation ship

38:07.870 --> 38:41.050
teach in where the row and the call them they and some here get gas station where row and the call.

38:41.130 --> 38:46.040
So if I run this again nothing will change.

38:46.830 --> 38:47.950
Cuz

38:50.330 --> 38:52.880
there's no actual ships on the board yet.

38:53.000 --> 38:59.100
So in the next lecture we're actually going to place the ships on the board and actually get it to draw.

38:59.430 --> 39:00.530
Ok so you then.
