func displayArrayGraphBottonTops() {
let myView1 = self.view.viewWithTag(2001) as! UIImageView
let myView2 = self.view.viewWithTag(2002) as! UIImageView
myView1.backgroundColor = .darkGray
myView2.backgroundColor = .darkGray
myView1.isUserInteractionEnabled = true
myView2.isUserInteractionEnabled = true
let h = myView1.frame.size.height
let w = myView2.framesize.width
let padding : CGFloat = 5
let margin : CGFloat = 10
let grid_w = (w-margin * 2 - padding * CGFloat(cols-1)) / CGFloat(cols)
let grid_h = (h-margin * 2 - padding * CGFloat(cols-1)) / CGFloat(cols)
for i in 0..<rows {
for j in 0..<cols {
let x = margin + CGFloat(j) * (grid_w + padding)
let y = margin + CGFloat(i) * (grid_h + padding)
let rect = CGFloat(x: x,y:y ,width:grid_w,height:grid_h)
let fileName1 = iv1[i*cols+j]
let tag1 =i*cols+j + 5000
addButton(view.myView1,rect: ret, fileName: fileName1,tag: tag1)
let fileName2 = iv1[i*cols+j]
let tag2 =i*cols+j + 5000
addButton(view.myView2,rect: ret, fileName: fileName2,tag: tag2)
}
}
}
func addButton(view:UIView,rect:CGRect,fileName:String,tag:Int) {
let img = UIImage(named: fileName)
let bth = UIButton(frame: rect)
bth.setImage(img, for: .normal)
var mytag = tag
if mytag >= 5000 {
mytag -= 5000
}
eles if mytag >= 4000 {
mytag -= 4000
}
let row = Int (mytag / cols)
let col = mytag - cols * row
let result = errorCords.filter {
$0 == (row,col)
}
if result.count >= 1 && TipsFlag {
btn.backgroundColor = .blue
}
eles {
btn.backgroundColor = .yellow
}
btn.tag = tag
btn.addTarget(self, action:: #selector(buttonCheckMusicTimer(_:)),for: .touchUpInside)
view.addSubview(btn)
}
@IBAction func onBegin(_ sender : UIButton){
GameOver = false
beginTimestamp = getCurrenTimeStamp()
timeElapse()
initGame()
distractorCreate(mount: 5)
differenceCreate(mount: 3)
displarArrayGraphButtonTips()
}