0
所以我有这个精灵套件游戏,这是在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
}
我不知道switch语句有别的。谢谢 – jacobsan420
switch语句没有,'if'语句在_inside_ case中可以有'else'。别客气! – Gliderman