That we have the high score table and Draut we need to be able to read it in and save it at.
So let's start doing those functions so just up here I'm going to say for read we save high scorers
it's going to take the
score table
I referenced Scott Streff
and are also going to write the mood ice.
High scores and this can't be hype.
Concert tickets change it.
So this way
so we have the two functions you're declaring and I'm just going to put them down here.
And we're going to implement them yet.
We're just going to use them in the code.
So when I save or add a high score I want to save the high scores they just say save high scores here.
Pass in.
And we up here
here going to say load scores.
Table.
So now we're using it.
And there's one thing I want to do in a row.
Save that for later.
So here now let's actually implement them.
We're going to need while we first need to actually include
stream
that because you have file for file.
Oh right.
OK.
That is now down here and we need to have an off stream file.
Call it and we to open a file and we have to choose whether we want it to be binary file or a text file.
And I think we're going to do a text file for this one and I'm going to put
in put a COTS char star file name here.
And to call a tie score scores table.
Text Vaders script table DXi
So this file name and use or receive a file open file name
and then I'm going to check to see if the file file is open just like for
and if it is then we will say four equals zero or less than table scores.
Will not scores science
and we do the same trick I did for a rate above right here and I'm only a draw are only going to save
10 of them.
I was 10 plus in now that we have to be in two places we probably should have constant for it.
So Max scores 10.
Year
air
and we'll say out file
are going to save the table scores.
I got name in the space between the table scores score
and all like so they and rate here will save file not close
up file.
Sorry
close.
OK.
So this will actually save the high scores.
And now let's load the high scores back.
So I have stream
and file
and say File Open file name for
and want to need string name in the score value.
In roles we need a score
score very well.
While we say if infile Dodge is open
and while not well or not at the end of the file
OK well say infile and get rid of the whitespace.
And if we're at the end of the file then say there is like kind of a blank line break.
Otherwise
say infile name you get a score you
bat and send it to actual score.
They will just add it to the scores.
And notice that we won't have to sort it because it's already in sorted order.
So we just close the file
so they.
So now
must think we need to do and that is in our handle input
if the if were in the intro screen right.
We should be able to see the high scores of that screen
or from that screen.
So I'm going to say.
And you have to press S to see the high score.
So if game dot current state is in the intro
then go to
high score screen
so the last thing we need to do is
say this to be true.
And so you break orce
break here.
Courtot So let's run this.
And there's no message here or no message saying you can go to the ice cream.
So it's actually do that as well.
And it's good to draw
draw a screen here and put a new string
press as string Rice -- to the scores.
And need
exposition
so
and string
the string ear.
So it's actually moved this up by five or something
just format it.
It's too high
too.
That's it.
So if I press S I should see the high scores.
There's obviously no high scores yet press space and go back.
Essed scores based back in press space in walks we try again.
It's really gotten hit song Id.
I'm actually trying to get hits of course.
So it's really bad bad get saved.
And the high score table let's exit and let's run this one more time in hopefully we should see the
high score that we just did.
And there it is.
And it's right there right.
So that's really rich.
I think we're done.
Tax Invaders game.
So I really hope you enjoyed it.
Hopefully you programmed along with me and I hope you enjoyed this game and working through it.
I know I went really fast through a lot of the explanations and that's really because you need to when
you're learning something new and trying to get good at it.
It really does take a lot of time to learn.
And often I found these when I was learning this my teacher actually said that you're not going to learn
much from our lectures.
You're going to learn from actually doing it yourself.
And so I kind of skipped a little bit on the actual explanations of a lot of these functions because
I really want you to kind of pause the video understand the code kind of step through it step by step
and see see really what's going on and why it needs to be that way.
OK.
So a lot of.
So I have to put a lot of responsibility on you to actually kind of grasp what's happening.
So I hope you enjoyed this project with a lot of fun for me.
This is quite a quite a big project seed's almost twelve hundred lines of code to actually do but keep
practicing and come up with some some of your own projects and see see how well you can actually see
how well you can actually program those projects and come up with.
I made I made these all look a lot easier than they are.
This would probably take you quite quite a bit longer than it took to pass through here but that's OK.
It's all really part of learning of programming and you just keep doing it and know and you'll get better.
So I'm going to wrap up the course in the next lecture.