From 190c3a029f28084cfd4b53ea5f24492340861373 Mon Sep 17 00:00:00 2001 From: Ivy Date: Sun, 14 Feb 2021 23:14:57 +0100 Subject: [PATCH] Removed random in favor of future static maps --- roguelike.cabal | 3 +-- src/Dungeon.hs | 9 ++------- src/Game.hs | 5 ++--- src/Main.hs | 4 +--- src/Rendering.hs | 2 +- 5 files changed, 7 insertions(+), 16 deletions(-) diff --git a/roguelike.cabal b/roguelike.cabal index 142a3e1..018b758 100644 --- a/roguelike.cabal +++ b/roguelike.cabal @@ -29,5 +29,4 @@ executable roguelike matrix, unordered-containers, microlens-th, - microlens, - random + microlens diff --git a/src/Dungeon.hs b/src/Dungeon.hs index b333276..64e7a8a 100644 --- a/src/Dungeon.hs +++ b/src/Dungeon.hs @@ -1,7 +1,6 @@ module Dungeon where import Data.Matrix -import System.Random data Cell = Solid | Empty @@ -14,12 +13,8 @@ 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 - +makeDungeon :: Int -> Int -> Dungeon +makeDungeon w h = Dungeon $ matrix h w $ const Empty dungeonToLists :: Dungeon -> [[Cell]] dungeonToLists (Dungeon m) = toLists m diff --git a/src/Game.hs b/src/Game.hs index 9e6fc31..e54dac4 100644 --- a/src/Game.hs +++ b/src/Game.hs @@ -2,7 +2,6 @@ module Game where -import System.Random import Lens.Micro.TH import Lens.Micro @@ -18,8 +17,8 @@ data Game = Game makeLenses ''Game -newGame :: (RandomGen r) => r -> Game -newGame gen = Game (makeDungeon gen 30 10) (Player (0,0)) +newGame :: Game +newGame = Game (makeDungeon 30 10) (Player (0,0)) runAction :: Action -> Game -> Maybe Game runAction (Walk N) game = Just $ game & player . pos . _2 -~ 1 diff --git a/src/Main.hs b/src/Main.hs index ffd4676..f313fa8 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -1,7 +1,6 @@ module Main where import Graphics.Vty -import System.Random import Game import Rendering @@ -11,8 +10,7 @@ main :: IO () main = do cfg <- standardIOConfig vty <- mkVty cfg - gen <- getStdGen - loop vty $ newGame gen + loop vty newGame shutdown vty where loop vty game = do update vty $ renderGame game diff --git a/src/Rendering.hs b/src/Rendering.hs index 025dd7c..48e91f3 100644 --- a/src/Rendering.hs +++ b/src/Rendering.hs @@ -17,6 +17,6 @@ dungeonToImg :: Dungeon -> Image dungeonToImg = vertCat . map (string defAttr . concatMap show) . dungeonToLists playerToImg :: Player -> Image -playerToImg p = (translateX px . translateY py $ char defAttr '@') +playerToImg p = translateX px . translateY py $ char defAttr '@' where px = p ^. pos . _1 py = p ^. pos . _2