如果按下按钮,我会有一系列图像,图像会随机出现。并且还有一个从阵列调用的图像,但它只是在我打开游戏后随机出现。我想为按下按钮做一个条件声明。就像按下按钮时我有5个条件:1-如果按下并且图像出现与UIIMage视图不同,则会添加分数 2-如果按钮未按下2秒钟将显示下来。 3-如果按下按钮,它与UIimage相同,所以游戏结束。 4-如果他计算了4张图像,因为他没有在2秒内拍摄图像,他就会失败。
var array:[UIImage] = [UIImage(named: "1.png")!,
UIImage(named: "2.png")!,
UIImage(named: "3.png")!,
UIImage(named: "4.png")!,
UIImage(named: "5.png")!,
UIImage(named: "6.png")!,
UIImage(named: "7.png")!,
UIImage(named: "8.png")!,
UIImage(named: "9.png")!,
UIImage(named: "10.png")!]
var random = arc4random_uniform(10)
@IBAction func myButtonPressed(button: UIButton) {
var randomNum: UInt32 = 10
randomNum = arc4random_uniform(UInt32(array.count))
myButton.setImage(UIImage(named: "bird\(randomNum).png"), for: UIControlState.normal)
// myButton.setImage(UIImage(named: "\(randomNum).png"), for: UI)
self.myImage.animationImages = array
let buttonWidth = myButton.frame.width
let buttonHeight = myButton.frame.height
// Find the width and height of the enclosing view
let viewWidth = myButton.superview!.bounds.width
let viewHeight = myButton.superview!.bounds.height
// Compute width and height of the area to contain the button's center
let xwidth = viewWidth - buttonWidth
let yheight = viewHeight - buttonHeight
// Generate a random x and y offset
let xoffset = CGFloat(arc4random_uniform(UInt32(xwidth)))
let yoffset = CGFloat(arc4random_uniform(UInt32(yheight)))
// Offset the button's center by the random offsets.
myButton.center.x = xoffset + buttonWidth / 2
myButton.center.y = yoffset + buttonHeight / 2
/* for i in array{
if myButton != myImage{
randomNum = arc4random_uniform(UInt32(array.count))
}
if else
} */
}
答案 0 :(得分:0)
也许你可以尝试这样的事情。至于你的第一个条件,你的UIImage视图变量是什么。它是故事板上显示的另一个UIImage视图吗?
cancel()
我不太确定你的第四个条件是什么。请澄清