Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Инициальная структура программы для руководства.
- Loading branch information
unknown
authored and
unknown
committed
Jun 4, 2011
1 parent
c2b20d6
commit 4e13bf8
Showing
1 changed file
with
5 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,6 @@ | ||
module Main where | ||
|
||
import Types | ||
import Locations | ||
import System.IO (hFlush, stdout) | ||
import Control.Monad.State (liftIO) | ||
|
||
directionsToString :: [Direction] -> String | ||
directionsToString (dir:dirs) = show dir ++ case null(dirs) of | ||
True -> [] | ||
False -> ", " ++ directionsToString dirs | ||
directionsToString [] = [] | ||
|
||
describeDirections :: Location -> String | ||
describeDirections loc = "You can go " ++ directionsToString ( getLocationDirections loc) | ||
|
||
describeActions :: Location -> String | ||
describeActions _ = "You can do something." | ||
|
||
describeGameSituation :: Location -> String | ||
describeGameSituation loc = do | ||
describeDirections loc | ||
describeActions loc | ||
|
||
|
||
getAction = do | ||
putStr "> " | ||
hFlush stdout | ||
line <- getLine | ||
return (line) | ||
|
||
run :: Location -> IO () | ||
run oldLoc = do | ||
putStrLn . describeLocation $ oldLoc | ||
putStrLn . describeDirections $ oldLoc | ||
putStrLn . describeActions $ Room | ||
x <- getAction | ||
case x of | ||
"Quit" -> return () | ||
"q" -> return () | ||
otherwise -> run . getLocation $ (oldLoc, x) | ||
|
||
main :: IO () | ||
main = run Room | ||
describeLocation :: String -> String | ||
describeLocation locName = case locName of | ||
"Home" -> "You are standing in the middle room at the wooden table." | ||
"Friend's home" -> "You are standing in the front of the night garden behind the small wooden fence." | ||
otherwise -> "Unknown location." |