Last active
October 28, 2018 14:37
-
-
Save olegknyazev/e28aae134cf100bfe0609490752c9c66 to your computer and use it in GitHub Desktop.
About Formatting: Concise and dense code
This file contains hidden or 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
case class Attack(from: Int3, to: Int3) extends Action { | |
override def apply(gs: GameState): GameState = { | |
Check.state(possible(gs)) | |
gs mapWorld { world => | |
(world.at(from), world.at(to)) match { | |
case (turret @ Building(_, _, tag @ Turret(ammo)), target @ Building(_, _, _)) => | |
val damagedTarget = damage(target) | |
val worldAfterShot = | |
world. | |
replace(from, turret.copy(tag = tag.copy(ammo = ammo - 1))). | |
replace(to, damagedTarget) | |
if (damagedTarget == Empty) | |
Capture.repaintNeighboursIfDetached(worldAfterShot, to) | |
else | |
worldAfterShot | |
case _ => throw new IllegalStateException() | |
} | |
} | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment