fix
无故事王国
2024-06-19 ee4954eb4dc84e0a6c0a784da717f9cc648b106b
DolphinEnglishLearnStudent/Moudle/Home/Listen/VC/HomeListenGame_2_VC.swift
@@ -43,6 +43,7 @@
                        let collection = UICollectionView(frame: .zero, collectionViewLayout: flowLayout)
                        collection.contentInset = UIEdgeInsets(top: 101, left: 40, bottom: 0, right: 40)
                        collection.register(ListenFight_Game_Pocket_CCell.self, forCellWithReuseIdentifier: "_ListenFight_Game_Pocket_CCell")
                        collection.isScrollEnabled = false
                        return collection
            }()
@@ -148,38 +149,60 @@
                        }
            }
            //判断检查两个Cell情况
            private func checking(){
            private func nextQuesAction(){
                        guard selectModels.count == 2 else {return}
            }
                        let firstM = selectModels.first
                        let lastM = selectModels.last
            private func answerQuestion(){
                        view.layoutIfNeeded()
                        var answerType:Fight_lessonType = .none
                        answerType = .success
                        switch answerType {
                                    case .success:
                                                voicePlayer.playSuccessVoice()
                        if firstM != nil && lastM != nil{
                                    if firstM!.model.id == lastM!.model.id{
                                                firstM!.model.isOpen = true
                                                lastM?.model.isOpen = true
                                                selectModels.removeAll()
                                                print("相同")
                                                viewModel.answerType.accept(.success)
                                                collectionView.reloadData()
                                    case .fail:
                                                voicePlayer.playFailVoice()
                                                rootViewModel.correctNum += 1
                                                voicePlayer.playSuccessVoice()
                                                self.selectModels.removeAll()
                                    }else{
                                                print("不相同")
                                                viewModel.answerType.accept(.fail)
                                                collectionView.reloadData()
                                                DispatchQueue.main.asyncAfter(wallDeadline: .now()+2.5) {
                                                            self.viewModel.answerType.accept(.none)
                                                            self.collectionView.reloadData()
                                                rootViewModel.errorNum += 1
                                                let firstIndex = firstM!.indexPath
                                                let secondIndex = lastM!.indexPath
                                                voicePlayer.playFailVoice()
                                                let firstIndexCell = self.collectionView.cellForItem(at: firstIndex!) as! ListenFight_Game_Pocket_CCell
                                                let secondIndexCell = self.collectionView.cellForItem(at: secondIndex!) as! ListenFight_Game_Pocket_CCell
                                                self.view.isUserInteractionEnabled = false
                                                DispatchQueue.main.asyncAfter(deadline: .now()+3.0){
                                                            firstIndexCell.toBackAction(self.view)
                                                            secondIndexCell.toBackAction(self.view)
                                                            self.selectModels.removeAll()
                                                }
                                    case .none:
                                                break
                                    }
                        }
                        let surplusListCount = datas.filter({$0.isOpen == false}).count
                        if surplusListCount == 0{
                                    NotificationCenter.default.post(name: NextLession_Noti, object: ["gameId":listen1Model.data!.id,"gameIntegral":listen1Model.data!.integral])
                                    rootViewModel.answerItems[0] = self.listen1Model
                                    timer?.invalidate()
                        }
                        print("剩余:\(surplusListCount)")
            }
}
extension HomeListenGame_2_VC:UICollectionViewDelegate{
            func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
                        if voicePlayer.isPlaying{
                                    print("正在播放语音");return
                        }
                        if datas[indexPath.row].isOpen{
                                    print("已经展开过了");return
@@ -201,48 +224,26 @@
                        if selectModels.count == 1{
                                    let cell = self.collectionView.cellForItem(at: indexPath) as! ListenFight_Game_Pocket_CCell
                                    cell.toFromAction()
                                    cell.toFromAction(self.view)
                                    if model.type == 2{
                                                //播放
                                                cell.cellPlaying()
                                                voicePlayer.playerAt(url: model.voice)
                                    }
                        }
                        if selectModels.count == 2{
                                    let cell = self.collectionView.cellForItem(at: indexPath) as! ListenFight_Game_Pocket_CCell
                                    cell.toFromAction()
                                    cell.toFromAction(self.view)
                                    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("相同")
                                                            rootViewModel.correctNum += 1
                                                }else{
                                                            print("不相同")
                                                            rootViewModel.errorNum += 1
                                                            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()
                                                            }
                                                }
                                    if model.type == 2{
                                                //语音先播放,再评估
                                                cell.cellPlaying()
                                                voicePlayer.playerAt(url: model.voice)
                                                return
                                    }
                                    let surplusListCount = datas.filter({$0.isOpen == false}).count
                                    if surplusListCount == 0{
                                                NotificationCenter.default.post(name: NextLession_Noti, object: ["gameId":listen1Model.data!.id,"gameIntegral":listen1Model.data!.answerIntegral])
                                                rootViewModel.answerItems[0] = self.listen1Model
                                                timer?.invalidate()
                                    }
                                    print("剩余:\(surplusListCount)")
                                    checking()
                        }
            }
}
@@ -301,14 +302,17 @@
extension HomeListenGame_2_VC:VoicePlayerDelegate{
            func playComplete() {
                        view.isUserInteractionEnabled = true
                        //正在播放的语音Cell要归位
                        if let index = currentPayCellIndex{
                                    let cell = collectionView.cellForItem(at: index) as! ListenFight_Game_Pocket_CCell
                                    cell.cellResotePay()
                        }
                        checking()
            }
            func playing() {
                        view.isUserInteractionEnabled = false
            }
}