-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.hs
More file actions
133 lines (117 loc) · 3.44 KB
/
Game.hs
File metadata and controls
133 lines (117 loc) · 3.44 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
{-
Module : Game
Description : Core, Handler with submodules and its integration. Executes games
-}
module Game where
import Unit
import MapTree
import Battle
import Story
import Saves
import System.Console.ANSI
import System.IO
import System.Exit
playGame :: Unit -> MapTree a -> IO ()
playGame unit Null = do
putStrLn $ endGameCongrats
playGame unit (Node (MapNode(village, NullUnity, story)) (a) (b))
|story == bombDialogue = do
putStrLn $ story
hero <- loseHp unit
choice hero a b
|story == battleFairyDialogue = do
putStrLn $ story
hero <- improveAttack unit
choice hero a b
|otherwise = do
putStrLn $ story
choice unit a b
playGame unit (Node (MapNode(village, enemy, story)) (a) (b)) = do
putStrLn $ "\n\n\n" ++ story
leaveGame unit (Node (MapNode(village, enemy, story)) (a) (b))
hero <- combat unit enemy
choice hero a b
leaveGame :: Unit -> MapTree a -> IO Unit
leaveGame hero (Node (MapNode(village, enemy, story)) (a) (b)) = do
putStrLn $ "Quer lutar? Digite 'sim' ou 'nao'."
ch <- getLine
case ch of
"nao" -> saveGame hero (Node (MapNode(village, enemy, story)) (a) (b))
"sim" -> return hero
otherwise-> leaveGame hero (Node (MapNode(village, enemy, story)) (a) (b))
loseHp :: Monad m => Unit -> m Unit
loseHp hero = do
return $ setHP hero $ getHP hero - 5
improveAttack :: Monad m => Unit -> m Unit
improveAttack hero = do
return $ setAttack hero $ getAttack hero + 2
saveGame :: Unit -> MapTree a -> IO b
saveGame hero (Node (MapNode(village, enemy, story)) (a) (b)) = do
putStrLn $ "Deseja salvar antes de sair? Por favor, digite 'sim' ou 'nao' novamente."
ch <- getLine
case ch of
"sim" -> do
saveGameData hero (Node (MapNode(village, enemy, story)) (a) (b))
exitSuccess
"nao" -> exitSuccess
otherwise -> saveGame hero (Node (MapNode(village, enemy, story)) (a) (b))
choice :: Unit -> MapTree a -> MapTree b -> IO()
choice hero Null Null = do
playGame hero Null
choice hero a b = do
putStrLn $ "Escolha um caminho! Onde explorar? (1) " ++ (getVillageName a) ++ " (2) " ++ (getVillageName b)
ch <- getLine
case ch of
"1" -> playGame hero a
"2" -> playGame hero b
otherwise -> (choice hero a b)
drawStartScreen :: IO()
drawStartScreen = do
putStrLn $ "##### RPGaskell #####"
putStrLn $ "1 <- Novo Jogo"
putStrLn $ "2 <- Continuar"
putStrLn $ "3 <- Sair"
choice <- getLine
case choice of
"1" -> newGame;
"2" -> loadGame;
"3" -> exitGame;
newGame :: IO ()
newGame = do
name <- readName
cls <- readClass
let unit = createUnit name cls 100 10 10 10 True
playGame unit storyMap
readName :: IO String
readName = do
clearScreen
putStrLn $ "Como voce se chama? "
name <- getLine
return name
readClass :: IO Class
readClass = do
clearScreen
beginning
putStrLn $ "(1) " ++bow ++ "\n"++ "(2) "++wand ++"\n"++ "(3) "++sword++"\n"
option <- getLine
case option of
"1" -> do
printChoice bow
return (Archer)
"2" -> do
printChoice wand
return (Wizard)
"3" -> do
printChoice sword
return (Warrior)
otherwise -> do
putStrLn $ "Escolha uma dos equipamentos! Sem eles você será amassado como uma batata."
ch <- getChar
readClass
loadGame :: IO()
loadGame = do
unit <- loadUnit
map <- loadMap
playGame unit map
exitGame :: IO a
exitGame = exitSuccess