-
-
Save johansjoberg/1573064 to your computer and use it in GitHub Desktop.
option refactoring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def click(x: Int, y: Int) { | |
val mx = screen.calculateTileIndex(screen.sx+x) | |
val my = screen.calculateTileIndex(screen.sy+y) | |
val tile = map.tiles(mx,my) | |
performPossibleUnitAction(tile.unit, mx, my) | |
} | |
private def performPossibleUnitAction(tileUnit:Option[Unit], mx: Int, my: Int) { | |
(tileUnit, selectedUnit) match { | |
case (None, Some(unit)) => { | |
unit.moveTo(mx, my) | |
} | |
case (Some(newSelectedUnit), Some(oldSelectedUnit)) => { | |
newSelectedUnit.select() | |
oldSelectedUnit.unselect() | |
} | |
case (Some(unit), None) => { | |
selectedUnit = Option(unit) | |
unit.select() | |
} | |
case (None, None) => //do nothing | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment