@@ -3600,170 +3600,212 @@ And we know exactly when that is in our controller.
36003600801
3601360100:42:59,577 --> 00:43:02,878
36023602It's right here in touch card. Whenever a button calls touch
3603+ 它就在 touchCard 方法里。每当按钮调用 touchCard
36033604
36043605802
3605360600:43:02,947 --> 00:43:04,613
36063607card, we know a card's being touched.
3608+ 我们就知道点击了某张卡片
36073609
36083610803
3609361100:43:04,682 --> 00:43:07,417
36103612And instead of doing all this flip card with emoji choices
3613+ 然后取代 flipCard( withEmoji: 选中的表情)
36113614
36123615804
3613361600:43:07,485 --> 00:43:09,985
36143617thing right here, I'm just gonna tell my game hey,
3618+ 这个方法,我用 game.chooseCard( at:)
36153619
36163620805
3617362100:43:10,054 --> 00:43:15,591
36183622choose this card. Okay?
3623+ 来告诉游戏说选这张卡片
36193624
36203625806
3621362600:43:15,659 --> 00:43:18,594
36223627So instead of handling it myself, I'm letting the model
3628+ 不是我自己控制器来处理,而是让模型
36233629
36243630807
3625363100:43:18,663 --> 00:43:21,230
36263632handle it. So, it's the one that's figuring it out.
3633+ 来处理它,让模型来实现逻辑
36273634
36283635808
3629363600:43:21,299 --> 00:43:24,199
36303637But there's something interesting to note here,
3638+ 但很有趣的是,我们注意
36313639
36323640809
3633364100:43:24,268 --> 00:43:26,869
36343642is that when I tell the model choose this card,
3643+ 当我让模型选择这张卡的时候
36353644
36363645810
3637364600:43:26,938 --> 00:43:29,905
36383647it might change the game might change. And in fact, I hope it
3648+ 它是可能会发生改变的,游戏的状态会发生改变
36393649
36403650811
3641365100:43:29,974 --> 00:43:31,841
36423652does change cuz it's supposed to be doing matching and
3653+ 而我也希望这样,因为它应该去匹配
36433654
36443655812
3645365600:43:31,909 --> 00:43:34,877
36463657all kinds of stuff. So it's gonna change. So now,
3658+ 等等,所以游戏的状态会改变
36473659
36483660813
3649366100:43:34,946 --> 00:43:39,415
36503662we have to update our view from the model, okay?
3663+ 那我们就需要从模型获取数据更新视图
36513664
36523665814
3653366600:43:39,483 --> 00:43:41,683
36543667Our view is now a little bit out of sync with the model,
3668+ 我们现在的视图就没更上模型的改变了
36553669
36563670815
3657367100:43:41,752 --> 00:43:43,085
36583672because when we chose this card,
3673+ 因为当我们选择这张卡片的时候
36593674
36603675816
3661367600:43:43,154 --> 00:43:45,087
36623677that could have caused the game to change.
3678+ 游戏的状态可能会发生变化
36633679
36643680817
3665368100:43:45,156 --> 00:43:48,057
36663682So we need a method like updateViewFromModel or
3683+ 所以我们需要一个类似于 updateViewFromModel 的方法
36673684
36683685818
3669368600:43:48,126 --> 00:43:51,594
36703687something like that. Some kind of func down here,
3688+ 来用模型更新视图,在下面实现这样一个方法
36713689
36723690819
3673369100:43:51,663 --> 00:43:55,430
36743692func updateViewFromModel. And what's that gonna do?
3693+ func updateViewFromModel 要做什么呢?
36753694
36763695820
3677369600:43:55,499 --> 00:43:58,534
36783697That's gonna use the other part of this API right here.
3698+ 他会使用 API 里的另一个部分
36793699
36803700821
3681370100:43:58,603 --> 00:44:00,803
36823702It's gonna look at all the cards and
3703+ 他会去查看所有的卡片
36833704
36843705822
3685370600:44:00,871 --> 00:44:03,772
36863707make sure all our card buttons match, right?
3708+ 然后确保按钮和卡片是保持一致的
36873709
36883710823
3689371100:44:03,841 --> 00:44:06,208
36903712Whether they're face up, whether they're matched,
3713+ 他们是否是面朝上的,是否已经配对了
36913714
36923715824
3693371600:44:06,277 --> 00:44:08,010
36943717all that business. We look in the game,
3718+ 等等这些。我们去 game 模型里
36953719
36963720825
3697372100:44:08,079 --> 00:44:11,046
3698- find out, and make sure our card doesn't match. All right,
3722+ find out, and make sure our card does match. All right,
3723+ 查看这些卡的状态,然后确保按钮是正确的
36993724
37003725826
3701372600:44:11,115 --> 00:44:12,948
3702- so how to we implement this updateViewFromModel?
3727+ so how do we implement this updateViewFromModel?
3728+ 好,那我们怎么实现 updateViewFromModel 呢?
37033729
37043730827
3705373100:44:13,017 --> 00:44:15,618
37063732Well I wanna go through all the card buttons and
3733+ 我要遍历所有的卡片的按钮
37073734
37083735828
3709373600:44:15,687 --> 00:44:19,355
37103737look at the game and set it up appropriately. So I could do
3738+ 然后对照 game 模型,然后正确地设置按钮
37113739
37123740829
3713374100:44:19,424 --> 00:44:24,893
37143742another for loop where I say for button in my cardButtons,
3743+ 我可以用一个 for 循环,也就是 for button in cardButtons
37153744
37163745830
3717374600:44:24,962 --> 00:44:28,330
37183747okay? And just go through and now each button will be if we
3748+ 对于 cardButtons 里的每个按钮,这个 button
37193749
37203750831
3721375100:44:28,399 --> 00:44:31,834
37223752look at the type of this it's going to be a UI button. See?
3753+ 如果我们查看它的类型,会是 UIButton,看到了吗?
37233754
37243755832
3725375600:44:31,903 --> 00:44:34,603
37263757Because this is a sequence of buttons. Isn't that cool?
3758+ 因为这是一系列按钮。这个可以吧?
37273759
37283760833
3729376100:44:34,672 --> 00:44:37,306
37303762All right? But I'm actually not gonna do that.
3763+ 是吧?但我不会这样做
37313764
37323765834
3733376600:44:37,375 --> 00:44:40,843
37343767I'm gonna do something else because I need to look up this
3768+ 我会选择用另一种方法,因为我要用
37353769
37363770835
3737377100:44:40,911 --> 00:44:45,147
37383772button's index in this card thing so I'm gonna do my for
3773+ 按钮的索引找到这个 card 里对应的卡片,因此
37393774
37403775836
3741377600:44:45,215 --> 00:44:50,018
37423777loop by index. In the card buttons array which I could do
3778+ 我选择循环索引。要遍历 cardButtons 数组,那我可以
37433779
37443780837
3745378100:44:50,087 --> 00:44:54,757
37463782with 0 dot dot less than cardButtons.count, okay.
3783+ 用 0..<cardButtons.count
37473784
37483785838
3749378600:44:54,825 --> 00:44:57,860
3750- Everybody understand this counter range right here, but
3787+ Everybody understand this countable range right here, but
3788+ 大家都理解这个可数区间吧?
37513789
37523790839
3753379100:44:57,929 --> 00:45:00,830
37543792I'm not gonna do that either I'm gonna show you another
3793+ 但是我也不会这么做。我要给你展示另一种方法
37553794
37563795840
3757379600:45:00,899 --> 00:45:05,501
37583797way, cardButtons.indicies, okay. cardButton.indicies
3798+ 用 cardButtons.indices,cardButtons 的索引
37593799
37603800841
3761380100:45:05,570 --> 00:45:09,839
37623802Indices is a method in array. Okay, that returs
3803+ indicies 是数组的一个方法(注:变量)
37633804
37643805842
3765380600:45:09,907 --> 00:45:13,509
37663807you a countable range of all the indexes into the array.
3808+ 给你一个由数组所有索引组成的可数的区间
37673809
37683810843
3769381100:45:13,578 --> 00:45:16,946
@@ -5188,6 +5230,7 @@ And then I'm gonna set it to be the index of the one and
518852301198
5189523101:04:41,077 --> 01:04:43,311
51905232only face up card.
5233+ 仅有的那张朝上的卡
51915234
519252351199
5193523601:04:43,379 --> 01:04:45,714
0 commit comments