2021-02-11 22:40:00 +00:00
|
|
|
module Dungeon where
|
|
|
|
|
|
|
|
import Data.Matrix
|
2021-02-14 13:32:24 +00:00
|
|
|
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
|
|
|
|
|
2021-02-14 13:32:24 +00:00
|
|
|
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
|