So now you've gotten the ship or the boards to draw properly.
Actually almost done sort of we even know it didn't seem like it.
All we've done and play game is do the set up boards but really that was actually a lot of the heavy
lifting in tween lectures.
I just set up the
to run in my terminal because I want to have it I want to be able to clear the screen and use that clear
screen function that we wrote hangman.
One thing I did also is I changed the size of my bat the terminal window the default size.
Usually it's like 80 by 24 I made it 86 by 32.
So I did that by going to preferences and then settings and then in the window size that is change that
columns to 86 and the roosted to you in Windows.
You really just have to right click and then hit preferences or something or settings possibly and you'll
see somewhere called
I think it's like size or something and then you can actually change the size of your window on Windows
as well.
So that's just one thing I did.
So I'm not going to show you how to set that up.
I showed you that already in hangman.
So now I want to in our draw function is done here.
Job boards.
I will clear the screen clear screen
J.
Do.
This is a one vertical clearing the screen and there's one other thing I want to do in set up boards.
You wrote that function in our
utilities to wait for a key press.
So I actually want to use it here.
So here I want to use wait for key press.
And actually here AFTER AFTER THIS TO WAIT FOR THIS
like that it's.
So now if I run it and I say A or actually say J say 10 or Zambal it wasn't a valid placement it says
it's a and b c it says Press any key to continue.
So then again it's a one horizontal k.
So it's working pretty nicely.
So now we should really just start wrapping up really.
So we want to finish play game
and you may think so many things to do.
It's really not that mean things to do and actually one thing we need is the current player or current
Where am actually going to set them to be Player 1 just because player 1 will get precedence and the
other player will be player to notice him using pointers here.
And I will also get the guess an I guess and we'll say do will draw the boards.
Of the current player.
Since it's a pointer we have to dereference it.
And all I have is valid guess at and we'll say Do While know is valid guess.
So we basically want to get it or.
Well first we want to prompt either so see Ouch
current We're name
what Which guess
K and then we'll get the guess using the function he already made get board position.
It's very me that function last time and we'll basically it's a valid guess is no guess a valid guess
if
essentially the current CH clear
so the guest board
so his guest board is is valid.
If it wasn't if we haven't guessed they're essentially so
what.
So if that's equal to G.T. non
So that's that one.
While these
will make that in a minute.
So that's really all there is to that one.
And then we have to check to see if it's not valid.
Yes we should just output.
Yes we should point to the user that it was which was a valid guess.
He.
Yes.
So.
So now that we have a valid guess we should update the board.
Right.
So the board will actually return to ship type the ship type that was hit.
So when to use ship type time.
And it's going to be cool to update or it's using the guess in the current player and the other glare
and then we will draw the boards of the current player
so and we'll say if the type is not equal to Esti none right.
So if it was a hit.
In other words and if it if we sunk the other players ship the player and other player so his ships
of the type that we hit minus one.
OK.
So notice up here.
That's how we kind of initialize our ships before we actually initialized it in this order.
So aircraft carrier first then shipping group cruiser than destroyer and submarine.
And we have this none here.
Right.
Well we I actually initialize them in this order as well.
So that's not a coincidence how I initialized it.
So the type will actually be one plus the
proper index into the players ships.
OK so the example aircraft carrier is one.
In this case so but aircraft carrier should be zero.
Is that is the zero element in the ship so I just said down here and play a game type minus one.
OK.
So that's again another use for income's is using them as indices into arrays.
OK.
And I did that very purposely.
So that was not an accident.
So Ouch.
You sunk
there.
The air is a your all your name
and then that ship name or ship type
so
gay men here we will say wait for the press just so that it doesn't automatically get cleared once drop
or will call the job boards.
That's OK.
So and then we will switch the players
in the current player and other player and notice I'm giving it the address of these pointers.
So if you saw the lectures four pointer pointers you know what I'm going to do here.
And then so is game over.
I'm going to need
one player to.
And we're going to need display when her
k.
So really we need to implement update boards is sunk so players is game over and display winner.
And they'll be one more with in is game over that we already saw two improvement.
So let's start at finding these and let's start with updateable it's
capitis
turn ship type ship that you hit.
If you did hit one and ship position to I guess and should be
the should be a reference.
Is your current player.
Here.
It's the other.
So it's going to hit it right here.
So update board.
So if the other player ship or third the CAS row and the gas column so if it's a
type so if it's not Esti none then it must be a hit.
Right.
Is the hitch.
Otherwise it's not a hit.
OK.
So the current player gets bored Gastar row guess or call them is Gaspard.
This should be cat.
And the other player
shipboard.
Yes.
Call them in.
This should be.
Is hit and it's true.
And then here you say get current player like he didn't hit.
He missed us or had just bored guest row and stuff.
Which column is he missed.
And will return other player ship or add in the guest row.
In the yes column in the ship.
Right.
OK.
So whether it's Jiechi non or it's some other type.
OK.
So that's really it for the update.
Actually it's really nothing more to it what to do is game over.
Cup is
put it here.
And returns true if the game's over and falls.
It's not
need to change the player it also can be Konst.
Your
copy it's
in play place it after here is OK.
So how would this work.
So if we look we made some new function called are all ships sunk in.
Gave it the player.
So we need to implement that.
So here we're just going to say return our ship ships sunk one or our ships song for play or to and
now appear are going to implement.
So it's going to turn a billion are all ships
and given the player
here.
And we go through see through this number of ships plus an F notch is on onto that next ships
and we return false right.
So if one is not Sonke and not all the ships just like lies which are true and now for the sunk will
sunk in now declare everything above.
Where in the
SO if
the ship's orientation is horizontal
then we'll go through all the columns of the ship ship position column
then ship session
complex ship such as
boss.
If so if it's not it's not hit here.
Then you know it's not sunk because they are every part of the ship has to be hit in order for it to
be sunk.
Shane Rowe column
it's not hit and there's no way.
And then we just do that for the critical case for each row.
Ship and
ship and rope was ship ships as
boss if not where.
Grew and ship the ship and call column.
So if that's not hit
then it can't have been on
here if it never return then obviously they're all sunk.
Or it or this ship at least sunk.
So now it's clear that these
after it came over
so we're almost done.
Actually we just need to do switch players and just play winner.
So let's do this one.
It's kind of fun.
So it's going to return nothing and it's going to take a pleasure star star
because we're going change the original pointer.
Just like we learned
in the last section.
So put it straight here.
So where start Tim it temporary will be the current where say
in the current Where is going to be the other player.
And the other player be OK.
So see our new you are referencing.
Each time we're actually changing the original pointer.
So we've gone over this in the last section so you should kind of understand how this is working now.
And we whenever the swap kind of function before so you kind of understand how this whole swap functions
sort of works as well.
OK.
So that's how you switch the player which players.
And now really in what's left all there is left is really the display winner
so this one should be fairly obvious as well.
How to write it.
Kind of written it a bunch of times for.
So I passed this by conc player reference
player for it.
It's
like so gay and let's just put it after as players emitting command like command click to go to these.
If you're under just in case you're wondering how I'm doing that.
So just put it right here.
OK.
And if it works you can use this one and again are all ships sunk player one then obviously player 2
1.
Right.
Yeah.
Great nations
to your name
you
and else.
Yeah.
Shin's
player 1
K super simple.
So that's really it.
So what's actually plaguing
one error.
No ship name for type
so I don't think that cleared
so it's.
So let's actually play one game of that.
See if everything's working correctly.
So a going to do the simplest possible out I can think of you on Mars aren't all an easy one.
Horizontal so for player one all all of his hours all of his ships will be all horizontally and player
to all be vertical OK.
Gee when.
So it all in one Santal.
OK.
So here is the press the key to continue.
Thing again.
So here's my lay out.
Player 1 and Player 2.
I will do all vertical.
A 1 vertical in a three vertical
A five go a
seven or goal a
vertical.
And here's player do.
So now switch to player 1 player 1 What is your guess.
I'm going to make player one just completely destroy a player do.
So I'm going to use kind of clairvoyant credible here and try that one so see how it hit.
So this is my guess for it.
It's a hit and it prompts me to continue by pressing any key.
So player 2 What's your guess be on.
So I see he has this here right.
So hopefully you will do this pretty quick.
Be one
hit and guess B to here.
Miss C-One hit and guess B three three
d one.
Still ahead.
No this has hasn't hasn't actually sunk a ship.
Right.
And B for
he one so use player to use aircraft carrier.
There you go.
Hopefully Stroh's be possible that be five miss a three.
Next
you won't play the entire game.
P.
Posts three their posts for that.
No no no.
So B.
I mean so you get the idea.
So I think everything's actually working pretty well.
And in the next lecture I want to go over adding a nice little feature because it's kind of annoying.
Playing against two human players raped her two human players playing when there's only one of me or
so would be nice if I could play against a simple AI.
So that's what we'll be doing in the next lecture.