2021-02-13 00:06:26 +00:00
|
|
|
{-# LANGUAGE TemplateHaskell #-}
|
|
|
|
|
2021-02-11 22:40:00 +00:00
|
|
|
module Game where
|
|
|
|
|
2021-02-14 13:32:24 +00:00
|
|
|
import System.Random
|
2021-02-13 00:06:26 +00:00
|
|
|
import Lens.Micro.TH
|
|
|
|
import Lens.Micro
|
|
|
|
|
2021-02-11 22:40:00 +00:00
|
|
|
import Dungeon
|
|
|
|
import Player
|
|
|
|
import Direction
|
|
|
|
import Action
|
|
|
|
|
|
|
|
data Game = Game
|
2021-02-13 00:06:26 +00:00
|
|
|
{ _dungeon :: Dungeon
|
|
|
|
, _player :: Player
|
2021-02-11 22:40:00 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 00:06:26 +00:00
|
|
|
makeLenses ''Game
|
|
|
|
|
2021-02-14 13:32:24 +00:00
|
|
|
newGame :: (RandomGen r) => r -> Game
|
|
|
|
newGame gen = Game (makeDungeon gen 30 10) (Player (0,0))
|
2021-02-11 22:40:00 +00:00
|
|
|
|
|
|
|
runAction :: Action -> Game -> Maybe Game
|
2021-02-14 13:32:24 +00:00
|
|
|
runAction (Walk N) game = Just $ game & player . pos . _2 -~ 1
|
|
|
|
runAction (Walk S) game = Just $ game & player . pos . _2 +~ 1
|
|
|
|
runAction (Walk W) game = Just $ game & player . pos . _1 -~ 1
|
|
|
|
runAction (Walk E) game = Just $ game & player . pos . _1 +~ 1
|
|
|
|
runAction (Walk NW) game = Just $ game & player . pos . both -~ 1
|
|
|
|
runAction (Walk NE) game = Just $ game & player . pos %~ (\(x,y) -> (x+1, y-1))
|
|
|
|
runAction (Walk SW) game = Just $ game & player . pos %~ (\(x,y) -> (x-1, y+1))
|
|
|
|
runAction (Walk SE) game = Just $ game & player . pos . both +~ 1
|
2021-02-11 22:40:00 +00:00
|
|
|
runAction None g = Just g
|
|
|
|
runAction ExitGame _ = Nothing
|