-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScore.hs
41 lines (34 loc) · 951 Bytes
/
Score.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
module Score where
import Defs
import Control.Monad
import Control.Monad.RWS
addPoints :: Int -> String -> Game ()
addPoints points reason = do
oldScore <- getScore
setScore $ oldScore + points
msg $ "You " ++ (if points >= 0 then "earn" else "lose") ++ " " ++
show (abs points) ++ " points for " ++ reason ++ ". " ++
"Use the \"score\" command to see your score."
maybeShowWinMessage
getScore :: Game Int
getScore = do
st <- get
return $ score st
setScore :: Int -> Game ()
setScore points = do
st <- get
put $ st { score = points }
getMaxScore :: Game Int
getMaxScore = do
st <- get
return $ maxScore st
setMaxScore :: Int -> Game ()
setMaxScore points = do
st <- get
put $ st { maxScore = points }
maybeShowWinMessage :: Game ()
maybeShowWinMessage = do
points <- getScore
maxPoints <- getMaxScore
when (points >= maxPoints) $ do
msg "You have won! You may exit with \"exit\", or continue playing."