Created
December 21, 2015 09:10
-
-
Save edvardm/b3b8b8b420be764e8144 to your computer and use it in GitHub Desktop.
game.hs
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
{-# LANGUAGE RecordWildCards #-} | |
import qualified Text.Show.Pretty as Pr | |
data Army = Army { name :: String | |
, units :: [Unit] | |
, solos :: [Solo] | |
, warlocks :: [Warlock] | |
, warbeasts :: [Warbeast] } | |
deriving (Eq, Show) | |
type Unit = (String, Int) | |
trolleUnits :: [Unit] | |
trolleUnits = [("Highwaymen", 8)] | |
type Solo = (String, Int) | |
trolleSolos :: [Solo] | |
trolleSolos = [("Braylen Wanderheart", 5), ("Trollkin Skinner", 2)] | |
type Warlock = String | |
trolleWarlocks :: [Warlock] | |
trolleWarlocks = ["Jarl Skuld", "Captain Gunnbjorn"] | |
type Warbeast = (String, Int) | |
trolleWarbeasts :: [Warbeast] | |
trolleWarbeasts = [("Dire Troll Bomber", 10)] | |
trolle :: Army | |
trolle = Army { name = "Trolle" | |
, units = trolleUnits | |
, solos = trolleSolos | |
, warlocks = trolleWarlocks | |
, warbeasts = trolleWarbeasts} | |
addUnit :: Unit -> Army -> Army | |
addUnit u army@Army{..} = army { units = u:units } | |
addWarlock :: Warlock -> Army -> Army | |
addWarlock w army@Army{..} = army { warlocks = w:warlocks } | |
main = do | |
putStrLn $ Pr.ppShow trolle | |
let newTrolle = addUnit ("Archers", 10) trolle | |
putStrLn $ Pr.ppShow newTrolle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment