tateti-tateti 0.1.0.0 → 0.1.0.1
raw patch · 3 files changed
+65/−58 lines, 3 filesdep ~arraydep ~lens-simpledep ~mtl
Dependency ranges changed: array, lens-simple, mtl, ncurses, random
Files
- src/Draw.hs +15/−17
- src/Main.hs +23/−10
- tateti-tateti.cabal +27/−31
src/Draw.hs view
@@ -15,7 +15,7 @@ -- main cross drawCross 7 Nothing (0, 0) - -- top row crosses+ -- small crosses let offsets = [1, 1 + 8, 1 + 8 + 8] coords = (,) <$> offsets <*> offsets poss = range (Position T L, Position B R)@@ -23,25 +23,23 @@ color_ids = map (winner >=> return . colors . color) poss mapM_ (uncurry $ drawCross 1) $ zip color_ids coords---drawCross :: Integer -> Maybe ColorID -> (Integer, Integer) -> Update ()-drawCross cellsize m_cid (y, x) = do- case m_cid of- Just cid -> setColor cid- Nothing -> setColor defaultColorID+ where+ drawCross cellsize m_cid (y, x) = do+ case m_cid of+ Just cid -> setColor cid+ Nothing -> setColor defaultColorID - moveCursor (cellsize + y) x- drawLineH (Just glyphLineH) (cellsize * 3 + 2)- moveCursor (cellsize + y + cellsize + 1) x- drawLineH (Just glyphLineH) (cellsize * 3 + 2)+ moveCursor (cellsize + y) x+ drawLineH (Just glyphLineH) (cellsize * 3 + 2)+ moveCursor (cellsize + y + cellsize + 1) x+ drawLineH (Just glyphLineH) (cellsize * 3 + 2) - moveCursor y (cellsize + x)- drawLineV (Just glyphLineV) (cellsize * 3 + 2)- moveCursor y (cellsize + x + cellsize + 1)- drawLineV (Just glyphLineV) (cellsize * 3 + 2)+ moveCursor y (cellsize + x)+ drawLineV (Just glyphLineV) (cellsize * 3 + 2)+ moveCursor y (cellsize + x + cellsize + 1)+ drawLineV (Just glyphLineV) (cellsize * 3 + 2) - setColor defaultColorID+ setColor defaultColorID drawMessages :: GameState -> Colors -> Update ()
src/Main.hs view
@@ -32,9 +32,9 @@ colors <- getColors whoPlaysLoop w1 colors (CPlayer X) >>= \case- -- quited+ -- player quited Nothing -> return ()- -- chose something+ -- player chose something Just m_choice -> do pl <- case m_choice of CPlayer pl -> return pl@@ -46,12 +46,19 @@ gPlayer .= pl lift $ updateWindow w1 clear + -- enter main loop and play, returning a winner m_winner <- mainLoop w1 w2 colors case m_winner of+ -- if no winner, just end Nothing -> return ()+ -- otherwise, draw everything,+ -- clear messages and display winner Just winner -> do+ drawAll w1 w2 colors+ lift $ updateWindow w2 clear+ endGameLoop winner w2 colors -- cleaning up@@ -61,13 +68,8 @@ mainLoop :: Window -> Window -> Colors -> Game (Maybe Winner) mainLoop w1 w2 colors = do- gs <- get- lift $ updateWindow w1 $ drawCrosses gs colors- lift $ updateWindow w2 $ drawMessages gs colors- lift $ updateWindow w1 $ drawMarks gs colors- lift $ updateWindow w1 $ drawCursor gs - lift render+ drawAll w1 w2 colors parseInput w1 >>= \case Movement m -> movePlayer m@@ -97,10 +99,9 @@ -- move to next board gBoardState . bsPosition .= played_p- p' <- use (gBoardState . bsPosition) -- enter free mode if closed- use (gBoardState . bsAx p' . bsWinner) >>= \case+ use (gBoardState . bsAx played_p . bsWinner) >>= \case Nothing -> return () Just _ -> gMode .= Free Quit -> gQuit .= True@@ -203,6 +204,18 @@ checkVertical v = check mark_f [ Position v x | x <- [L .. R] ] checkHorizontal h = check mark_f [ Position y h | y <- [T .. B] ] checkDraw = check has_f $ range (Position T L, Position B R)+++drawAll :: Window -> Window -> Colors -> Game ()+drawAll w1 w2 colors = do+ gs <- get++ lift $ updateWindow w1 $ drawCrosses gs colors+ lift $ updateWindow w2 $ drawMessages gs colors+ lift $ updateWindow w1 $ drawMarks gs colors+ lift $ updateWindow w1 $ drawCursor gs++ lift render getColors :: Game Colors
tateti-tateti.cabal view
@@ -1,33 +1,29 @@-name: tateti-tateti-version: 0.1.0.0-cabal-version: >=1.10-build-type: Simple-license: BSD3-license-file: LICENSE-copyright: 2015 Ezequiel A. Alvarez-maintainer: welcometothechango@mgail.com-homepage: http://github.com/alvare/tateti-tateti#readme-synopsis: Meta tic-tac-toe ncurses game.-description:- Please see README.md-category: Game-author: Ezequiel A. Alvarez+name: tateti-tateti+version: 0.1.0.1+synopsis: Meta tic-tac-toe ncurses game.+description: Please see README.md+homepage: http://github.com/alvare/tateti-tateti#readme+license: BSD3+license-file: LICENSE+author: Ezequiel A. Alvarez+maintainer: welcometothechango@gmail.com+copyright: 2015 Ezequiel A. Alvarez+category: Game+build-type: Simple+cabal-version: >=1.10 executable tateti-tateti- main-is: Main.hs- build-depends:- base >=4.7 && <5,- ncurses >=0.2.14 && <0.3,- mtl >=2.2.1 && <2.3,- lens-simple >=0.1.0.8 && <0.2,- array >=0.5.1.0 && <0.6,- random ==1.1.*- default-language: Haskell2010- hs-source-dirs: src- other-modules:- Draw- OtherScreens- Types- Util- ghc-options: -Wall -O2-+ hs-source-dirs: src+ other-modules: Draw+ , OtherScreens+ , Types+ , Util+ ghc-options: -Wall -O2+ main-is: Main.hs+ default-language: Haskell2010+ build-depends: base >= 4.7 && < 5+ , ncurses+ , mtl+ , lens-simple+ , array+ , random