Reputation: 11
I was trying to convert a java class into a scala one but I found problem with
break
statement into a match case
structure.
Can anyone help me to do it in the right way?
Here is the code:
override def keyPressed(event: KeyEvent): Unit = if (Main.getScene.getMario isAlive) event getKeyCode match {
case KeyEvent.VK_RIGHT =>
if (Main.getScene.getxPos == -1) this setBackgroundPosition(0, this FIRST_BACKGROUND_POSITION, this SECOND_BACKGROUND_POSITION)
this.setMovement(true, true, this MOVEMENT)
//break
case KeyEvent.VK_LEFT =>
if (Main.getScene.getxPos == 4601) this setBackgroundPosition(4600, this FIRST_BACKGROUND_POSITION, this SECOND_BACKGROUND_POSITION)
this setMovement(true, false, -MOVEMENT)
//break
case KeyEvent.VK_UP =>
Main.getScene.getMario.setJumping(true)
Audio playSound (JUMP_SOUND + Res.AUDIO_EXT)
//break
case KeyEvent.VK_R =>
Main.main(Array())
//break
}
As you can see,i would like to put a break statement after each case. Thank you in advance.
Upvotes: 1
Views: 974
Reputation: 3120
Scala's match
will behave just the way you want here (it'll only match one case). You don't need a break
after each case.
Upvotes: 5