-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMarcelFeoELazaroJoabe.hs
53 lines (46 loc) · 1.63 KB
/
MarcelFeoELazaroJoabe.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
import System.Random
import System.IO
atualizaArquivo::Int -> IO()
atualizaArquivo qtdTentativas = do
recorde <- readFile "highscore.txt"
let recordeInt = read recorde
if qtdTentativas < recordeInt
then do
writeFile "highscore.txt" (show qtdTentativas)
putStrLn "Voce bateu o recorde!"
else
putStrLn "Boa tentativa, mas voce nao bateu o recorde"
jogarNovamente :: IO ()
jogarNovamente = do
putStrLn "Você quer jogar novamente? (s ou n)"
op <- getLine
if op == "s"
then do
putStrLn "<< JOGO NOVO >>"
jogar
else
putStrLn "Até a próxima :)"
verificaNum :: Int -> Int -> IO ()
verificaNum numAleatorio qtdTentativas = do
putStr "Qual número você acha é? "
num <- readLn :: IO Int
if num == numAleatorio
then do
atualizaArquivo qtdTentativas
putStrLn $ "Você acertou!\nNúmero correto: " ++ show num ++ "\nTotal de tentativas: " ++ show qtdTentativas
jogarNovamente
else do
if num < numAleatorio
then putStrLn $ "Você errou. O número é maior."
else putStrLn $ "Você errou. O número é menor."
verificaNum numAleatorio (qtdTentativas + 1)
jogar :: IO ()
jogar = do
numAleatorio <- randomRIO (1, 100)
putStrLn "Digite um número entre 1 e 100:"
verificaNum numAleatorio 1
main :: IO ()
main = do
hSetBuffering stdout NoBuffering
putStrLn "<< JOGO DA ADIVINHAÇÃO >>"
jogar