about summary refs log tree commit diff
path: root/src/Xanthous/Entities/Character.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Xanthous/Entities/Character.hs')
-rw-r--r--src/Xanthous/Entities/Character.hs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Xanthous/Entities/Character.hs b/src/Xanthous/Entities/Character.hs
index 1c7d1bbe82a6..0bb5867ee5e1 100644
--- a/src/Xanthous/Entities/Character.hs
+++ b/src/Xanthous/Entities/Character.hs
@@ -4,8 +4,10 @@ module Xanthous.Entities.Character
   , characterName
   , inventory
   , characterDamage
+  , characterHitpoints
   , mkCharacter
   , pickUpItem
+  , isDead
   ) where
 --------------------------------------------------------------------------------
 import Xanthous.Prelude
@@ -24,6 +26,7 @@ data Character = Character
   { _inventory :: !(Vector Item)
   , _characterName :: !(Maybe Text)
   , _characterDamage :: !Word
+  , _characterHitpoints :: !Word
   }
   deriving stock (Show, Eq, Generic)
   deriving anyclass (CoArbitrary, Function)
@@ -51,13 +54,20 @@ instance Entity Character where
 instance Arbitrary Character where
   arbitrary = genericArbitrary
 
+initialHitpoints :: Word
+initialHitpoints = 10
+
 mkCharacter :: Character
 mkCharacter = Character
   { _inventory = mempty
   , _characterName = Nothing
   , _characterDamage = 1
+  , _characterHitpoints = initialHitpoints
   }
 
+isDead :: Character -> Bool
+isDead = (== 0) . view characterHitpoints
+
 pickUpItem :: Item -> Character -> Character
 pickUpItem item = inventory %~ (item <|)