Setup
This commit is contained in:
parent
0720f3b719
commit
d4fbcda73b
13 changed files with 412 additions and 169 deletions
136
lib/RPGEngine/Data.hs
Normal file
136
lib/RPGEngine/Data.hs
Normal file
|
@ -0,0 +1,136 @@
|
|||
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]
|
||||
}
|
||||
|
||||
type Layout = [Strip]
|
||||
type Strip = [Physical]
|
||||
|
||||
data Physical = Void
|
||||
| Walkable
|
||||
| Blocked
|
||||
| Entrance
|
||||
| Exit
|
||||
deriving (Show, Eq)
|
||||
|
||||
------------------------------- Player -------------------------------
|
||||
|
||||
data Player = Player {
|
||||
playerHp :: Maybe Int,
|
||||
inventory :: [Item]
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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 :: Maybe Direction
|
||||
}
|
||||
|
||||
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)
|
Reference in a new issue