Created
May 31, 2012 23:38
-
-
Save darkf/2847214 to your computer and use it in GitHub Desktop.
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
type actor = {mutable hp : int; name : string} | |
type battle = {enemy : actor; mutable turn : int} | |
type attack = Slash of int | |
let player = {hp=100; name="Player"} | |
let runAttack by who atk = | |
match atk with | |
| Slash dmg -> printfn "%s slashes %s for %d" by.name who.name dmg; who.hp <- who.hp - dmg | |
let runTurn b = | |
printfn "Turn %d" b.turn | |
if b.turn % 2 = 1 then | |
// player's turn | |
runAttack player b.enemy <| Slash 10 | |
else | |
// enemy's turn | |
runAttack b.enemy player <| Slash 5 | |
b.turn <- b.turn + 1 | |
printfn "Status: Player HP: %d | Enemy HP: %d" player.hp b.enemy.hp | |
let main = | |
let b = {enemy={hp=100; name="Bob Dylan"}; turn=1} | |
for i = 0 to 5 do | |
runTurn b | |
System.Console.ReadKey true |> ignore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment