Skip to content

Instantly share code, notes, and snippets.

@vgaltes
Created July 4, 2016 21:17
Show Gist options
  • Save vgaltes/e3d52f6638d5250e28f513405e6b0448 to your computer and use it in GitHub Desktop.
Save vgaltes/e3d52f6638d5250e28f513405e6b0448 to your computer and use it in GitHub Desktop.
let applyDamage damage player =
match player with
| Thing t -> Player.Thing {t with Health = t.Health - damage}
| Character c -> Player.Character {c with Health = c.Health - damage}
let applyHeal healing player =
match player with
| Thing t -> Player.Thing {t with Health = t.Health + healing}
| Character c -> Player.Character {c with Health = c.Health + healing}
let rec applyRules value rules characterFrom playerTo distance =
match rules with
| [] -> value
| x::xs ->
let result = x characterFrom playerTo distance value
match result with
| None -> 0
| Some v -> applyRules v xs characterFrom playerTo distance
let interactWith characterFrom playerTo action distance =
match action with
| Attack amount ->
let damage = applyRules amount attackRules characterFrom playerTo distance
playerTo |> applyDamage damage
| Heal amount ->
let healing = applyRules amount healRules characterFrom playerTo distance
playerTo |> applyHeal healing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment