Skip to content

Commit

Permalink
Working distinction between single and multiplayer game
Browse files Browse the repository at this point in the history
  • Loading branch information
nbartlomiej committed Apr 4, 2012
1 parent fd6c9ea commit 5906375
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
5 changes: 4 additions & 1 deletion Application.hs
@@ -1,4 +1,5 @@
{-# LANGUAGE TypeFamilies, QuasiQuotes, TemplateHaskell, OverloadedStrings #-} {-# LANGUAGE TypeFamilies, QuasiQuotes, TemplateHaskell, OverloadedStrings,
MultiParamTypeClasses #-}


module Application where module Application where


Expand Down Expand Up @@ -29,4 +30,6 @@ instance Yesod Tfoo where
addScript $ StaticR $ StaticRoute ["scripts","jquery.wiggle.js"] [] addScript $ StaticR $ StaticRoute ["scripts","jquery.wiggle.js"] []
hamletToRepHtml $(hamletFile "templates/layout.hamlet") hamletToRepHtml $(hamletFile "templates/layout.hamlet")


instance RenderMessage Tfoo FormMessage where
renderMessage _ _ = defaultFormMessage


7 changes: 6 additions & 1 deletion Tfoo/Handlers/Root.hs
Expand Up @@ -14,8 +14,9 @@ import Tfoo.Helpers.Game
import Data.Text as T import Data.Text as T
import Data.List as L import Data.List as L
import Data.Maybe as M import Data.Maybe as M
import Control.Monad


import Control.Monad
import Control.Applicative
import Control.Concurrent.MVar import Control.Concurrent.MVar


import Yesod import Yesod
Expand All @@ -34,6 +35,10 @@ postGamesR :: Handler RepHtml
postGamesR = do postGamesR = do
tfoo <- getYesod tfoo <- getYesod
id <- liftIO $ newGame tfoo id <- liftIO $ newGame tfoo
Just single <- runInputPost $ Just <$> iopt hiddenField (T.pack "single")
if isJust single
then setupComputerPlayer id
else return ()
redirect $ GameR id redirect $ GameR id


getGameR :: Int -> Handler RepHtml getGameR :: Int -> Handler RepHtml
Expand Down
4 changes: 4 additions & 0 deletions Tfoo/Helpers/Game.hs
Expand Up @@ -71,3 +71,7 @@ playerAuthorizations :: Handler [Player]
playerAuthorizations = do playerAuthorizations = do
authorizations <- lookupSession $ pack "players" authorizations <- lookupSession $ pack "players"
return $ fromMaybe [] $ fmap (words . unpack) authorizations return $ fromMaybe [] $ fmap (words . unpack) authorizations

setupComputerPlayer :: Int -> Handler ()
setupComputerPlayer id = do
return ()
3 changes: 1 addition & 2 deletions templates/index.hamlet
Expand Up @@ -6,10 +6,9 @@
\ Play ↓ or <a target=_blank href=https://github.com/nbartlomiej/tfoo>view source</a>. \ Play ↓ or <a target=_blank href=https://github.com/nbartlomiej/tfoo>view source</a>.
<div .play> <div .play>
<form method=post action=@{GamesR}> <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"> <input type=submit value="VS. Computer">
<form method=post action=@{GamesR}> <form method=post action=@{GamesR}>
<input type=hidden name=humans value=2>
<input type=submit value="VS. Human"> <input type=submit value="VS. Human">


<div #social_media_wrapper> <div #social_media_wrapper>
Expand Down

0 comments on commit 5906375

Please sign in to comment.