Created
July 4, 2016 21:17
-
-
Save vgaltes/e3d52f6638d5250e28f513405e6b0448 to your computer and use it in GitHub Desktop.
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
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