Guest User

Untitled

a guest
Oct 20th, 2023
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. newtype Health    = Health Int deriving Num
  2. newtype Attack    = Attack Int deriving Num
  3. newtype Defense   = Defense Int deriving Num
  4.  
  5. data Fighter = MkFighter
  6.   { health  :: Health
  7.   , attack  :: Attack
  8.   , defense :: Defense
  9.   , actions :: [Action]
  10.   }
  11.  
  12. type Knight  = Fighter
  13. type Monster = Fighter
  14.  
  15. act x = x { actions = tail $ actions x }
  16.  
  17. duel :: Fighter -> Fighter -> Fighter
  18. duel x y = case head $ actions x of
  19.   AcAttack       xa -> duel (y { health = health y - (Health xa) }) (act y)
  20.   AcPotion       xa -> duel y (x { health = health x + (Health xa) })
  21.   AcDefenseSpell xa -> duel y (x { defense = defense x + (Defense xa) })
  22.   AcRunAway         -> y
  23.  
Advertisement
Add Comment
Please, Sign In to add comment