Hey guys,
i'm looking for a basic game written in haskell ie. rock paper scissors or high low if anyone had any links to somewhere i could get it or if anyone could post anything it would be great help!!
thanks
Archived topic from Iceteks, old topic ID:3329, old post ID:26987
Haskell Games
Haskell Games
A basic guess the number game in Haskell.
Code: Select all
module Main where
import System
import Random
import IO
makeGuesses :: Int -> Int -> IO ()
makeGuesses _ 0 = return ()
makeGuesses correctAnswer nGuessesRemaining =
do
putStr "Your guess? "
hFlush stdout
input <- getLine
let guess = read input
case compare guess correctAnswer of
LT -> do
putStrLn "Too low!"
makeGuesses correctAnswer (nGuessesRemaining - 1)
EQ -> do
putStrLn "Correct!"
return ()
GT -> do
putStrLn "Too high!"
makeGuesses correctAnswer (nGuessesRemaining - 1)
main :: IO ()
main = do
(maxNumberS:nGuessesS:_) <- getArgs
let (maxNumber, nGuesses) = map read (maxNumberS, nGuessesS)
correctAnswer <- randomRIO (0, maxNumber)
makeGuesses correctAnswer nGuesses[code]
[color=#888888][size=85]Archived topic from Iceteks, old topic ID:3329, old post ID:26988[/size][/color]