This repository has been archived on 2023-06-24. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
2022FuncProg-project3-RPGEn.../lib/RPGEngine/Data.hs

141 lines
No EOL
3.3 KiB
Haskell

module RPGEngine.Data where
-------------------------------- Game --------------------------------
-- TODO Add more
data Game = Game {
-- Current state of the game
state :: State,
playing :: Level,
levels :: [Level],
player :: Player
}
------------------------------- 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 -------------------------------
type X = Int
type Y = Int
data Player = Player {
playerHp :: Maybe Int,
inventory :: [Item],
coord :: (X, Y)
} 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)