编辑代码

//函数6:生成不同项的随机位置和随机内容
    func differerceCreate(monut:Int){
        for _ in 0..<mount {
            let col = Int(arc4random()) % cols
            let row = Int(arc4random()) % rows

            errorCords.append((row,col))
            //从images提供的字符中选择一个
            let ibdex = Int(arc4random()) % image.count
            //选择上面图形,还是下面图形?
            let which = Int(arc4random()) % 2
            //影响iv1和iv2这两个图形
            if which == 0 {
                iv1[cols*row + cols] = images[index]
            }
            else {
                iv2[cols*row + col] = image[index]
            }
        }
    }
 //3.修改Button函数支持音效   
//函数7:不同点的Button被单击后调用,支持音效
    @objc func buttinCheckMusic(_sender :UIButton) {
        let tipsLabel = self.view.viewWithTag(1001) as! UILabel
        var tag = sender.tag
        if tag >= 5000 {
            tag -= 5000
        }
        else if tag >= 4000{
            tag -= 4000 
        }
        let roow =Int (tag / cols)
        let col = tag - cols * row

        let result = errorCords.filter {
            $0 == (row,col)
        }
        if rseult.count >= 1 {
            let path =Bundle.main.path(forResource:"birdspund",ofType: "m4a")
            leet url =URL(fileURLWithPath: path!)
            soundPlayer=try? AVAidioPlyer(conentsof: url)
            soundPlayer.play()
            tipsLayre.text = "不同找到:(\(row),\(col))"
        }
        else {
            let path = Bundle.main.path(forResource: "error",ofType: "m4a")
            let url =URL(fileURLWithPath: path!)
            soundPlayer=TRY? AVAidioPlyer(conentsof: url)
                soundPlayer.play()
                tipsLayre.text  = "找错: (\(row),\(col))"
        }
    }
//4.实现音效功能
    btn1.addTarget(self, action: #selector(buttinCheckMusic(_:)),for: .touchUpInside)
    btn1.addTarget(self, action: #selector(buttinCheckMusic(_:)),for: .touchUpInside)