So far our game is played properly and we can actually go in here and play the different titles and
we get good result and we see the game a state as we saw it in our previous lessons.
However there are some really major challenges with our game and I'm going to try to demonstrate all
of them to you before I go into fixing them and I should mention that while this video was paused I
changed the duration of all of the transitions to two so we can actually see a little bit of a longer
transition.
Now let's go for problems.
The first thing is this.
If I tap on the tile and that tile turns and shows us number two I can tap on it again and turns to
again and it feels oh I found the right one.
So it actually compares the same time against himself which is obviously not a good thing.
So thats the first thing we have to avoid.
They have to make sure we have one tile has been tapped.
It can not without a gain.
The other problem we have is this but I tap on a time and its animation hasn't finished yet.
I can install another one so I can top this and then on the boss at the same time which is another good
thing I have to make sure I wait for one animation to end before I go in I tap on another one.
So thats the second problem.
Now look at this one this one is a little bit more challenging to understand.
Imagine a top on this one time.
It turns on a tap on the other one and that one turns.
And we compared them and they are not the same for what happens if I do this.
What happens if I tap on one time it sounds and then for whatever reason my user decides to reset what
is going to happen if I tap on a tiger right now if I tap on any time is going to flip and then is going
to flip back because eatings the app is this still in the Complera state.
You see I tapped on one.
I put the app in the compare mode and I reset the Apostol still thinks it is in the compair mode.
So when I tap again it thinks that it has to do the comparison.
And obviously everything goes bad.
So thats another thing that we have to be.
We have to be mindful of what we have to kind of address them.
So let's go ahead and try to fix all of these things going to go into my reset function first and in
my research function I'm going to say when you do a reset and the game time becomes zero and the farm
talks become then and the game label is hit then it's to a few other things.
Say first time that becomes nil.
So if our user decided to switch between a certain level of the game and the game is played to another
reset level then we make sure that the tiles are actually in.
So the first time isn't that the second time is all soon.
None of them has a value within them.
And most importantly compare now becomes false.
So we are not at the compare stage when the game resets itself every every time that we reset it.
So that's the first thing that I want to keep in mind.
Then the important thing becomes this thing.
If I stop one I should be able to tap another one until this animation is finished.
So to tackle that I have to actually have a variable that tells me if something is currently being animated
let's say it again I have another way to know if something is currently in the middle of the transition.
So to do that I'm going to go to my view controller and I'm going to add a new valuable down here and
I'm going to call this one that title or take title is animating.
And that is by default of course false.
But soon enough is going to become true.
When does it become true every time that we begin an animation and that happens in all touches and that
it touches and that whether we go with this compare mode or to this other one we end up running an animation.
And since that is happening I'm going to go ahead in here and say every time they come in here and we
find a toile of the type.
My label.
Let's go ahead and say a tile is animating this through.
So every time that we go on we begin an animation we set that to be true.
There are two things we still have to do.
We have to set it to False some sometime B we have to use it.
So if it is animating we shouldn't do anything.
That second part is actually the easier parts I'm going to do it here.
I'm going to say Venda touch ends.
If a tile is animating it means something is still running.
Just return don't do anything.
Don't do any of the rest of these things so that's perfect so far.
If a tile is animating we can't touch anyone nothing is going to actually work.
We then return out of the function.
Now if it is animating we have to wait for the animation to finish.
And if it did finish we have to be able to tap again.
And that's where things become a little bit more complicated because the reveal and compare does a different
thing than the flip to reveal.
So I'm going to go to the flip to reveal in here and in here I'm going to say when the animation ends
in the completion we have to set that value to false again.
So I have to write the body of the completion which I'm going to do it like this.
I'm going to say I have it's body and it has its argument of the closure.
Let's call it rez.
I'm going to say that we have to eventually close down our function.
So each year in the completion of the flipper reveal I'm going to go ahead and say self at tile is animating
becomes false.
Now this is only one of the four different types of animations that we have because we have Philip backflipped
smile reveal and compare and flip to reveal.
So this was the flip to reveal.
The school had to flip back flip back I'm going to have to copy the same thing in the animation so I'm
going to copy the whole completion block to flip back and say when you're finished doing whatever it
is the animation you're doing set the tile is animating force.
I'm going to go to Philip to a smile in here and I'm going to do the same thing.
Once you decide that that is the right one and you showed us your smile do the same thing and end the
reveal and compare which already has a completion Bruck.
I'm going to say self doubt.
A title is animating becomes true and that's all I have to do to fix that one.
Let's go ahead and run this up and see where we can get so far we should be in a place that if it is
being animated We should then be able to tap on another one so that and be here when I have.
Nothing happens once again and nothing happens so the moment I let one of them finish that is when I
can tap again.
Also that problem we had before we saying this one and then reset and play again is not there anymore
simply because everything we had the resets.
Why didn't we end up doing this compare now becomes false.
So as a result everything that is said the first time is nil the second time and then on the compare
is what's the only problem which is still lingering is this.
I have tapped on one time.
It sounds like that after I play it again it shows that I kick it on its own so there is still something
that we have to address.
Let's see how are we going to do that.
This only happens if we have already tapped on something and we are touching it one more time.
So knowing that there is a radius in the touches and that method this is the situation it will happen
if you have already touched something.
If you've got them the first time now you're getting the second time it is actually happening to be
the same as the one before I stop on this one.
It flips.
I top my self again.
Again it flips.
So it's only happening within this part of the court.
So when you're I'm going to say you've typed while the one that you just found is the first time.
If this is the one you already memorized that this is the one then don't do anything return again.
So in the body of the touches and that function if we tapped on a tile we found it and we're in the
Complera state it means the second time you're tapping on something.
If that did happen then obviously we should just sit here because the tile that we are trying to touch
again is the tile that we have already found.
Now I want you to spend just a few seconds and look at this piece of code.
Perhaps only this little part of it and ask yourself if this is going to work because I can see a problem
with it.
And let me run the code and maybe that problem shows itself.
So here is what we were trying to avoid tapping on IDN and then tapping on it which worked very well.
It didn't let us do it.
Now what happens if the user does that and then they realize oh we cannot tap on the same tile twice
and then they try to tack on something else nothing happens.
No animation runs.
And the reason for it is this.
And this is something that you know you could run the app and then understand and try to fix it or you
could look at the code and hopefully get it right.
To be honest I didn't realize at the very first time I was trying this code.
So here's the situation when you type on any object and you find it you said a tile is animating to
true in here.
It will return without anyone setting it back to false.
You see before you had this piece of code either they reveal and compare or flip to reveal one of these
guys with eventually said this tile is animating to force.
But right now we're going to return.
No one is doing that.
So in order to fix it I'm going to say if that did happen say a tile is animating is false.
Let's see if that's going to address our issue.
So now I top on one.
I cannot tap on itself anymore and I can tap on somebody else and they too they get compared against
each other.
And if I touch one.
In the meantime I can not touch one.
And then when it ends Obviously I trust it.
And if I tap on one and I for whatever reason decide to reset everything is reset I'm replaying the
game and everything is working.
That is however not very true.
There's still one other issue.
And let me show you how that is happening.
I've got four on seven.
They are not the same of course.
I have to really speed this up so that 4 and they are the same and they're working.
So what happens if they use their taps on this again.
It returns to its previous four numbers status simply because we haven't had a mechanism in place that
says if you found something remove it from the pool I don't want you to play on something that you have
already found.
So let's go ahead and add that one here as well.
I'm going to go to touches on that.
I'm going to go in here and say voyde you find the touch and you do all of these things and you know
that you have found a toilet which is of the type label.
Right.
Then do this effect find the tiles array that contains top tile.
It's Muzi have tapped on something we have already found which is for instance this one.
If that's the case don't do anything just for that.
So this part happens once you've found one of the tiles because even despite that we have already found
is a member of the right type of objects.
It is a member of the label.
So if you're saying if you typed on it and it was the right type.
What we have already found that don't do any of these things just right here.
Let's see if that's going to work.
So here in the simulator I've got this one 0 and 1 which are not the right ones.
I had one and one which are the right ones.
And now that they flip to where they needed them to.
I can't stop on them anymore because this piece is wrong now.
It says Oh these are the guys you have already found.
You shouldn't try to top on them anymore.
So that's about that.
A very long list and I guess with so many different things to do.
Let me quickly recap everything we did the other than your variable called Etoile is animating which
is false by default.
Every time we went to the touches and we said that the value to be true which means something is happening
right now.
Every time we came for touches and that we tested.
If that is true we shouldn't be doing anything anymore.
And every time the animation ended such as in the reveal and compare or into the flip to a smile we
set that value back to false which helps us understand that we now can touch some other times and then
we said in our touches and again that if we tapped on a time and that time was a member of the Von's
we have already found don't do anything just right there.
So we don't have to do the comparison anymore.
And then we said if you tapped on a tile and you placed it in the freestyle and then you tapped again
on the same one.
And if it was the right one the same one as before then said there is any animating to fall so we can
reach top both return don't do any of the comparisons or anything anymore.
And that is essentially all we have done in this lesson.
It is a bit of a long one but it shows us everything that we needed.
So let's keep it up to here and move on to our next lesson.