Setup
This commit is contained in:
parent
0720f3b719
commit
d4fbcda73b
13 changed files with 412 additions and 169 deletions
|
@ -5,7 +5,7 @@ module RPGEngine.Data.Game
|
|||
,initGame
|
||||
) where
|
||||
|
||||
import RPGEngine.Data.Types
|
||||
import RPGEngine.Data
|
||||
import RPGEngine.Data.State
|
||||
|
||||
----------------------------------------------------------------------
|
||||
|
@ -13,5 +13,13 @@ import RPGEngine.Data.State
|
|||
-- Initialize the game
|
||||
initGame :: Game
|
||||
initGame = Game {
|
||||
state = defaultState
|
||||
state = defaultState,
|
||||
playing = head levels,
|
||||
levels = levels
|
||||
}
|
||||
where levels = [emptyLevel]
|
||||
emptyLevel = Level {
|
||||
layout = [],
|
||||
items = [],
|
||||
entities = []
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ module RPGEngine.Data.State
|
|||
, nextState
|
||||
) where
|
||||
|
||||
import RPGEngine.Data.Types
|
||||
import RPGEngine.Data
|
||||
|
||||
----------------------------- Constants ------------------------------
|
||||
|
||||
|
|
|
@ -1,115 +0,0 @@
|
|||
module RPGEngine.Data.Types where
|
||||
|
||||
-------------------------------- Game --------------------------------
|
||||
|
||||
-- TODO Add more
|
||||
data Game = Game {
|
||||
-- Current state of the game
|
||||
state :: State
|
||||
}
|
||||
|
||||
------------------------------- 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
|
||||
deriving (Show)
|
Reference in a new issue