ContentsIndex
AdventureGame
Contents
Types
Data
Functions
Description
A little text-based adventure in haskell This code has been written by JP Moresmau (jp_at_moresmau_dot_fr) This is no copyright at all on it, feel free to reuse
Synopsis
data DirectionInfo = DirectionInfo {
descDir :: Description
locationCode :: LocationCode
}
data LocationInfo = LocationInfo {
descLoc :: Description
directions :: DirectionMap
lookable :: LookableMap
takeable :: TakeableMap
}
data ItemInfo = ItemInfo {
itemCode :: ItemCode
itemDescription :: Description
}
data GameState = GameState {
location :: LocationCode
items :: ItemMap
changedLookableMap :: ChangedLookableMap
}
data TakeAction
= TakeActionOK {
takeDescription :: Description
changedLookable :: LookableMap
}
| TakeActionFail {
takeDescription :: Description
}
| TakeActionNeedItem {
neededItem :: ItemCode
failDescription :: Description
okDescription :: Description
changedLookable :: LookableMap
}
type LocationMap = Map LocationCode LocationInfo
type DirectionMap = Map DirectionCode DirectionInfo
type LookableMap = Map ItemCode Description
newtype ItemMap = ItemMap (Map ItemCode Description)
newtype ChangedLookableMap = ChangedLookableMap (Map LocationCode LookableMap)
type TakeableMap = Map ItemCode TakeAction
type LocationCode = String
type ItemCode = String
type Description = String
type DirectionCode = String
actions :: Map String (GameState -> [String] -> (GameState, [String]))
ioactions :: Map String (GameState -> [FilePath] -> IO (GameState, String))
start :: IO ()
getCommand :: GameState -> IO ()
locationDescription :: LocationCode -> String
locationDirections :: LocationCode -> [String]
move :: GameState -> [DirectionCode] -> (GameState, [String])
processMove :: GameState -> [DirectionCode] -> [String] -> (GameState, [String])
help :: GameState -> [String] -> (GameState, [String])
look :: GameState -> [ItemCode] -> (GameState, [String])
lookOne :: GameState -> [ItemCode] -> [String]
lookInState :: GameState -> ItemCode -> String
lookDefault :: GameState -> ItemCode -> String
carry :: GameState -> [ItemCode] -> (GameState, [String])
takeItem :: GameState -> [ItemCode] -> (GameState, [String])
processTakeAction :: GameState -> ItemCode -> TakeAction -> (GameState, [String])
trade :: GameState -> [ItemCode] -> (GameState, [String])
gameOver :: GameState -> Bool
save :: GameState -> [FilePath] -> IO (GameState, String)
load :: GameState -> [FilePath] -> IO (GameState, String)
showItemMap :: ItemMap -> ShowS
readItemMap :: ReadS ItemMap
showChangedLookableMap :: ChangedLookableMap -> ShowS
readChangedLookableMap :: ReadS ChangedLookableMap
Types
data DirectionInfo
information about an exit way from a location
Constructors
DirectionInfo
descDir :: Descriptionthe description of the exit
locationCode :: LocationCodethe code for the location where the exit goes to
show/hide Instances
data LocationInfo
information about a specific location in the game world
Constructors
LocationInfo
descLoc :: Descriptionthe description of the location
directions :: DirectionMapthe available exits
lookable :: LookableMapthe different items one can look at
takeable :: TakeableMapthe different items one can take
show/hide Instances
data ItemInfo
information about an item
Constructors
ItemInfo
itemCode :: ItemCodethe code for the item
itemDescription :: Descriptiona description
show/hide Instances
data GameState
the current game state. This is the only mutable object (of course, it is not mutable, but a different instance will be built every time the state change
Constructors
GameState
location :: LocationCodewhere the player is
items :: ItemMapthe items the player is carrying
changedLookableMap :: ChangedLookableMapthe changes in what can be looked at in the world (items taken are not present any more...)
show/hide Instances
data TakeAction
action of taking an item
Constructors
TakeActionOKaction succeeds
takeDescription :: Descriptionthe description of the item
changedLookable :: LookableMapthe changes to the lookable map
TakeActionFailaction fails
takeDescription :: Descriptionthe description of the failure
TakeActionNeedItemyou need another item to get the object
neededItem :: ItemCodethe other item needed to get this item
failDescription :: Descriptiondescription of failure
okDescription :: Descriptiondescription of success
changedLookable :: LookableMapthe changes to the lookable map
show/hide Instances
type LocationMap = Map LocationCode LocationInfo
map of locations by code
type DirectionMap = Map DirectionCode DirectionInfo
map of directions by code
type LookableMap = Map ItemCode Description
map of lookable items by code
newtype ItemMap
map of items by code. Note the newtype because we need it to be Show and Read
Constructors
ItemMap (Map ItemCode Description)
show/hide Instances
Read ItemMap
Show ItemMap
newtype ChangedLookableMap
the map of changes in what the player can look at
Constructors
ChangedLookableMap (Map LocationCode LookableMap)
show/hide Instances
type TakeableMap = Map ItemCode TakeAction
map of items the player can take, by code
type LocationCode = String
code for location
type ItemCode = String
code for item
type Description = String
description of something
type DirectionCode = String
code for direction
Data
actions :: Map String (GameState -> [String] -> (GameState, [String]))
all actions possible to the player
ioactions :: Map String (GameState -> [FilePath] -> IO (GameState, String))
all IO actions
Functions
start :: IO ()
start the game
getCommand
:: GameStatethe current game state
-> IO ()resulting IO
command loop: shows the current state, asks for a command, executes it, and loops | till exit is typed or till the game over state is reached
locationDescription :: LocationCode -> String
the description of a given location
locationDirections :: LocationCode -> [String]
the directions possible from a location
move :: GameState -> [DirectionCode] -> (GameState, [String])
move one or several steps
processMove :: GameState -> [DirectionCode] -> [String] -> (GameState, [String])
process the move
help :: GameState -> [String] -> (GameState, [String])
shows all possible commands
look :: GameState -> [ItemCode] -> (GameState, [String])
look at an item or a location (or several)
lookOne :: GameState -> [ItemCode] -> [String]
look at one item recursively
lookInState :: GameState -> ItemCode -> String
look at one item in the game state
lookDefault :: GameState -> ItemCode -> String
look at one item in the game world
carry :: GameState -> [ItemCode] -> (GameState, [String])
show what the player is carrying
takeItem :: GameState -> [ItemCode] -> (GameState, [String])
take an item
processTakeAction :: GameState -> ItemCode -> TakeAction -> (GameState, [String])
process the actual take action
trade :: GameState -> [ItemCode] -> (GameState, [String])
trade an item in. Here, you don't get to choose what you get in exchange!
gameOver :: GameState -> Bool
are the exit conditions filled?
save
:: GameStatethe current game state
-> [FilePath]the file paths (we use only the first one)
-> IO (GameState, String)the io operations
save the current game
load
:: GameStatethe current game state
-> [FilePath]the file paths (we use only the first one)
-> IO (GameState, String)the io operations
load a saved game
showItemMap :: ItemMap -> ShowS
implementation of show for an item map: transform the map in list
readItemMap :: ReadS ItemMap
implementation of read for ItemMap: from list to map
showChangedLookableMap :: ChangedLookableMap -> ShowS
implementation of show for a changedLookableMap: transform the map of map into a list of lists
readChangedLookableMap :: ReadS ChangedLookableMap
implementation of read for a changedLookableMap: from a list of lists to a map of maps
Produced by Haddock version 0.7