Skip to content

Commit

Permalink
Version 1.7.3
Browse files Browse the repository at this point in the history
Adapted to Haskell Platform 2013.2.0.0, wxWidgets 2.9.5 and
wxHaskell 0.90.1.0. Amongst others, hierarchical module system
introduced. GUI.hs: staticBitmapCreate has now 0x00200000
(== wxBORDER_NONE) as style, as wxWidgets does not accept -1 as style
anymore. The clientsize of the ¨move now¨ button is not set anymore,
so the text fits. TicTacToe now repainted on resize
  • Loading branch information
HJvT committed Oct 3, 2013
1 parent a7a50f8 commit 56ec71e
Show file tree
Hide file tree
Showing 23 changed files with 205 additions and 103 deletions.
2 changes: 1 addition & 1 deletion Ataxx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
module Ataxx (Ataxx, ataxx) where

import Game
import Array
import Data.Array
-- import Graphics.UI.WX
import Graphics.UI.WX hiding (border, point)
import Graphics.UI.WXCore hiding (point)
Expand Down
2 changes: 1 addition & 1 deletion Bamp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
module Bamp (Bamp, bamp) where

import Game
import Array
import Data.Array
import Graphics.UI.WX hiding (border, point)
import Graphics.UI.WXCore hiding (point)
import Tools
Expand Down
53 changes: 32 additions & 21 deletions GUI.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# OPTIONS -fglasgow-exts #-}
{-# LANGUAGE ExistentialQuantification #-}

---------
-- GUI --
Expand All @@ -9,18 +9,19 @@ module GUI (gui, version) where
import Game -- hiding (name)
import Graphics.UI.WX hiding (bitmap, children, click, selections, stop)
import Graphics.UI.WXCore
import Char
import Data.Char
import Tools hiding (field)
import List
import Data.List

version :: String
version = "1.7.2"
version = "1.7.3"


gui :: [GeneralGame] -> IO ()
gui games = do

{--== CREATION PHASE ==--}

f <- mdiParentFrame []
c <- mdiParentFrameGetClientWindow f

Expand All @@ -37,26 +38,26 @@ gui games = do

logo <- bitmapCreateLoad "images\\gebop.bmp" wxBITMAP_TYPE_ANY

{--== DEFENITION PHASE ==--}

{--== DEFINITION PHASE ==--}
let onpaint :: DC () -> Rect -> IO ()
onpaint dc r = do
tileBitmap dc r logo

{--== MODIFICATION PHASE ==--}

set mGame [ text := "&Game" ]
set iNew [ text := "&New Game\tCtrl+N", help := "Start a new game" , on command := newgame f games]
set iQuit [ help := "Quit the application" , on command := close f]
set iHelp [ text := "&Contents" , help := "Show the contents of GeBoP" , on command := html f "help\\index.html"]
set iAbout [ help := "Information about this program", on command := infoDialog f "About GeBoP" about]

set f [ visible := True
, clientSize := sz 640 480
, picture := "gebop.ico"
, text := "GeBoP"
, menuBar := [mGame, mHelp]
, statusBar := [field]
set f [ visible := True
, clientSize := sz 640 480
, picture := "gebop.ico"
, text := "GeBoP"
, menuBar := [mGame, mHelp]
, statusBar := [field]
]

set c [ on paint := onpaint
Expand Down Expand Up @@ -196,7 +197,7 @@ game mdiparent g pr newg = do

--{ field <- statusField []

{--== DEFENITION PHASE ==--}
{--== DEFINITION PHASE ==--}

let

Expand Down Expand Up @@ -234,7 +235,9 @@ game mdiparent g pr newg = do
for 0 (floor $ 19 * val t !!! i) (\j -> line dc (pt (xi + 1) (80 - j)) (pt (xi + 39) (80 - j)) [penColor := green])
for (floor $ 18 * val t !!! i) 0 (\j -> line dc (pt (xi + 1) (80 - j)) (pt (xi + 39) (80 - j)) [penColor := red ])
line dc (pt xi 80) (pt (xi + 40) 80) []
if player t == i && movesnr t > 0 then drawBitmap dc turn (pt xi 110) True [] else return ()
if player t == i && movesnr t > 0
then drawBitmap dc turn (pt xi 110) True []
else return ()
drawBitmap dc (if human pr !!! i then humanbmp else computerbmp) (pt xi 160) True []
ifIO (win i) $ drawBitmap dc winner (pt xi 110) True []

Expand All @@ -261,8 +264,7 @@ game mdiparent g pr newg = do
, bgcolor := setLum 0.95 $ colorplayer i
, visible := not (human pr !!! i)
]
set but [ clientSize := sz 60 20
, text := "move now"
set but [ text := "move now"
, color := setLum 0.25 $ colorplayer i
, bgcolor := setLum 0.95 $ colorplayer i
, on command := oncommand i
Expand Down Expand Up @@ -293,7 +295,8 @@ game mdiparent g pr newg = do
let b = (bs !!! p')
i <- get b itemCount
vs <- mapM (\p'' -> get (bs !!! p'') (item $ i - 1)) [p' .. length bs - 1]
when (not $ all null vs) $ mapM_ (\b' -> itemAppend b' "") bs
when (not $ all null vs) $
mapM_ (\b' -> itemAppend b' "") bs
i' <- get b itemCount
set b [item (i' - 1) := s]
mapM_ (\b' -> set b' [selection := i' - 1]) bs
Expand Down Expand Up @@ -440,14 +443,18 @@ brain mdiparent pr vart varb newg = do

{--== CREATION PHASE ==--}

let extraInfo = \_ -> return () -- "info" if you want tracing
f <- mdiChildFrame mdiparent []
extraInfo "mdiChildFrame"
sw <- splitterWindow f []
extraInfo "splitterWindow"

pLeft <- panel sw []
pRight <- panel sw []
pBoard <- panel pRight []
pValue <- panel pRight []
pInfo <- panel pRight []
extraInfo "panel"

mGame <- menuPane []
iNew <- menuItem mGame []
Expand All @@ -461,24 +468,28 @@ brain mdiparent pr vart varb newg = do
iHelp <- menuItem mHelp []
iBrain <- menuItem mHelp []
iAbout <- menuAbout mHelp []
extraInfo "menu"

logos <- mapM (bitmap.nameplayer) [0 .. 5]
winner <- bitmap "winner"
leeg <- bitmap "empty"

bPlayer <- staticBitmapCreate pRight (-1) (logos !!! 0) rectNull (-1)
bPlayer <- staticBitmapCreate pRight (-1) (logos !!! 0) rectNull 0x00200000 -- 0x00200000 == wxBORDER_NONE
extraInfo "staticBitmapCreate"

-- tPlayer <- staticText pRight []
tMind <- staticText pInfo []
tMaxd <- staticText pInfo []
tVolume <- staticText pInfo []
extraInfo "staticText"

tc <- treeCtrl pLeft []
extraInfo "treeCtrl"

g <- varGet vart >>= return . state
varu <- varCopy vart

{--== DEFENITION PHASE ==--}
{--== DEFINITION PHASE ==--}

let

Expand Down
6 changes: 3 additions & 3 deletions Game.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{-# OPTIONS -fglasgow-exts #-}
{-# LANGUAGE ExistentialQuantification #-}

module Game where

import Graphics.UI.WX hiding (children, value)
import Array
import Data.Array
import Tools

----------------
Expand Down Expand Up @@ -163,4 +163,4 @@ followbest t = case filter (\i -> not $ closed $ children t ! i) $ best t of
b -> b

followopen :: Game g => Tree g -> [Int]
followopen t = map fst $ filter (not.closed.snd) $ assocs $ children t
followopen t = map fst $ filter (not.closed.snd) $ assocs $ children t
62 changes: 32 additions & 30 deletions GeBoP.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ Synopsis: Several games
Description:
The games: Ataxx, Bamp, Halma, Hez, Kram, Nim, Reversi, TicTacToe, and Zenix
Homepage: http://www.haskell.org/haskellwiki/GeBoP
Version: 1.7.2
Version: 1.7.3
License: BSD3
License-file: LICENSE.txt
Author: Maarten Löffler
Maintainer: Maarten Löffler <[email protected]>
Maintainer: wxHaskell developer mailing list <[email protected]>
Stability: Stable
Cabal-Version: >= 1.2
Build-type: Simple
Category: Game
Tested-with: GHC == 6.10.4, GHC == 6.12.1, GHC == 6.12.3
Tested-with: GHC == 7.4.1, GHC == 7.4.2, GHC == 7.6.3
Extra-Source-Files:
changelog.txt
readme.txt,
Expand Down Expand Up @@ -85,38 +85,40 @@ Data-files: gebop.ico,
images/turn.bmp,
images/turn_mask.bmp,
images/winner.bmp,
images/winner_mask.bmp
help/brain.html
help/gebop.bmp
help/index.html
help/info_ataxx.html
help/info_bamp.html
help/info_halma.html
help/info_hex.html
help/info_kram.html
help/info_nim.html
help/info_reversi.html
help/info_tictactoe.html
help/info_zenix.html
help/rules_ataxx.html
help/rules_bamp.html
help/rules_halma.html
help/rules_hex.html
help/rules_kram.html
help/rules_nim.html
help/rules_reversi.html
help/rules_tictactoe.html
images/winner_mask.bmp,
help/brain.html,
help/gebop.bmp,
help/index.html,
help/info_ataxx.html,
help/info_bamp.html,
help/info_halma.html,
help/info_hex.html,
help/info_kram.html,
help/info_nim.html,
help/info_reversi.html,
help/info_tictactoe.html,
help/info_zenix.html,
help/rules_ataxx.html,
help/rules_bamp.html,
help/rules_halma.html,
help/rules_hex.html,
help/rules_kram.html,
help/rules_nim.html,
help/rules_reversi.html,
help/rules_tictactoe.html,
help/rules_zenix.html

Executable gebop
Build-Depends:
base < 5,
wxcore >= 0.11 && < 0.13,
wx >= 0.11 && < 0.13,
haskell98 < 1.1,
directory < 1.1
array >= 0.4 && < 0.5,
base >= 4.5 && < 4.7,
directory >= 1.1 && < 1.3,
random >= 1.0 && < 1.1,
wx >= 0.11 && < 0.91,
wxcore >= 0.11 && < 0.91

Main-Is: Main.hs
GHC-Options: "-Wall"
GHC-Options: -Wall -optc-static-libgcc

-- The following can only work, when GeBoP stops printing trace data:
-- if os(mingw32)
Expand Down
6 changes: 3 additions & 3 deletions Halma.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
module Halma (Halma, halma) where

import Game
import Array
import Data.Array
-- import Graphics.UI.WX
import Graphics.UI.WX hiding (border, empty, point)
import Graphics.UI.WXCore hiding (empty, point)
Expand Down Expand Up @@ -231,7 +231,7 @@ move pr (f, t) (p, Halma s) = ( (p + 1) `mod` players pr
, Halma $ s // [(f, Nothing), (t, Just p)]
)

startpos :: (Num t, Num t1, Enum t1) => t -> [(t1, t1)]
startpos :: (Eq t, Num t, Num t1, Enum t1) => t -> [(t1, t1)]
startpos 0 = [(x, y) | x <- [-4 .. -1], y <- [x + 5 .. 4]]
startpos 1 = [(x, y) | x <- [-8 .. -5], y <- [ - 4 .. x + 4]]
startpos 2 = [(x, y) | x <- [-4 .. -1], y <- [x - 4 .. - 5]]
Expand Down Expand Up @@ -276,4 +276,4 @@ y/j
87654321012345678 x/i
--------
-}
-}
4 changes: 2 additions & 2 deletions Hex.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
module Hex (Hex, hex) where

import Game
import Array
import Data.Array
import Graphics.UI.WX hiding (border, point)
import Graphics.UI.WXCore hiding (point)
import Tools
Expand Down Expand Up @@ -178,4 +178,4 @@ jumps = [ (( 2, 1), [( 1, 0), ( 1, 1)])
1 1
0
-}
-}
4 changes: 2 additions & 2 deletions Inf.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ instance Ord a => Ord (Inf a) where
compare _ (Infinite True ) = LT
compare _ (Infinite False) = GT

instance Num a => Num (Inf a) where
instance (Num a, Eq a) => Num (Inf a) where
Finite x + Finite y = Finite (x + y)
Infinite True + Infinite False = error "<+inf> + <-inf>"
Infinite False + Infinite True = error "<-inf> + <+inf>"
Expand All @@ -53,4 +53,4 @@ fin :: a -> Inf a
fin = Finite

inf :: Inf a
inf = Infinite True
inf = Infinite True
2 changes: 1 addition & 1 deletion Kram.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
module Kram (Kram, kram) where

import Game
import Array
import Data.Array
import Graphics.UI.WX hiding (border, point)
import Graphics.UI.WXCore hiding (point)
import Tools
Expand Down
3 changes: 1 addition & 2 deletions Reversi.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
module Reversi (Reversi, reversi) where

import Game
import Array
-- import Graphics.UI.WX
import Data.Array
import Graphics.UI.WX hiding (border)
import Graphics.UI.WXCore
import Tools
Expand Down
25 changes: 19 additions & 6 deletions TicTacToe.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ rules _ = "Tictactoe"
| otherwise = (i + 3 * j)
case lookup n (zip (map snd $ possiblemoves st) [0..]) of
Nothing -> return ()
Just n' -> move' n'
Just n' -> move' n'

set p [ on click := onclick
, on paint := onpaint
set p [ on click := onclick
, on paint := onpaint
, on resize := repaint p
]

return ()
Expand All @@ -97,12 +98,24 @@ possiblemoves st = filter ((== Nothing) . fst) $ zip st [0 .. 8]

drawCross :: DC () -> Rect -> IO ()
drawCross dc (Rect x y w h) =
do line dc (pt (x + w `div` 10) (y + h `div` 10)) (pt (x + w - w `div` 10) (y + h - h `div` 10)) [penColor := blue, penWidth := 2]
line dc (pt (x + w `div` 10) (y + h - h `div` 10)) (pt (x + w - w `div` 10) (y + h `div` 10)) [penColor := blue, penWidth := 2]
do line
dc
(pt (x + w `div` 10) (y + h `div` 10))
(pt (x + w - w `div` 10) (y + h - h `div` 10))
[penColor := blue, penWidth := 2]
line
dc
(pt (x + w `div` 10) (y + h - h `div` 10))
(pt (x + w - w `div` 10) (y + h `div` 10))
[penColor := blue, penWidth := 2]

drawCircle :: DC () -> Rect -> IO ()
drawCircle dc (Rect x y w h) =
do circle dc (pt (x + w `div` 2) (y + h `div` 2)) (2 * (min w h) `div` 5) [penColor := red, penWidth := 2, brushKind := BrushTransparent]
do circle
dc
(pt (x + w `div` 2) (y + h `div` 2))
(2 * (min w h) `div` 5)
[penColor := red, penWidth := 2, brushKind := BrushTransparent]

move :: Int -> (Player, TicTacToe) -> (Player, TicTacToe)
move n (p, TicTacToe s) = (1 - p, TicTacToe $ (n |> Just p) s)
Expand Down
Loading

0 comments on commit 56ec71e

Please sign in to comment.