Skip to content

Commit 970fb1b

Browse files
committed
2_801-842
1 parent 3016020 commit 970fb1b

1 file changed

Lines changed: 46 additions & 3 deletions

File tree

subtitles/2. MVC.srt

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3600,170 +3600,212 @@ And we know exactly when that is in our controller.
36003600
801
36013601
00:42:59,577 --> 00:43:02,878
36023602
It's right here in touch card. Whenever a button calls touch
3603+
它就在 touchCard 方法里。每当按钮调用 touchCard
36033604

36043605
802
36053606
00:43:02,947 --> 00:43:04,613
36063607
card, we know a card's being touched.
3608+
我们就知道点击了某张卡片
36073609

36083610
803
36093611
00:43:04,682 --> 00:43:07,417
36103612
And instead of doing all this flip card with emoji choices
3613+
然后取代 flipCard(withEmoji: 选中的表情)
36113614

36123615
804
36133616
00:43:07,485 --> 00:43:09,985
36143617
thing right here, I'm just gonna tell my game hey,
3618+
这个方法,我用 game.chooseCard(at:)
36153619

36163620
805
36173621
00:43:10,054 --> 00:43:15,591
36183622
choose this card. Okay?
3623+
来告诉游戏说选这张卡片
36193624

36203625
806
36213626
00:43:15,659 --> 00:43:18,594
36223627
So instead of handling it myself, I'm letting the model
3628+
不是我自己控制器来处理,而是让模型
36233629

36243630
807
36253631
00:43:18,663 --> 00:43:21,230
36263632
handle it. So, it's the one that's figuring it out.
3633+
来处理它,让模型来实现逻辑
36273634

36283635
808
36293636
00:43:21,299 --> 00:43:24,199
36303637
But there's something interesting to note here,
3638+
但很有趣的是,我们注意
36313639

36323640
809
36333641
00:43:24,268 --> 00:43:26,869
36343642
is that when I tell the model choose this card,
3643+
当我让模型选择这张卡的时候
36353644

36363645
810
36373646
00:43:26,938 --> 00:43:29,905
36383647
it might change the game might change. And in fact, I hope it
3648+
它是可能会发生改变的,游戏的状态会发生改变
36393649

36403650
811
36413651
00:43:29,974 --> 00:43:31,841
36423652
does change cuz it's supposed to be doing matching and
3653+
而我也希望这样,因为它应该去匹配
36433654

36443655
812
36453656
00:43:31,909 --> 00:43:34,877
36463657
all kinds of stuff. So it's gonna change. So now,
3658+
等等,所以游戏的状态会改变
36473659

36483660
813
36493661
00:43:34,946 --> 00:43:39,415
36503662
we have to update our view from the model, okay?
3663+
那我们就需要从模型获取数据更新视图
36513664

36523665
814
36533666
00:43:39,483 --> 00:43:41,683
36543667
Our view is now a little bit out of sync with the model,
3668+
我们现在的视图就没更上模型的改变了
36553669

36563670
815
36573671
00:43:41,752 --> 00:43:43,085
36583672
because when we chose this card,
3673+
因为当我们选择这张卡片的时候
36593674

36603675
816
36613676
00:43:43,154 --> 00:43:45,087
36623677
that could have caused the game to change.
3678+
游戏的状态可能会发生变化
36633679

36643680
817
36653681
00:43:45,156 --> 00:43:48,057
36663682
So we need a method like updateViewFromModel or
3683+
所以我们需要一个类似于 updateViewFromModel 的方法
36673684

36683685
818
36693686
00:43:48,126 --> 00:43:51,594
36703687
something like that. Some kind of func down here,
3688+
来用模型更新视图,在下面实现这样一个方法
36713689

36723690
819
36733691
00:43:51,663 --> 00:43:55,430
36743692
func updateViewFromModel. And what's that gonna do?
3693+
func updateViewFromModel 要做什么呢?
36753694

36763695
820
36773696
00:43:55,499 --> 00:43:58,534
36783697
That's gonna use the other part of this API right here.
3698+
他会使用 API 里的另一个部分
36793699

36803700
821
36813701
00:43:58,603 --> 00:44:00,803
36823702
It's gonna look at all the cards and
3703+
他会去查看所有的卡片
36833704

36843705
822
36853706
00:44:00,871 --> 00:44:03,772
36863707
make sure all our card buttons match, right?
3708+
然后确保按钮和卡片是保持一致的
36873709

36883710
823
36893711
00:44:03,841 --> 00:44:06,208
36903712
Whether they're face up, whether they're matched,
3713+
他们是否是面朝上的,是否已经配对了
36913714

36923715
824
36933716
00:44:06,277 --> 00:44:08,010
36943717
all that business. We look in the game,
3718+
等等这些。我们去 game 模型里
36953719

36963720
825
36973721
00: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

37003725
826
37013726
00: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

37043730
827
37053731
00:44:13,017 --> 00:44:15,618
37063732
Well I wanna go through all the card buttons and
3733+
我要遍历所有的卡片的按钮
37073734

37083735
828
37093736
00:44:15,687 --> 00:44:19,355
37103737
look at the game and set it up appropriately. So I could do
3738+
然后对照 game 模型,然后正确地设置按钮
37113739

37123740
829
37133741
00:44:19,424 --> 00:44:24,893
37143742
another for loop where I say for button in my cardButtons,
3743+
我可以用一个 for 循环,也就是 for button in cardButtons
37153744

37163745
830
37173746
00:44:24,962 --> 00:44:28,330
37183747
okay? And just go through and now each button will be if we
3748+
对于 cardButtons 里的每个按钮,这个 button
37193749

37203750
831
37213751
00:44:28,399 --> 00:44:31,834
37223752
look at the type of this it's going to be a UI button. See?
3753+
如果我们查看它的类型,会是 UIButton,看到了吗?
37233754

37243755
832
37253756
00:44:31,903 --> 00:44:34,603
37263757
Because this is a sequence of buttons. Isn't that cool?
3758+
因为这是一系列按钮。这个可以吧?
37273759

37283760
833
37293761
00:44:34,672 --> 00:44:37,306
37303762
All right? But I'm actually not gonna do that.
3763+
是吧?但我不会这样做
37313764

37323765
834
37333766
00:44:37,375 --> 00:44:40,843
37343767
I'm gonna do something else because I need to look up this
3768+
我会选择用另一种方法,因为我要用
37353769

37363770
835
37373771
00:44:40,911 --> 00:44:45,147
37383772
button's index in this card thing so I'm gonna do my for
3773+
按钮的索引找到这个 card 里对应的卡片,因此
37393774

37403775
836
37413776
00:44:45,215 --> 00:44:50,018
37423777
loop by index. In the card buttons array which I could do
3778+
我选择循环索引。要遍历 cardButtons 数组,那我可以
37433779

37443780
837
37453781
00:44:50,087 --> 00:44:54,757
37463782
with 0 dot dot less than cardButtons.count, okay.
3783+
用 0..<cardButtons.count
37473784

37483785
838
37493786
00: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

37523790
839
37533791
00:44:57,929 --> 00:45:00,830
37543792
I'm not gonna do that either I'm gonna show you another
3793+
但是我也不会这么做。我要给你展示另一种方法
37553794

37563795
840
37573796
00:45:00,899 --> 00:45:05,501
37583797
way, cardButtons.indicies, okay. cardButton.indicies
3798+
用 cardButtons.indices,cardButtons 的索引
37593799

37603800
841
37613801
00:45:05,570 --> 00:45:09,839
37623802
Indices is a method in array. Okay, that returs
3803+
indicies 是数组的一个方法(注:变量)
37633804

37643805
842
37653806
00:45:09,907 --> 00:45:13,509
37663807
you a countable range of all the indexes into the array.
3808+
给你一个由数组所有索引组成的可数的区间
37673809

37683810
843
37693811
00: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
51885230
1198
51895231
01:04:41,077 --> 01:04:43,311
51905232
only face up card.
5233+
仅有的那张朝上的卡
51915234

51925235
1199
51935236
01:04:43,379 --> 01:04:45,714

0 commit comments

Comments
 (0)