From 9b164e4f6522dcf395ded0ba71ff0f80b566a2f5 Mon Sep 17 00:00:00 2001 From: nek0 Date: Wed, 1 May 2024 18:04:47 +0200 Subject: [PATCH] tinker a little with Map generation and display --- src-lib/Library/Map.hs | 18 ++++++++++++++++++ src-lib/Library/Types/Map.hs | 6 +++++- src-server/Main.hs | 3 ++- src-server/Server/Map.hs | 13 ++++--------- wizard-wipeout.cabal | 3 ++- 5 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 src-lib/Library/Map.hs diff --git a/src-lib/Library/Map.hs b/src-lib/Library/Map.hs new file mode 100644 index 0000000..db1f8fb --- /dev/null +++ b/src-lib/Library/Map.hs @@ -0,0 +1,18 @@ +module Library.Map where + +import Data.Matrix + +import Library.Types + +prettyPrintMap + :: ServerMap + -> IO () +prettyPrintMap tilemap = do + mapM_ + (\row -> do + mapM_ + (putStr . show) + row + putStr "\n" + ) + (toLists tilemap) diff --git a/src-lib/Library/Types/Map.hs b/src-lib/Library/Types/Map.hs index 81fbc6c..d540521 100644 --- a/src-lib/Library/Types/Map.hs +++ b/src-lib/Library/Types/Map.hs @@ -31,7 +31,11 @@ instance FromJSON ClientMap data Tile = Air -- ^ walkable area | Wall -- ^ obstacle - deriving (Show, Eq, Generic) + deriving (Eq, Generic) + +instance Show Tile where + show Air = " " + show Wall = "█" instance ToJSON Tile diff --git a/src-server/Main.hs b/src-server/Main.hs index 88e08b8..6bf8956 100644 --- a/src-server/Main.hs +++ b/src-server/Main.hs @@ -22,6 +22,7 @@ import Options.Applicative -- internal imports +import Library.Map import Library.Types import Server.Communication @@ -48,7 +49,7 @@ main = do putStrLn "-----------------------------------------------------------------------------------" arena <- generateArena setMapRows setMapColumns setSpawnerProbability putStrLn "generated arena:" - print (arenaMap arena) + prettyPrintMap (arenaMap arena) putStrLn "-----------------------------------------------------------------------------------" putStrLn "starting game…" now <- getCurrentTime diff --git a/src-server/Server/Map.hs b/src-server/Server/Map.hs index ef6db61..cc88d1e 100644 --- a/src-server/Server/Map.hs +++ b/src-server/Server/Map.hs @@ -61,11 +61,11 @@ generateMap mapRows mapColumns = do where divide :: Int -> Int -> Int -> Int -> ServerMap -> IO ServerMap divide rowOffset colOffset rowSize colSize tilemap - | rowSize <= 3 || colSize <= 3 = pure tilemap + | rowSize <= 4 || colSize <= 4 = pure tilemap | otherwise = do -- position wall intersection at random - crossRow <- randomRIO (2, rowSize - 1) - crossCol <- randomRIO (2, colSize - 1) + crossRow <- randomRIO (2, rowSize - 2) + crossCol <- randomRIO (2, colSize - 2) -- position wall passages at random wall tiles rowHole1 <- randomRIO (1, crossRow - 1) @@ -74,18 +74,13 @@ generateMap mapRows mapColumns = do colHole2 <- randomRIO (crossCol + 1, colSize - 1) -- determine all possible passages - let allHoles = + let holes = [ (rowHole1, crossCol) , (rowHole2, crossCol) , (crossRow, colHole1) , (crossRow, colHole2) ] - -- drop one of the passages randomly - randomDropIndex <- randomRIO (0, length allHoles - 1) - let randomDrop = allHoles !! randomDropIndex - holes = filter (/= randomDrop) allHoles - crossedMap = M.mapPos (\(r, c) tile -> if (r - rowOffset == crossRow && c - colOffset > 0 && c - colOffset <= colSize) || diff --git a/wizard-wipeout.cabal b/wizard-wipeout.cabal index 79b27b1..0b67857 100644 --- a/wizard-wipeout.cabal +++ b/wizard-wipeout.cabal @@ -18,7 +18,8 @@ common warnings library import: warnings - exposed-modules: Library.Types + exposed-modules: Library.Map + Library.Types Library.Types.Communication Library.Types.Map Library.Types.Player