| | |
| | | |
| | | import UIKit |
| | | |
| | | struct Game_2_SelectModel:Hashable{ |
| | | var indexPath:IndexPath! |
| | | var model:Listen1SubModel! |
| | | } |
| | | |
| | | class HomeListenGame_2_VC: BaseVC { |
| | | |
| | | private var viewModel = FightAnswerViewModel() |
| | | |
| | | var rootViewModel:HomeListenFightViewModel! |
| | | private var listen1Model:Listen1Model! |
| | | private var selectModels = [Game_2_SelectModel]() |
| | | |
| | | private lazy var label_time:UILabel = { |
| | | let label = UILabel() |
| | |
| | | |
| | | private lazy var collectionView:UICollectionView = { |
| | | let flowLayout = UICollectionViewFlowLayout() |
| | | let w = (JQ_ScreenW - 40 * 2 - 30) / 4.0 |
| | | let w = (JQ_ScreenW - 40 * 2 - 50) / 5.0 |
| | | flowLayout.itemSize = CGSize(width: w, height: w * 0.675) |
| | | |
| | | flowLayout.minimumInteritemSpacing = 10 |
| | |
| | | |
| | | private var timer:Timer? |
| | | private var times:Int = 600 |
| | | |
| | | required init(listen1Model:Listen1Model){ |
| | | super.init(nibName: nil, bundle: nil) |
| | | self.listen1Model = listen1Model |
| | | self.listen1Model.subjectList.shuffle() |
| | | } |
| | | |
| | | required init?(coder: NSCoder) { |
| | | fatalError("init(coder:) has not been implemented") |
| | | } |
| | | |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | |
| | | make.centerY.equalTo(label_surplusTitle) |
| | | make.height.equalTo(44) |
| | | } |
| | | |
| | | |
| | | collectionView.delegate = self |
| | | collectionView.dataSource = self |
| | |
| | | |
| | | extension HomeListenGame_2_VC:UICollectionViewDelegate{ |
| | | func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { |
| | | viewModel.selectIndex.accept(indexPath) |
| | | _ = self.collectionView.dequeueReusableCell(withReuseIdentifier: "_ListenFight_Game_Pocket_CCell", for: indexPath) as! ListenFight_Game_Pocket_CCell |
| | | |
| | | |
| | | if selectModels.last?.indexPath == indexPath{ |
| | | print("重复点击");return |
| | | } |
| | | |
| | | let model = listen1Model.subjectList[indexPath.row] |
| | | |
| | | if selectModels.count >= 2{ |
| | | selectModels.removeFirst() |
| | | } |
| | | |
| | | selectModels.append(Game_2_SelectModel(indexPath: indexPath, model: model)) |
| | | |
| | | print(selectModels.map({"\($0.indexPath.row)"}).joined(separator: "——")) |
| | | |
| | | if selectModels.count == 1{ |
| | | let cell = self.collectionView.cellForItem(at: indexPath) as! ListenFight_Game_Pocket_CCell |
| | | cell.toFromAction() |
| | | } |
| | | |
| | | if selectModels.count == 2{ |
| | | let cell = self.collectionView.cellForItem(at: indexPath) as! ListenFight_Game_Pocket_CCell |
| | | cell.toFromAction() |
| | | |
| | | let firstM = selectModels.first |
| | | let lastM = selectModels.last |
| | | |
| | | if firstM != nil && lastM != nil{ |
| | | if firstM!.model.id == lastM!.model.id{ |
| | | firstM!.model.isOpen = true |
| | | lastM?.model.isOpen = true |
| | | selectModels.removeAll() |
| | | print("相同") |
| | | }else{ |
| | | print("不相同") |
| | | let firstIndex = firstM!.indexPath |
| | | let secondIndex = lastM!.indexPath |
| | | |
| | | let firstIndexCell = self.collectionView.cellForItem(at: firstIndex!) as! ListenFight_Game_Pocket_CCell |
| | | let secondIndexCell = self.collectionView.cellForItem(at: secondIndex!) as! ListenFight_Game_Pocket_CCell |
| | | |
| | | DispatchQueue.main.asyncAfter(deadline: .now()+0.5){ |
| | | firstIndexCell.toBackAction() |
| | | secondIndexCell.toBackAction() |
| | | self.selectModels.removeAll() |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | extension HomeListenGame_2_VC:UICollectionViewDataSource{ |
| | | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { |
| | | let model = listen1Model.subjectList[indexPath.row] |
| | | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_ListenFight_Game_Pocket_CCell", for: indexPath) as! ListenFight_Game_Pocket_CCell |
| | | |
| | | cell.setModel(model) |
| | | cell.voice_view.isHidden = !model.correct.isEmpty |
| | | return cell |
| | | } |
| | | |
| | | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { |
| | | return 12 |
| | | return listen1Model.subjectList.count |
| | | } |
| | | } |
| | | |