Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Omg, we print out the board.

YEAAAAAH BOIIII!
  • Loading branch information...
commit 96560c958fd42b061d7f916a37c663a10714510d 1 parent 58477f4
@steveklabnik authored
Showing with 42 additions and 7 deletions.
  1. +1 −0  .gitignore
  2. +1 −1  Makefile
  3. +40 −6 behind.hs
View
1  .gitignore
@@ -1,3 +1,4 @@
*.hi
behind
*.o
+*.swp
View
2  Makefile
@@ -1,2 +1,2 @@
main:
- runhaskell behind.hs
+ ghc -o behind -package hscurses behind.hs
View
46 behind.hs
@@ -1,4 +1,5 @@
import UI.HSCurses.Curses
+import System.IO
type Health = Int
type Name = String
@@ -9,6 +10,12 @@ data Cell = Wall
| Empty
| Goal
+instance Show Cell where
+ show Wall = "#"
+ show Empty = "."
+ show Goal = "<"
+
+
data World = MakeWorld [[Cell]] Int Int
initWorld :: IO World
@@ -19,14 +26,36 @@ initPlayer = return $ Player "Someone" 10
act :: World -> Key -> IO World
act (MakeWorld board x y) i = case i of
- KeyChar 'h' -> return $ MakeWorld board (x - 1) y
- KeyChar 'j' -> return $ MakeWorld board x (y - 1)
- KeyChar 'k' -> return $ MakeWorld board x (y + 1)
- KeyChar 'l' -> return $ MakeWorld board (x + 1) y
- otherwise -> return (MakeWorld board x y)
+ KeyChar 'h' -> return $ MakeWorld board (lowerBound (x - 1)) y
+ KeyChar 'j' -> return $ MakeWorld board x (lowerBound (y - 1))
+ KeyChar 'k' -> return $ MakeWorld board x (upperBound (y + 1))
+ KeyChar 'l' -> return $ MakeWorld board (upperBound (x + 1)) y
+ otherwise -> return $ MakeWorld board x y
+
+lowerBound :: Int -> Int
+lowerBound n = max n 0
+
+upperBound :: Int -> Int
+upperBound n = min n 1
drawWorld :: World -> IO ()
-drawWorld (MakeWorld board x y) = putStrLn $ "x: " ++ show x ++ " y: " ++ show y
+drawWorld (MakeWorld board x y) = do
+ wclear stdScr
+ wMove stdScr 0 0
+ --foldl (\ys -> foldl (\c -> myshow (return ()) c) ys) (return ()) board
+ board' <- return $ map (\ys -> map (show) ys) board
+ board'' <- return $ foldr (++) "" $ foldr (\a b -> a ++ ["\r\n"] ++ b) [] board'
+ putStr board''
+ putStr $ "x: " ++ show x ++ " y: " ++ show y
+
+myshow :: IO a -> Cell -> IO ()
+myshow boo c = putStr $ show c
+
+drawSpace :: [[Cell]] -> Int -> Int -> IO ()
+drawSpace board x y = do
+ wMove stdScr y x
+ putStr $ show $ board !! x !! y
+
hasWon :: World -> Bool
@@ -42,9 +71,14 @@ gameLoop n w p
gameLoop (n + 1) w' p
main = do
+ hSetBuffering stdout NoBuffering
initCurses
+ cBreak True
+ echo False
+ nl False
world <- initWorld
player <- initPlayer
gameLoop 0 world player
+ endWin
putStr "Goodbye!"
Please sign in to comment.
Something went wrong with that request. Please try again.