This lecture I want to go over making a little library to kind of encapsulate curses.
So in here I'm going to make a new header file in what I call it.
Curses utilities dot h
in that must have going to make a new source file in and call it curses.
It's C.P
in in the H mode to define some functions so first function is going to define it just to initialize
cursors
and going to say
whether or not in this the parameters whether or not I want to delay our input.
Nodaway
that it's in here.
Copy this in mind it's the file.
And you put this in the dot file and then ended up CBP file going to include curses you tildes done
each and I'm going to implement it.
So for the initialization really all it's going to be is to look second
actually up here in P.
I'm also going to include curses says this.
So again this is for Mac here on Windows you should be doing include curses.
It's a
sue.
Now we should write the function to initialize curses.
So don't say it it's in that I don't ever want Echo because he's this for games I don't ever want the
cursor
and I'm going to set the no delay
no this no delay capital-T are naming convention and I'm going to say no delay here because maybe I
want turn based games later.
And I'm always going to keep that
screen any more.
The first function we're going to have for our little utility library next function is going to be shut
down curses.
It's going to take no crammer's
or copy that or put this here and we're in when that.
So that's like that's already two functions to use.
And let's actually start testing this.
So instead of using it including this here
to include our own curses you do this to each answer in that say
initialize
curses in case get false.
For now
and when you say sure or well I guess since I don't wait till later for that we're going to say Shut
down here.
It's that way.
So I come back to this periodically and keep adding things.
And so the next thing I need is the let's do clear screen we're screen
copy this
in here is going to say clear
Dovid or clear screen function and also need our refresh the screen.
Wow
so copy that.
Here is trash.
So the point of doing all this is just going to be so we don't really have to keep every input reimplementing
everything we initialize and shut down everything.
Each time we'll just call functions and it also makes it for you know if you want to kind of portably
use this or maybe that curses invalidation changes shape.
Highly doubt at this point.
But if it did we could just implement everything.
Reimplement everything here instead of changing all of our programs directly.
OK so we have that you only need a couple more things.
Am I going to want
the say the the screen with
and shikse turn integer and are also going to need screen height
copies.
Put them here.
And to get the whip.
The screen is just columns to get height is the line.
Right.
And what else do we need.
Well let's do
character so we're going to see in each and then get Schar and remember it's into because we want so
said here and all it's going to do is turn good character now in our app here say get rich character
like that.
OK.
So the next thing is won't you be able to set a character.
Boyd
or maybe we should call it raw character and we'll give it the inte exposition and the y position and
notice it's X before y now.
And character itself character.
Copy this.
Here is
here.
You say return or not returns.
And the add character and exposition or why position gets first and then exposition and then the character
so this whole thing that we're doing is usually called the wrapper technical term and that's to to hide
implementation details.
What else are you going to need.
We're going to need say
maybe maybe once the move wrap Well we'd move cursor
and say in x x rows.
Why.
Now we can do X X first and then Y.
Move y pause x ball.
There'll be another one that we need.
But I don't want to really want to implement it right now.
I'm going to save that for our game actually.
So for now we're going to say we're still going to include curses up here.
We need it.
At but we're only really need it for this function in we'll say 10 10
a string string.
And run it.
It's still working.
It's good.
And the last thing we're going to do
you're is actually we're going to move this to each
this and we're going to make an and he is going to be arrow keys.
Or actually sorry arrow.
He's this
and I say up is he
down is he down.
In left he left in right.
Is he right.
So we're kind of making our own arrow keys and we're just setting it to be the
curses version.
So that's it for now we may add some things to curses you still a little bit later when we actually
tackle the game itself.
So in the next section we'll finally do our Space Invaders clone called TECS invaders.
So I'll see you then.