{- | Ein- und Ausgabe fuer Game.VierGewinnt getrennt von Zugberechnung -} module Game.VierGewinnt.HTML ( komplett, erzeuge, main, ) where import Game.VierGewinnt (Spieler(..), Zug, Spielstand, grundstellung, brettVon, wertung, anfangundzuege, moeglicheZuege, berechneSpielstand, istMatt, ) import Game.Utility (readMaybe, nullToMaybe, ) import Text.Html((<<), (+++), noHtml, spaceHtml, concatHtml, renderHtml, toHtml, ) import qualified Text.Html as Html import qualified Data.List as List import Data.Array((!)) import qualified Network.CGI as CGI farbe :: Maybe Spieler -> String farbe Nothing = Html.white farbe (Just Mensch) = Html.blue farbe (Just Computer) = Html.red labelAnchor :: String -> Html.Html -> Html.Html labelAnchor ref label = Html.anchor label Html.! [Html.href ref] relHeight, relWidth :: Int -> Html.HtmlAttr relHeight r = Html.strAttr "HEIGHT" (show r ++ "%") relWidth r = Html.strAttr "WIDTH" (show r ++ "%") spielstand :: Spielstand -> Html.Html spielstand stand = concatHtml [moeglichesEnde, table] where brett = brettVon stand fmtf x = Html.td spaceHtml Html.! [relHeight 14, Html.bgcolor (farbe x)] table = Html.center (Html.table (concatHtml tableContents) Html.! [relWidth 65, relHeight 65, Html.border 2]) tableContents = zuege: [Html.tr (concatHtml [fmtf (brett!(i,7-j)) | i<-[1..7]]) | j<-[1..6]] moeglichesEnde = case wertung stand of 6000 -> Html.h2 << "Du bist matt!" (-6000) -> Html.h2 << "Du hast gewonnen!" _ -> noHtml zuege = Html.tr (concatHtml (map gencell [1..7])) {- fmt [] = "