OK I'm sorry to report that we're all losers.
At least according to our game manager.
Don't read too much into that.
We have our game and we can always lose but it's actually impossible to win.
OK.
So how do we win.
In the end game routine we've already set up the win messages.
We see that we're all ready to show the message window with you when but you need to trigger some kind
of game winning conditions and the game play and do that.
We actually have to go back to the play game routine in the play game routine.
We have a wild loop that's always running.
So while the game is not over essentially this while loop is running every frame almost like an update
method so inside of here we can check our score against the current score goal.
If on this frame we exceed the score goal then we win.
All right.
So let's write the code for that.
Our current score is actually being kept on the score manager.
So we need to check their score manager instance is not know then well exactly how do I access the current
score of the score manager anyway.
Score malinger instance dot and there's nothing really there to help me get my current score Monod developed
shows me everything that's publicly available and I don't see current score.
So let's go back to the score manager class and I see that my current score is a private integer.
Now I could just go ahead and make this public.
But what's much more common you'll see especially in a production environment is that we would make
this a property.
Now we saw properties briefly when we made the singleton class A property is a public means of getting
access to an otherwise private variable.
So I can make a property simply by saying public and curred score and it looks like a variable.
Up until this point.
And then instead of a semi-colon or an equal sign when I'm going to do now is put curly braces.
Now I property is going to be named Just like my current score except I'm going to capitalize it in
Pascal case and strip off the prefix.
We don't set the properties value directly.
Instead I define a code block with curly braces and then we have a get and a set accessor method inside
of it the get method is going to be used to get the value out of the property.
And that's just going to return and current score.
Now I have a set method I can use the value keyword to pass a value into the property.
And then what we do is we just set and courage score equal to the value.
Now inside of here you would often use properties to handle a little bit of side logic.
You can add quite a few statements in either the set or the get method and if you recall back to the
singleton class you can see that up close here we have a lot of logic trying to figure out what's the
correct instance to return from the capital instance property.
So for example if you had a getter and a setter and you want to update the UI every time you set the
value for any current score we could have some logic in here that updated the current score for example.
Now the other great thing that you can do with properties is that you can make it read only and I can
do that just by removing the set accessor method.
So let's just grab this whole set block and delete.
Now we have something that allows us to get the current score out of the score manager.
But I'm protected against actually changing the current score by accident.
The only way you can really add to the score is using that public add score method.
No properties are great for the protection of our data.
And so that's why you'll often see them in handling the data into a private variable.
Now we haven't used properties a whole lot because we didn't want to overly complicate our previous
lessons but now that we're toward the end of the class I should tell you everywhere that you have a
public variable where it's public just to give access to another class you might want to consider turning
that into a property instead.
Now back in the game manager I can just check if the score manager thought instance that current score
of the capital C is greater than or equal to the score goal.
And if so then and it's game over it's true.
And and is winner is also true.
And then that's it.
That should trigger our game winning.
Dylan So if you save it in the editor let's set a very modest score of say 500 points in ten moves.
And I'll play the game
OK.
As a score goal of 500 we'll make a few swaps and if I get lucky on a chain reaction collapse and once
I hit 500 then bam you win
OK.
That's pretty good.
One thing that might look a little bit better.
Let me just put in a small delay before the screen Fator triggers.
Let's move the lines for the screen Fator after the message window.
And we'll add a little delay.
So you'll return to wait for seconds.
Just one extra second in there.
And now let's try again.
And let me try not to embarrass myself.
Whoops.
Coulda made a match five there
and now you could see our message window slides into place and then we get a little a second before
the screen fader kicks in.
I think that looks pretty good.
Now again if we were developing this app for real we would now have a little dialog box that told us
oh we've won the game and you want to replay the level try to get a higher score or go back to the main
menu where you can load a different level.
Right now we just have this one level and we're just reloading it.
OK well our game is finally coming together.
Maybe it's still at a proof of concept stage but it's playable and it is starting to get more fun.
What we really want to do now is start adding some bells and whistles in the next lesson.
Let's do that quite literally by adding some sound with a sound manager.