所以我有这个精灵套装游戏,用swift 2编码。游戏包括从屏幕上掉下来的这些彩色圆圈(绿色,红色,紫色,黄色,蓝色),从相同的高度开始,但从不同的宽度。在屏幕的底部有一个栏,告诉你什么颜色不要按。因此,如果条形图为黄色,并且您单击黄色圆圈,则会丢失。我已经失去了实施,但我似乎无法弄清楚如何检测点击的圆圈是否不是条形图上的颜色。这是我的颜色检测代码。请记住,变量" colorNeeded"是您不想点击的颜色
switch colorNeeded {
case SKColor.redColor():
if Red.containsPoint(location) {
print("Color Needed is Blue, Blue Circle Clicked")
print("Lose, score is: \(score)")
changeColorNeeded()
}
break
case SKColor.blueColor():
if Blue.containsPoint(location) {
print("Color Needed is Blue, Blue Circle Clicked")
print("Lose, score is: \(score)")
changeColorNeeded()
}
break
case SKColor.yellowColor():
if Yellow.containsPoint(location) {
print("Color Needed is Blue, Blue Circle Clicked")
print("Lose, score is: \(score)")
changeColorNeeded()
}
break
case SKColor.greenColor():
if Green.containsPoint(location) {
print("Color Needed is Blue, Blue Circle Clicked")
print("Lose, score is: \(score)")
changeColorNeeded()
}
break
case SKColor.purpleColor():
if Purple.containsPoint(location) {
print("Color Needed is Blue, Blue Circle Clicked")
print("Lose, score is: \(score)")
changeColorNeeded()
}
break
default:
if Purple.containsPoint(location) || Green.containsPoint(location) || Yellow.containsPoint(location) || Blue.containsPoint(location) || Red.containsPoint(location){
score++
("Good Color Clicked")
ChangeCounter++
if ChangeCounter == 5 {
changeColorNeeded()
}
}
break
}
答案 0 :(得分:0)
我会在else
语句中添加if
,这些语句会设置一个标志,指示您没有单击错误的颜色,或者调用具有{{1}中代码的方法} default
声明。像这样:
在证明为正面之前,这是错误的:
if
等。对于交换机中的每个var isSafeClick = false
case SKColor.redColor():
if Red.containsPoint(location) {
print("Color Needed is Blue, Blue Circle Clicked")
print("Lose, score is: \(score)")
changeColorNeeded()
} else {
isSafeClick = true
}
break
语句。在if
语句的末尾,添加另一个switch
以查看if
是否为isSafeClick
:
true
对于方法方法,只需将代码直接放在此文本的上方(名称类似" safeScorePoint"或其他),并在每个if (isSafeClick) {
score++
("Good Color Clicked")
ChangeCounter++
if ChangeCounter == 5{
changeColorNeeded()
}
}
的{{1}}中叫那个方法。