Parsing all events, making parser errors fatal
[darcs-mirror-haskell-partty.git] / DeafAndSilent.hs
1 import Control.Monad.Trans
2 import Control.Monad.State
3 import Control.Monad.Writer
4 import System.Random
5
6 import Partty
7
8 type UserData = Maybe Place
9
10 dcb :: DayCallback UserData
11 dcb DayStarts = do
12         mbp <- get
13         case mbp of
14                 Nothing -> do
15                         liftIO $ putStrLn "No idea where to go, guessgin..."
16                         room <- liftIO $ randomRIO (0,9)
17                         send (Goto room)
18                 Just room -> do
19                         liftIO $ putStrLn $ "Yay, I know where to go! (" ++ show room ++")"
20                         send (Goto room)
21
22
23 dcb e = return ()
24
25 ncb :: NightCallback UserData
26 ncb (NightEnds) = put Nothing
27
28 ncb (PartyHint room) = put (Just room)
29
30 ncb (GotScore score) = liftIO $ putStrLn $ "Got score: " ++ show score
31
32 ncb e = return ()
33
34
35 main = do
36         runPartty "localhost" 1111 "me2" "passwd" dcb ncb Nothing
37