roguelike/src/Dungeon.hs

26 lines
704 B
Haskell
Raw Normal View History

2021-02-11 22:40:00 +00:00
module Dungeon where
import Data.Matrix
import System.Random
2021-02-11 22:40:00 +00:00
data Cell = Solid | Empty
instance Show Cell where
show Solid = "#"
show Empty = "."
newtype Dungeon = Dungeon (Matrix Cell)
instance Show Dungeon where
show (Dungeon m) = unlines . map (concatMap show) $ toLists m
makeDungeon :: (RandomGen r) => r -> Int -> Int -> Dungeon
makeDungeon gen w h = Dungeon $ Data.Matrix.fromList h w (randomCells gen)
where randomCells g = let (c,nGen) = randomR (0 :: Int,1 :: Int) g
in case c of 0 -> Solid : randomCells nGen
1 -> Empty : randomCells nGen
2021-02-11 22:40:00 +00:00
dungeonToLists :: Dungeon -> [[Cell]]
dungeonToLists (Dungeon m) = toLists m