-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTypes.hs
107 lines (86 loc) · 2.27 KB
/
Types.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
module Types where
import Control.Monad (mapM_)
import Control.Monad.State (StateT(..), MonadState(..), MonadIO(..), evalStateT)
import qualified Data.Map as M
type MaybeSomething a = (Maybe a, String)
data Room = InventoryRoom | Home | Friend'sYard | Corridor | NoRoom
deriving (Eq, Show, Read, Ord)
type Rooms = [Room]
type LongDescribedRooms = Rooms
data Direction = North | South | West | East | NoDirection
deriving (Eq, Show, Read)
type Directions = [Direction]
data OpenCloseState = Opened | Closed
deriving (Eq, Show, Read)
type ObjectName = String
data Object =
Object {
objectName :: ObjectName,
objectRoom :: Room
}
| Container {
objectName :: ObjectName,
objectContainerState :: OpenCloseState,
objectContents :: Objects,
objectRoom :: Room
}
| Complex {
objectName :: ObjectName,
objectComponent1 :: Object,
objectComponent2 :: Object,
objectRoom :: Room
}
deriving (Show, Read)
type Objects = [Object]
type Components = Objects
type MaybeWeldedObject = Maybe (Object, String)
type Welder = Components -> MaybeWeldedObject
data Path = Path {
pathDirection :: Direction,
pathRoom :: Room
} deriving (Eq, Show, Read)
type Paths = [Path]
data Location = Location {
locRoom :: Room,
locPaths :: Paths,
locLongDescribed :: Bool
} deriving (Show, Read)
type Locations = M.Map Room Location
type MaybeLocation = MaybeSomething Location
data GameState = GameState {
gsLocations :: Locations,
gsCurrentRoom :: Room,
gsObjects :: Objects
} deriving (Show, Read)
type GS a = (StateT GameState IO a)
data Command =
Walk Direction
| Look
| Go String
| Examine ObjectName
| Inventory
| Take ObjectName
| Weld ObjectName ObjectName
| Open ObjectName
| New
| Quit String
| Help
deriving (Eq, Show, Read)
data InputCommand =
QualifyPickup Objects
| QualifyOpen Objects
type InputString = String
type OutputMessage = String
type InputOutputString = String
data GameAction =
PrintMessage OutputMessage
| QuitGame OutputMessage
| ReadUserInput
| ReadMessagedUserInput InputOutputString InputCommand
| SaveState GameState OutputMessage
| StartNewGame
class Openable a where
open :: a -> MaybeSomething a
close :: a -> MaybeSomething a
showStated :: a -> String
showContents :: a -> String