1 00:00:00,500 --> 00:00:06,170 So far our game is played properly and we can actually go in here and play the different titles and 2 00:00:06,170 --> 00:00:11,360 we get good result and we see the game a state as we saw it in our previous lessons. 3 00:00:11,360 --> 00:00:16,400 However there are some really major challenges with our game and I'm going to try to demonstrate all 4 00:00:16,400 --> 00:00:22,670 of them to you before I go into fixing them and I should mention that while this video was paused I 5 00:00:22,670 --> 00:00:28,340 changed the duration of all of the transitions to two so we can actually see a little bit of a longer 6 00:00:28,340 --> 00:00:29,500 transition. 7 00:00:29,540 --> 00:00:31,080 Now let's go for problems. 8 00:00:31,100 --> 00:00:32,510 The first thing is this. 9 00:00:32,690 --> 00:00:39,650 If I tap on the tile and that tile turns and shows us number two I can tap on it again and turns to 10 00:00:39,650 --> 00:00:42,390 again and it feels oh I found the right one. 11 00:00:42,530 --> 00:00:48,470 So it actually compares the same time against himself which is obviously not a good thing. 12 00:00:48,470 --> 00:00:50,090 So thats the first thing we have to avoid. 13 00:00:50,090 --> 00:00:53,150 They have to make sure we have one tile has been tapped. 14 00:00:53,150 --> 00:00:55,580 It can not without a gain. 15 00:00:55,580 --> 00:01:01,060 The other problem we have is this but I tap on a time and its animation hasn't finished yet. 16 00:01:01,100 --> 00:01:07,460 I can install another one so I can top this and then on the boss at the same time which is another good 17 00:01:07,460 --> 00:01:13,640 thing I have to make sure I wait for one animation to end before I go in I tap on another one. 18 00:01:13,640 --> 00:01:15,870 So thats the second problem. 19 00:01:15,890 --> 00:01:21,110 Now look at this one this one is a little bit more challenging to understand. 20 00:01:21,110 --> 00:01:23,100 Imagine a top on this one time. 21 00:01:23,300 --> 00:01:26,340 It turns on a tap on the other one and that one turns. 22 00:01:26,390 --> 00:01:30,410 And we compared them and they are not the same for what happens if I do this. 23 00:01:30,410 --> 00:01:37,340 What happens if I tap on one time it sounds and then for whatever reason my user decides to reset what 24 00:01:37,340 --> 00:01:44,270 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 25 00:01:44,270 --> 00:01:50,030 to flip back because eatings the app is this still in the Complera state. 26 00:01:50,040 --> 00:01:51,610 You see I tapped on one. 27 00:01:51,620 --> 00:01:57,830 I put the app in the compare mode and I reset the Apostol still thinks it is in the compair mode. 28 00:01:57,950 --> 00:02:01,460 So when I tap again it thinks that it has to do the comparison. 29 00:02:01,580 --> 00:02:03,550 And obviously everything goes bad. 30 00:02:03,560 --> 00:02:05,830 So thats another thing that we have to be. 31 00:02:05,930 --> 00:02:08,770 We have to be mindful of what we have to kind of address them. 32 00:02:08,960 --> 00:02:18,760 So let's go ahead and try to fix all of these things going to go into my reset function first and in 33 00:02:18,760 --> 00:02:23,950 my research function I'm going to say when you do a reset and the game time becomes zero and the farm 34 00:02:23,950 --> 00:02:28,410 talks become then and the game label is hit then it's to a few other things. 35 00:02:28,410 --> 00:02:31,200 Say first time that becomes nil. 36 00:02:31,360 --> 00:02:39,130 So if our user decided to switch between a certain level of the game and the game is played to another 37 00:02:39,130 --> 00:02:43,690 reset level then we make sure that the tiles are actually in. 38 00:02:43,720 --> 00:02:47,430 So the first time isn't that the second time is all soon. 39 00:02:47,620 --> 00:02:49,510 None of them has a value within them. 40 00:02:49,720 --> 00:02:54,380 And most importantly compare now becomes false. 41 00:02:54,520 --> 00:03:01,480 So we are not at the compare stage when the game resets itself every every time that we reset it. 42 00:03:01,690 --> 00:03:04,460 So that's the first thing that I want to keep in mind. 43 00:03:04,610 --> 00:03:07,700 Then the important thing becomes this thing. 44 00:03:07,870 --> 00:03:13,600 If I stop one I should be able to tap another one until this animation is finished. 45 00:03:13,630 --> 00:03:21,170 So to tackle that I have to actually have a variable that tells me if something is currently being animated 46 00:03:21,850 --> 00:03:27,760 let's say it again I have another way to know if something is currently in the middle of the transition. 47 00:03:27,940 --> 00:03:33,910 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 48 00:03:33,910 --> 00:03:42,060 I'm going to call this one that title or take title is animating. 49 00:03:42,420 --> 00:03:44,550 And that is by default of course false. 50 00:03:44,560 --> 00:03:47,180 But soon enough is going to become true. 51 00:03:47,320 --> 00:03:54,790 When does it become true every time that we begin an animation and that happens in all touches and that 52 00:03:54,880 --> 00:04:01,610 it touches and that whether we go with this compare mode or to this other one we end up running an animation. 53 00:04:01,690 --> 00:04:07,260 And since that is happening I'm going to go ahead in here and say every time they come in here and we 54 00:04:07,270 --> 00:04:09,370 find a toile of the type. 55 00:04:09,370 --> 00:04:10,320 My label. 56 00:04:10,420 --> 00:04:14,590 Let's go ahead and say a tile is animating this through. 57 00:04:14,950 --> 00:04:20,150 So every time that we go on we begin an animation we set that to be true. 58 00:04:20,320 --> 00:04:22,250 There are two things we still have to do. 59 00:04:22,800 --> 00:04:27,710 We have to set it to False some sometime B we have to use it. 60 00:04:27,730 --> 00:04:30,830 So if it is animating we shouldn't do anything. 61 00:04:31,060 --> 00:04:34,680 That second part is actually the easier parts I'm going to do it here. 62 00:04:34,930 --> 00:04:37,710 I'm going to say Venda touch ends. 63 00:04:38,140 --> 00:04:44,450 If a tile is animating it means something is still running. 64 00:04:44,560 --> 00:04:46,660 Just return don't do anything. 65 00:04:46,660 --> 00:04:51,930 Don't do any of the rest of these things so that's perfect so far. 66 00:04:52,000 --> 00:04:56,440 If a tile is animating we can't touch anyone nothing is going to actually work. 67 00:04:56,450 --> 00:04:58,860 We then return out of the function. 68 00:04:58,900 --> 00:05:04,020 Now if it is animating we have to wait for the animation to finish. 69 00:05:04,180 --> 00:05:07,900 And if it did finish we have to be able to tap again. 70 00:05:08,170 --> 00:05:13,840 And that's where things become a little bit more complicated because the reveal and compare does a different 71 00:05:13,840 --> 00:05:15,680 thing than the flip to reveal. 72 00:05:15,820 --> 00:05:24,260 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 73 00:05:24,350 --> 00:05:28,880 in the completion we have to set that value to false again. 74 00:05:28,940 --> 00:05:33,350 So I have to write the body of the completion which I'm going to do it like this. 75 00:05:33,350 --> 00:05:38,050 I'm going to say I have it's body and it has its argument of the closure. 76 00:05:38,050 --> 00:05:39,560 Let's call it rez. 77 00:05:39,620 --> 00:05:44,400 I'm going to say that we have to eventually close down our function. 78 00:05:44,570 --> 00:05:52,910 So each year in the completion of the flipper reveal I'm going to go ahead and say self at tile is animating 79 00:05:52,910 --> 00:05:54,740 becomes false. 80 00:05:54,750 --> 00:06:01,280 Now this is only one of the four different types of animations that we have because we have Philip backflipped 81 00:06:01,370 --> 00:06:04,650 smile reveal and compare and flip to reveal. 82 00:06:04,700 --> 00:06:06,650 So this was the flip to reveal. 83 00:06:06,770 --> 00:06:12,440 The school had to flip back flip back I'm going to have to copy the same thing in the animation so I'm 84 00:06:12,440 --> 00:06:19,520 going to copy the whole completion block to flip back and say when you're finished doing whatever it 85 00:06:19,520 --> 00:06:24,700 is the animation you're doing set the tile is animating force. 86 00:06:24,710 --> 00:06:28,670 I'm going to go to Philip to a smile in here and I'm going to do the same thing. 87 00:06:28,700 --> 00:06:34,580 Once you decide that that is the right one and you showed us your smile do the same thing and end the 88 00:06:34,580 --> 00:06:37,570 reveal and compare which already has a completion Bruck. 89 00:06:37,580 --> 00:06:39,730 I'm going to say self doubt. 90 00:06:39,800 --> 00:06:45,890 A title is animating becomes true and that's all I have to do to fix that one. 91 00:06:45,890 --> 00:06:51,410 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 92 00:06:51,410 --> 00:06:57,730 being animated We should then be able to tap on another one so that and be here when I have. 93 00:06:57,800 --> 00:07:05,930 Nothing happens once again and nothing happens so the moment I let one of them finish that is when I 94 00:07:05,930 --> 00:07:07,500 can tap again. 95 00:07:07,700 --> 00:07:17,780 Also that problem we had before we saying this one and then reset and play again is not there anymore 96 00:07:17,840 --> 00:07:20,820 simply because everything we had the resets. 97 00:07:20,830 --> 00:07:25,740 Why didn't we end up doing this compare now becomes false. 98 00:07:25,760 --> 00:07:32,100 So as a result everything that is said the first time is nil the second time and then on the compare 99 00:07:32,150 --> 00:07:36,350 is what's the only problem which is still lingering is this. 100 00:07:36,350 --> 00:07:38,800 I have tapped on one time. 101 00:07:38,930 --> 00:07:45,590 It sounds like that after I play it again it shows that I kick it on its own so there is still something 102 00:07:45,590 --> 00:07:46,890 that we have to address. 103 00:07:46,910 --> 00:07:48,460 Let's see how are we going to do that. 104 00:07:48,470 --> 00:07:55,940 This only happens if we have already tapped on something and we are touching it one more time. 105 00:07:55,940 --> 00:08:03,900 So knowing that there is a radius in the touches and that method this is the situation it will happen 106 00:08:04,230 --> 00:08:06,850 if you have already touched something. 107 00:08:06,990 --> 00:08:12,720 If you've got them the first time now you're getting the second time it is actually happening to be 108 00:08:12,960 --> 00:08:16,450 the same as the one before I stop on this one. 109 00:08:16,560 --> 00:08:17,550 It flips. 110 00:08:17,670 --> 00:08:19,040 I top my self again. 111 00:08:19,170 --> 00:08:20,310 Again it flips. 112 00:08:20,370 --> 00:08:23,640 So it's only happening within this part of the court. 113 00:08:23,760 --> 00:08:32,040 So when you're I'm going to say you've typed while the one that you just found is the first time. 114 00:08:32,250 --> 00:08:40,240 If this is the one you already memorized that this is the one then don't do anything return again. 115 00:08:40,260 --> 00:08:46,290 So in the body of the touches and that function if we tapped on a tile we found it and we're in the 116 00:08:46,290 --> 00:08:51,480 Complera state it means the second time you're tapping on something. 117 00:08:51,570 --> 00:08:58,440 If that did happen then obviously we should just sit here because the tile that we are trying to touch 118 00:08:58,440 --> 00:09:01,560 again is the tile that we have already found. 119 00:09:01,560 --> 00:09:06,080 Now I want you to spend just a few seconds and look at this piece of code. 120 00:09:06,090 --> 00:09:12,030 Perhaps only this little part of it and ask yourself if this is going to work because I can see a problem 121 00:09:12,030 --> 00:09:12,660 with it. 122 00:09:13,110 --> 00:09:18,430 And let me run the code and maybe that problem shows itself. 123 00:09:18,430 --> 00:09:27,110 So here is what we were trying to avoid tapping on IDN and then tapping on it which worked very well. 124 00:09:27,120 --> 00:09:29,320 It didn't let us do it. 125 00:09:29,340 --> 00:09:35,610 Now what happens if the user does that and then they realize oh we cannot tap on the same tile twice 126 00:09:36,030 --> 00:09:39,660 and then they try to tack on something else nothing happens. 127 00:09:39,660 --> 00:09:41,280 No animation runs. 128 00:09:41,280 --> 00:09:42,720 And the reason for it is this. 129 00:09:42,720 --> 00:09:47,760 And this is something that you know you could run the app and then understand and try to fix it or you 130 00:09:47,760 --> 00:09:50,780 could look at the code and hopefully get it right. 131 00:09:50,820 --> 00:09:54,510 To be honest I didn't realize at the very first time I was trying this code. 132 00:09:54,550 --> 00:10:01,650 So here's the situation when you type on any object and you find it you said a tile is animating to 133 00:10:01,660 --> 00:10:03,480 true in here. 134 00:10:03,610 --> 00:10:08,360 It will return without anyone setting it back to false. 135 00:10:08,520 --> 00:10:15,600 You see before you had this piece of code either they reveal and compare or flip to reveal one of these 136 00:10:15,600 --> 00:10:19,210 guys with eventually said this tile is animating to force. 137 00:10:19,290 --> 00:10:21,650 But right now we're going to return. 138 00:10:21,690 --> 00:10:23,100 No one is doing that. 139 00:10:23,100 --> 00:10:29,780 So in order to fix it I'm going to say if that did happen say a tile is animating is false. 140 00:10:30,270 --> 00:10:32,540 Let's see if that's going to address our issue. 141 00:10:34,150 --> 00:10:35,680 So now I top on one. 142 00:10:35,730 --> 00:10:42,630 I cannot tap on itself anymore and I can tap on somebody else and they too they get compared against 143 00:10:42,630 --> 00:10:43,330 each other. 144 00:10:43,630 --> 00:10:44,840 And if I touch one. 145 00:10:44,970 --> 00:10:47,390 In the meantime I can not touch one. 146 00:10:47,610 --> 00:10:49,990 And then when it ends Obviously I trust it. 147 00:10:50,250 --> 00:10:57,750 And if I tap on one and I for whatever reason decide to reset everything is reset I'm replaying the 148 00:10:57,750 --> 00:11:00,000 game and everything is working. 149 00:11:00,030 --> 00:11:01,780 That is however not very true. 150 00:11:01,790 --> 00:11:03,970 There's still one other issue. 151 00:11:03,970 --> 00:11:06,210 And let me show you how that is happening. 152 00:11:06,210 --> 00:11:07,680 I've got four on seven. 153 00:11:07,680 --> 00:11:10,640 They are not the same of course. 154 00:11:10,680 --> 00:11:17,100 I have to really speed this up so that 4 and they are the same and they're working. 155 00:11:17,400 --> 00:11:20,220 So what happens if they use their taps on this again. 156 00:11:20,220 --> 00:11:27,690 It returns to its previous four numbers status simply because we haven't had a mechanism in place that 157 00:11:27,690 --> 00:11:34,980 says if you found something remove it from the pool I don't want you to play on something that you have 158 00:11:34,980 --> 00:11:36,540 already found. 159 00:11:36,690 --> 00:11:39,840 So let's go ahead and add that one here as well. 160 00:11:40,000 --> 00:11:41,750 I'm going to go to touches on that. 161 00:11:41,850 --> 00:11:47,700 I'm going to go in here and say voyde you find the touch and you do all of these things and you know 162 00:11:47,700 --> 00:11:51,300 that you have found a toilet which is of the type label. 163 00:11:51,450 --> 00:11:52,080 Right. 164 00:11:52,080 --> 00:12:01,880 Then do this effect find the tiles array that contains top tile. 165 00:12:02,040 --> 00:12:08,720 It's Muzi have tapped on something we have already found which is for instance this one. 166 00:12:08,730 --> 00:12:12,030 If that's the case don't do anything just for that. 167 00:12:12,330 --> 00:12:19,680 So this part happens once you've found one of the tiles because even despite that we have already found 168 00:12:19,800 --> 00:12:23,130 is a member of the right type of objects. 169 00:12:23,190 --> 00:12:24,780 It is a member of the label. 170 00:12:24,810 --> 00:12:28,380 So if you're saying if you typed on it and it was the right type. 171 00:12:28,520 --> 00:12:33,770 What we have already found that don't do any of these things just right here. 172 00:12:34,230 --> 00:12:36,020 Let's see if that's going to work. 173 00:12:38,110 --> 00:12:47,140 So here in the simulator I've got this one 0 and 1 which are not the right ones. 174 00:12:47,140 --> 00:12:51,880 I had one and one which are the right ones. 175 00:12:52,030 --> 00:12:54,920 And now that they flip to where they needed them to. 176 00:12:54,940 --> 00:12:58,730 I can't stop on them anymore because this piece is wrong now. 177 00:12:58,750 --> 00:13:01,090 It says Oh these are the guys you have already found. 178 00:13:01,090 --> 00:13:03,630 You shouldn't try to top on them anymore. 179 00:13:03,760 --> 00:13:04,970 So that's about that. 180 00:13:04,990 --> 00:13:09,300 A very long list and I guess with so many different things to do. 181 00:13:09,520 --> 00:13:15,880 Let me quickly recap everything we did the other than your variable called Etoile is animating which 182 00:13:15,880 --> 00:13:17,640 is false by default. 183 00:13:17,830 --> 00:13:24,190 Every time we went to the touches and we said that the value to be true which means something is happening 184 00:13:24,190 --> 00:13:25,040 right now. 185 00:13:25,210 --> 00:13:27,990 Every time we came for touches and that we tested. 186 00:13:28,030 --> 00:13:31,490 If that is true we shouldn't be doing anything anymore. 187 00:13:31,690 --> 00:13:38,200 And every time the animation ended such as in the reveal and compare or into the flip to a smile we 188 00:13:38,200 --> 00:13:45,460 set that value back to false which helps us understand that we now can touch some other times and then 189 00:13:45,550 --> 00:13:52,960 we said in our touches and again that if we tapped on a time and that time was a member of the Von's 190 00:13:52,960 --> 00:13:57,630 we have already found don't do anything just right there. 191 00:13:57,700 --> 00:14:00,320 So we don't have to do the comparison anymore. 192 00:14:00,580 --> 00:14:07,690 And then we said if you tapped on a tile and you placed it in the freestyle and then you tapped again 193 00:14:07,750 --> 00:14:09,070 on the same one. 194 00:14:09,070 --> 00:14:16,030 And if it was the right one the same one as before then said there is any animating to fall so we can 195 00:14:16,030 --> 00:14:21,120 reach top both return don't do any of the comparisons or anything anymore. 196 00:14:21,280 --> 00:14:24,270 And that is essentially all we have done in this lesson. 197 00:14:24,340 --> 00:14:28,440 It is a bit of a long one but it shows us everything that we needed. 198 00:14:28,570 --> 00:14:31,570 So let's keep it up to here and move on to our next lesson.