-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.idr
56 lines (44 loc) · 1.12 KB
/
Main.idr
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
module Main
import Hangman
import Messages
wantToKeepPlaying : IO Bool
wantToKeepPlaying = do
putStrLn Messages.doYouWantToPlay
yes <- getChar
return (yes == 'y')
nextLetter : GuessedWord -> IO Char
nextLetter word = do
putStrLn $ Messages.currentWord word
putStrLn $ Messages.enterALetter $ guessedLetters word
char <- getChar
return (char)
nextInteration : Game -> IO Game
nextInteration game =
case currentWord game of
Nothing =>
do
return (game)
Just word =>
if (livesLeft game < 0 || (isAllGuessed $ word) ) then
do
putStrLn Messages.death
return (game)
else
do
letter <- nextLetter $ word
nextInteration (makeGuess game letter)
mainLoop : Game -> IO Game
mainLoop game = do
putStrLn (Messages.wordsLeft game)
wantsToPlay <- wantToKeepPlaying
when (not wantsToPlay || (not $ anyWordsLeft game) ) $ do
putStrLn $ show wantsToPlay
putStrLn Messages.goodbye
return ()
game <- nextInteration (setNextWord game)
putStrLn "\n\n\n"
mainLoop game
main : IO ()
main = do
mainLoop defaultGame
return ()