|
|
|
|
|
| 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 {} | | | data LocationInfo = LocationInfo {} | | | data ItemInfo = ItemInfo {} | | | data GameState = GameState {} | | | | | 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 :: Description | the description of the exit
| | locationCode :: LocationCode | the code for the location where the exit goes to
|
|
| Instances | |
|
|
| data LocationInfo |
| information about a specific location in the game world
| | Constructors | | Instances | |
|
|
| data ItemInfo |
| information about an item
| | Constructors | | 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 :: LocationCode | where the player is
| | items :: ItemMap | the items the player is carrying
| | changedLookableMap :: ChangedLookableMap | the changes in what can be looked at in the world (items taken are not present any more...)
|
|
| Instances | |
|
|
| data TakeAction |
| action of taking an item
| | Constructors | | TakeActionOK | action succeeds
| | takeDescription :: Description | the description of the item
| | changedLookable :: LookableMap | the changes to the lookable map
|
| | TakeActionFail | action fails
| | takeDescription :: Description | the description of the failure
|
| | TakeActionNeedItem | you need another item to get the object
| | neededItem :: ItemCode | the other item needed to get this item
| | failDescription :: Description | description of failure
| | okDescription :: Description | description of success
| | changedLookable :: LookableMap | the changes to the lookable map
|
|
| 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 | | Instances | |
|
|
| newtype ChangedLookableMap |
| the map of changes in what the player can look at
| | Constructors | | 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 |
| :: GameState | the 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 |
| :: GameState | the current game state
| | -> [FilePath] | the file paths (we use only the first one)
| | -> IO (GameState, String) | the io operations
| | save the current game
|
|
|
| load |
| :: GameState | the 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 |