我正在制作一个真假游戏,我们必须确定逻辑表达式是真还是假。这是一个单击游戏。如果我们单击,则当前的 true 条件变为 false,反之亦然。一系列逻辑表达式会从屏幕上弹出,当它到达区域时,当前条件必须等于逻辑表达式才能获得分数。为了验证真值,它检查真值的图像。我试过一个案例,它是“真实的和真实的”并且当前条件是真实的,这是真实的。但是,当它穿过该区域时,分数并没有增加。我哪里出错了?
@IBAction func button_clicked(sender: UIButton) {
if (truth_click == true) {
truth_click = false
self.truth_button.image = UIImage(named: "false_button")
}
else if (truth_click == false) {
truth_click = true
self.truth_button.image = UIImage(named: "true_button")
}
}
func check_truth() {
if (truth_click == true) {
//when it reaches the zone
if (left_truth.center.y > 330 ) {
//if true and true
if ((left_truth.image == UIImage(named: "true")) && (symbol.image == UIImage(named: "and")) && (right_truth.image == UIImage(named: "true"))) {
self.score += 1
}
//if true and false
//if false and true
//if false and false
self.score_label.text = String(self.score)
}
}
if (truth_click == false) {
//when it reaches the zone
if (left_truth.center.y > 330 ) {
//if true and false
if ((left_truth.image == UIImage(named: "true")) && (symbol.image == UIImage(named: "and")) && (right_truth.image == UIImage(named: "false"))) {
self.score += 1
}
//if true and true
//if false and true
//if false and false
self.score_label.text = String(self.score)
}
}
}
最佳答案
部分问题是针对 UIImage(named:...)
的新实例测试 *_truth.image
。 UIImage 是一个对象。实例化一个新的 UIImage 创建一个新对象。具有相同内容的两个对象不相等......没有额外的工作。
关于ios - Swift:当对象在一个区域内时运行代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35546246/