Fix dependency loop
This commit is contained in:
parent
b7278d6afc
commit
f529fc5237
25 changed files with 251 additions and 199 deletions
|
@ -1,5 +1,7 @@
|
|||
module RPGEngine.Data.Game
|
||||
( isLegalMove
|
||||
, isPlayerAtExit
|
||||
, isPlayerDead
|
||||
) where
|
||||
|
||||
import RPGEngine.Data
|
||||
|
@ -14,9 +16,21 @@ import RPGEngine.Data.Level (findAt, directionOffsets)
|
|||
|
||||
-- Check if a move is legal by checking what is located at the new position.
|
||||
isLegalMove :: Direction -> Game -> Bool
|
||||
isLegalMove dir g@Game{ state = Playing { level = lvl, player = p@Player{ position = (x, y) }}} = legality
|
||||
isLegalMove dir g@Game{ state = Playing{ level = lvl, player = p@Player{ position = (x, y) }}} = legality
|
||||
where legality = physical `elem` [Walkable, Entrance, Exit]
|
||||
physical = findAt newPos lvl
|
||||
newPos = (x + xD, y + yD)
|
||||
(xD, yD) = directionOffsets dir
|
||||
isLegalMove _ _ = False
|
||||
isLegalMove _ _ = False
|
||||
|
||||
-- Check if a player is standing on an exit
|
||||
isPlayerAtExit :: Game -> Bool
|
||||
isPlayerAtExit g@Game{ state = Playing{ player = player, level = level }} = atExit
|
||||
where playerPos = position player
|
||||
atPos = findAt playerPos level
|
||||
atExit = atPos == Exit
|
||||
isPlayerAtExit _ = False
|
||||
|
||||
-- Check if the players health is <= 0, which means the player is dead.
|
||||
isPlayerDead :: Game -> Bool
|
||||
isPlayerDead _ = False
|
Reference in a new issue