Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Working distinction between single and multiplayer game

  • Loading branch information...
commit 5906375904c793dc6685147eb3ab4dc75a6f57a8 1 parent fd6c9ea
@nbartlomiej authored
View
5 Application.hs
@@ -1,4 +1,5 @@
-{-# LANGUAGE TypeFamilies, QuasiQuotes, TemplateHaskell, OverloadedStrings #-}
+{-# LANGUAGE TypeFamilies, QuasiQuotes, TemplateHaskell, OverloadedStrings,
+ MultiParamTypeClasses #-}
module Application where
@@ -29,4 +30,6 @@ instance Yesod Tfoo where
addScript $ StaticR $ StaticRoute ["scripts","jquery.wiggle.js"] []
hamletToRepHtml $(hamletFile "templates/layout.hamlet")
+instance RenderMessage Tfoo FormMessage where
+ renderMessage _ _ = defaultFormMessage
View
7 Tfoo/Handlers/Root.hs
@@ -14,8 +14,9 @@ import Tfoo.Helpers.Game
import Data.Text as T
import Data.List as L
import Data.Maybe as M
-import Control.Monad
+import Control.Monad
+import Control.Applicative
import Control.Concurrent.MVar
import Yesod
@@ -34,6 +35,10 @@ postGamesR :: Handler RepHtml
postGamesR = do
tfoo <- getYesod
id <- liftIO $ newGame tfoo
+ Just single <- runInputPost $ Just <$> iopt hiddenField (T.pack "single")
+ if isJust single
+ then setupComputerPlayer id
+ else return ()
redirect $ GameR id
getGameR :: Int -> Handler RepHtml
View
4 Tfoo/Helpers/Game.hs
@@ -71,3 +71,7 @@ playerAuthorizations :: Handler [Player]
playerAuthorizations = do
authorizations <- lookupSession $ pack "players"
return $ fromMaybe [] $ fmap (words . unpack) authorizations
+
+setupComputerPlayer :: Int -> Handler ()
+setupComputerPlayer id = do
+ return ()
View
3  templates/index.hamlet
@@ -6,10 +6,9 @@
\ Play ↓ or <a target=_blank href=https://github.com/nbartlomiej/tfoo>view source</a>.
<div .play>
<form method=post action=@{GamesR}>
- <input type=hidden name=humans value=1>
+ <input type=hidden name=single value=true>
<input type=submit value="VS. Computer">
<form method=post action=@{GamesR}>
- <input type=hidden name=humans value=2>
<input type=submit value="VS. Human">
<div #social_media_wrapper>
Please sign in to comment.
Something went wrong with that request. Please try again.