136 lines
No EOL
3.2 KiB
Haskell
136 lines
No EOL
3.2 KiB
Haskell
module RPGEngine.Data where
|
|
|
|
-------------------------------- Game --------------------------------
|
|
|
|
-- TODO Add more
|
|
data Game = Game {
|
|
-- Current state of the game
|
|
state :: State,
|
|
playing :: Level,
|
|
levels :: [Level]
|
|
}
|
|
|
|
------------------------------- Level --------------------------------
|
|
|
|
data Level = Level {
|
|
layout :: Layout,
|
|
items :: [Item],
|
|
entities :: [Entity]
|
|
} deriving (Eq, Show)
|
|
|
|
type Layout = [Strip]
|
|
type Strip = [Physical]
|
|
|
|
data Physical = Void
|
|
| Walkable
|
|
| Blocked
|
|
| Entrance
|
|
| Exit
|
|
deriving (Eq, Show)
|
|
|
|
------------------------------- Player -------------------------------
|
|
|
|
data Player = Player {
|
|
playerHp :: Maybe Int,
|
|
inventory :: [Item]
|
|
} deriving (Eq, Show)
|
|
|
|
instance Living Player where
|
|
hp = playerHp
|
|
|
|
------------------------------- State --------------------------------
|
|
|
|
-- Current state of the game.
|
|
data State = Menu
|
|
| Playing
|
|
| Pause
|
|
| Win
|
|
| Lose
|
|
|
|
------------------------------- Object -------------------------------
|
|
|
|
class Object a where
|
|
id :: a -> String
|
|
x :: a -> Int
|
|
y :: a -> Int
|
|
name :: a -> String
|
|
description :: a -> String
|
|
actions :: a -> [([Condition], Action)]
|
|
value :: a -> Maybe Int
|
|
|
|
class Living a where
|
|
hp :: a -> Maybe Int
|
|
|
|
data Item = Item {
|
|
itemId :: ItemId,
|
|
itemX :: Int,
|
|
itemY :: Int,
|
|
itemName :: String,
|
|
itemDescription :: String,
|
|
itemActions :: [([Condition], Action)],
|
|
itemValue :: Maybe Int,
|
|
useTimes :: Maybe Int
|
|
} deriving (Eq, Show)
|
|
|
|
instance Object Item where
|
|
id = itemId
|
|
x = itemX
|
|
y = itemY
|
|
name = itemName
|
|
description = itemDescription
|
|
actions = itemActions
|
|
value = itemValue
|
|
|
|
data Entity = Entity {
|
|
entityId :: EntityId,
|
|
entityX :: Int,
|
|
entityY :: Int,
|
|
entityName :: String,
|
|
entityDescription :: String,
|
|
entityActions :: [([Condition], Action)],
|
|
entityValue :: Maybe Int,
|
|
entityHp :: Maybe Int,
|
|
direction :: Direction
|
|
} deriving (Eq, Show)
|
|
|
|
instance Object Entity where
|
|
id = entityId
|
|
x = entityX
|
|
y = entityY
|
|
name = entityName
|
|
description = entityDescription
|
|
actions = entityActions
|
|
value = entityValue
|
|
|
|
instance Living Entity where
|
|
hp = entityHp
|
|
|
|
type EntityId = String
|
|
type ItemId = String
|
|
|
|
------------------------------ Condition -----------------------------
|
|
|
|
data Condition = InventoryFull
|
|
| InventoryContains ItemId
|
|
| Not Condition
|
|
| AlwaysFalse
|
|
deriving (Show, Eq)
|
|
|
|
------------------------------- Action -------------------------------
|
|
|
|
data Action = Leave
|
|
| RetrieveItem ItemId
|
|
| UseItem ItemId
|
|
| DecreaseHp EntityId ItemId
|
|
| IncreasePlayerHp ItemId
|
|
| Nothing
|
|
deriving (Show, Eq)
|
|
|
|
------------------------------ Direction -----------------------------
|
|
|
|
data Direction = North
|
|
| East
|
|
| South
|
|
| West
|
|
| Center -- Equal to 'stay where you are'
|
|
deriving (Show, Eq) |