Skip to content

Instantly share code, notes, and snippets.

@olegknyazev
Last active October 28, 2018 14:37
Show Gist options
  • Save olegknyazev/e28aae134cf100bfe0609490752c9c66 to your computer and use it in GitHub Desktop.
Save olegknyazev/e28aae134cf100bfe0609490752c9c66 to your computer and use it in GitHub Desktop.
About Formatting: Concise and dense code
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