在Scala中我有這樣的功能:我該如何重寫Scala中的另一個函數?
def handleCollision {
walls.foreach(w => if (curPlayer.intersects(w)) {
curPlayer.setLocation(playerStartPos._1, playerStartPos._2)
updateLives(-1)
})
obstacles.foreach(o => if (curPlayer.intersects(o)) {
curPlayer.setLocation(playerStartPos._1, playerStartPos._2)
updateLives(-1)
})
} // End "handleCollision"
當球員擊打鍵「C」在我的匹配語句我想要做的是:
case 'c' =>
我想它來調用這個函數並覆蓋上述功能,使其不再工作:
def cheatKey {
walls.foreach(w => if (curPlayer.intersects(w)) {
updateLives(+0)
})
obstacles.foreach(o => if (curPlayer.intersects(o)) {
updateLives(+0)
})
}
謝謝
所有答案都不錯,但是這一次是正是我需要的。謝謝! – Chris 2013-05-01 23:16:37