In this lecture I want to get the Gheen sort of set up and have everything drawing so you start with
getting everything set up.
So we're going to need two players
overseas or player type and here to
and we're going to do the initialize the player.
We didn't actually
didn't actually break it down in the top down design but I didn't do it because we were doing it right
away.
So initialize
we're in one it was going to name him Player 1.
It's where
to
like so.
So it's
a lead function declaration this year.
And we're going to pass by reference because right change the player's state in here we're going to
need a concert char.
Star player
and we're gonna have to string copy it into the player's array.
So we're going to Sturckow.
And by the way if we you should include the utils so that we have it.
I've already done that here.
But if you haven't you should pause the video and include the utils in your project.
So string.
So we have that.
Now let's implement this.
So how are we going to do this.
So let's say if player name is not equal to no pointer
is to use string copy.
And in fact we should probably also check to see and read the story when player name is greater than
zero.
And if that's true then we're going to copy it into our player name array.
So
in now we want to actually set all the ships correctly for the player.
OK.
So to do this we will say say player datt Shep's zero.
So be the
was going to be the aircraft I guess.
So type
reaching for this
kind of carrier
where ships
0
teach
size should be your
carrier size.
Merda chips
of
Rouche.
So the position and the orientation of this doesn't matter at the start.
Right.
It's a Roekel zero and seeing things here
you call them
ships hero
station again doesn't matter.
Because we're going to set them all in our set up.
So and we have to do this a bunch of times right now do it for each aircraft carrier.
So it would be nicer if we actually had it for each ship or should say no aircraft carrier would be
nice if we had a function to do.
So let's actually make a function and so it's a national as
ship.
And it will actually take the ship by reference and it will take the ship's size and the type.
Right.
That's the only Those are really only two things that really mattered and what just kind of set them
all to be like this.
So to copy this
to or she's going to copy this whole thing
cut it in and so instead of pulling to ships zero of this ship
that
and now all they have to do is just set the type and size ship type.
So in this space ship site it's.
So now when it's initialized player instead of just kind of directly doing it we'll just call the function
because we have to do it for each ship so.
And it will be in it in this ship.
Ship's zero.
Ear.
It's in the
carrier
K and we just need to do this for each one.
So
ships of one will be our battleship
and of to the cruiser
three or destroyer
or submarine
and that's it.
So that will now initialize all our other players.
So we only have two.
So that should be good.
So let's right the main kind of lube.
You know I do this is a name in with the players want it to and while want to do a
copy this
is peer
turns nothing you will pass by reference
here.
Day.
And we want to do that said
Lillian that many times shouldn't be too magical what we how we implement that.
So let's just implement.
Want to play again right now just the way
so is your input.
This and will have comments char input.
Yes or no.
Did before
it was input.
It's of course to get character and would you like to play again and slash and that's And will the error
string so it's actually to find it's years and when it's just fine it various their context should just
here straight
but error
as I get
past there and say valid input and two and remember are lower case and upper case stuff did for so and
will turn input equal to Y.
So there's what I want to play again.
So in either way.
So we're actually done with the main now.
And all we have to do is concentrate on play again.
So let's let's do the kind of set up for.
But we won't do the entirety of set up or.
I don't think this lecture will do the dry it so let's start at.
So I have to set up words for player 1 and set up order for player to
and that's all we're going to get.
In this lecture footplate game so he said it's
here.
So here we're going to make void's your attorney thing and I guess we'll pass it by reference.
Well OK.
It was our declaration
in down here.
Well actually it's some of it.
All.
So how did this work.
See set up or so clear the board.
So that's the first thing to do.
So again we'll have another function called clipboards
or boards of player and she passed comments actually no need to change.
So that's the reference again
here boards
and how will this work.
So all we have to do is say for our equals zero for that row.
Ours is less than the board size right.
Size or you just find that's
and go through all the column s
so board size
and what we have to do is clear the board.
So if we access the start with the board.
So the gas board of R and C should be Jiechi none right.
So this will set every element in this 2d array to be G-d not.
So the player effectively hasn't guessed here yet is what this is saying and like Likewise the shipboard
here this should be actually the ship type.
This is a ship part this whole thing.
And the ship type should be as not.
Right because there's no this really means there is no ship here at this location.
And also there's two elements to this array structure.
So is hit is false right.
Nothing was hit here and there's no there's nothing here in first place.
So that'll clear the boards.
That's what that means.
And if you go back you set up boards to clear boards of the player
right now is the very first step.
We said we appear and then we essentially loop through all the ships and then draw the board each time.
Given the current ship and then place all that right.
So I think what we'll do for the rest of this lecture is just draw the board and we'll skip kind of
the rest of it for now.
So what we're going to do is clear the boards and then just draw the board.
So draw forward it's
player.
Is this
here knock or turn or anything.
Just draw function.
And in this case now we're never going to change it so I can put Konst where I can change the player
as we drive.
OK.
In here it's a drop or it's.
So how will this work.
So what I want to do is have the I want the columns all marked and the rows are marked so the rows go
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
other.
So
this one is going to be a little bit hand-wavy won't really break it down in terms of the explanation
exactly but I'm just going to use star typing wreathing we need and I'll sort of explain after or explain
a little bit on the way.
Mostly when after.
So essentially what I want to do is draw the columns row.
So this is all the kind of one to 10 for each one.
So you don't even have this function but you'll see in a minute and then draw the
gain
and you'll see why did this.
You know
and I'm going to go through all the rose
and you're going to need a separator line.
Or
it's then you're probably encouraged in what I'm doing here but just just try to follow follow along
and you'll see exactly how this works.
It all kind of come together.
Normally when you're doing drawing it's very error prone and usually takes a few iterations get it correct.
So
here
ch.
Yes
there.
So essentially what I'm doing is draw a separate line which will kind of look like
it looks like this to you.
So it'll kind of look like this except for each three dashes we'll have another plus.
So each cell will look like this.
And does it look like an empty cell on the board.
OK.
So they'll have three spaces in the middle space will actually draw something to represent like the
ship or whether it was hit or not.
OK.
So
that's what I'm doing here.
And these are all functions of that it's like.
Ouch and all
in half to try another separate line for the last separator.
CH
one more step.
In another and
and up here.
So let's start drawing kind of lines and stuff.
So
right for let's say Boyd separator line
this see how much.
So this will essentially just make all the kind of all the cells essentially for all of the columns
they and the next one
rule
is pretty similar.
See Ciro's this or size
plus an
things this will actually draw the name of the thing.
It's
answer that deals with those most of it and I would just need a few more functions which is in fact
let's show what this looks like right now.
It's the first
Roger.
So you can see
it's not quite right.
So haven't done all of the kind of the vertical bars for each one and these are not centered correctly.
But that will be easy to fix.
Let's continue on with the East.
It's this simpler.
So it's those two and those I didn't have to declare these functions.
They didn't really just have to be above where you use them.
So I will actually declare them above anyway but just so you know you don't have to declare every function.
You just need to define them before you use them.
Essentially wise was possible plane to you so your void
draw
or
change it.
CH
In true.
So this will actually fill in what goes here essentially and all rows.
So char name routine row plus a
because the row.
For example if it is 0 0 plus a is a and then one plus a is b.
Right.
In
this and then will go through all the columns C zero.
So this order is
plus and will say see out space and then what we want right now I'm going to print out another space
but this is this is going to change this part because we want is whatever is the representation of that
ship.
And show you exactly what I mean this second
this way.
And similarly for the gas I'm actually going to copy
this
void drawer and I guess sporter
the player
in the
K.
So
now once again.
And I said OK.
So see how this almost looks like what we want right.
So you'll see each there is a a a b c f g h i j for each row.
And so this will be kind of the
this will be kind of the player ship board and this will be his guess word.
OK.
So that's why I met whatsoe'er what I meant with them being next to each other at an early age change.
SCHROCK Holmes So how come this is not working.
Missed something.
Toothpastes here.
Three spaces two spaces
Jesus.
And then again they're real.
So this is two spaces.
This is two spaces.
This is one space.
So you'll notice I'm drawing both players boards.
So what we need to do now is I need to fill in what the representation of each ship will be.
OK.
So if I have an aircraft carrier down here basically or what I want to see is a right and it's hit then
it's going to be a like if it's at here star a.
And then that's that's why I chose the names that I did for the
ships because you'll notice that none of these start with the same character a b c d s.
Ok so I did that on purpose actually.
So let's actually get the representation for the ships so that
so strong this
will say char get the ship in station counts.
We're
in and I'll pass it the row.
So this second
row you know it the column and if it hits
the player dock ship board because we're checking the ship board because as the whether it's hit or
not intromission column dot is hit then we're going to return a star character.
This is going to represent hit.
And then here if player dot ship board
row and column ship type you get up you could probably also use a switch statement if you want.
Not going either.
You're
and return it's in a k a A for aircraft carrier.
If player docked ship or
row and column
ship type
is the bell ship
to turn it be it will be if player ship word
to cone ship type
it's the cruiser
Hurn see if played
call them
the destroyer.
Turn the and if you're down to ship word
in on
type as teams
turn as
and otherwise we're going to return empty.
So it's not there.
Essentially.
So this will take care of drawing on our ships once we place them we have placed them yet.
So it was set up boards.
It's not done yet but we will do that in the next lecture.
But there's one more function we need to take care of and that is
I guess get gets representation.
Gas station at is where
you home.
Laird Yes.
Ord row and column this will be a lot easier on us.
It's
then all return again that star.
Otherwise if
the player gets bored.
Ro
Cohen is a miss
and will return a zero I guess or no lower case as we haven't guessed there is space.
No it's G.T. missed
missed OK.
So that will do it for the drawing functions.
But we still have to actually call the
representations of this one and get this ship or ship repens representation ship
teach in where the row and the call them they and some here get gas station where row and the call.
So if I run this again nothing will change.
Cuz
there's no actual ships on the board yet.
So in the next lecture we're actually going to place the ships on the board and actually get it to draw.
Ok so you then.