module States ( MState(..) ,DState(..) ,DGameBoard(..) ,TexObjGrp ,TexObjKey(..) ,getTextureObj ,fdivBoardNumX ,fdivBoardNumY ,KState(..) ,kStateChangeDownKey ,kStateChangePos ,kStateChangeDownKP ,mStateChangeEvents ,EventKey ,Eventx(..) ,mStateChangeGBoardCells ,mStateChangeGBoardCellsID ,GBoardCells(..) ,Cell(..) ,EventType(..) ,GStone(..) ) where import Graphics.Rendering.OpenGL import Graphics.UI.GLUT import System.Random import qualified Data.Map as Map data MState = MState { playerStone :: GStone ,gBoardCells :: GBoardCells ,displayGameBoard :: DGameBoard ,divBoardNumX :: GLint ,divBoardNumY :: GLint ,events :: (Map.Map EventKey Eventx) } deriving (Show) data GStone = SWhite | SBlack deriving (Show) type GBoardCells = Map.Map (Vector2 GLint) GStone data EventKey = EReset | EFrame | EDivPlus | EDivMinus deriving (Show , Eq , Ord) data Eventx = Eventx { eventID :: Int ,eventFlag :: Bool ,eventType :: EventType } deriving (Show) data EventType = Continue | AppOnce deriving (Show ,Eq) mStateChangeEvents :: MState -> (Map.Map EventKey Eventx) -> MState mStateChangeEvents (MState ps gbcs dgb dx dy _) exs = (MState ps gbcs dgb dx dy exs) mStateChangeGBoardCells :: MState -> GBoardCells-> MState mStateChangeGBoardCells (MState ps _ dgb dx dy exs) gbcs = (MState ps gbcs dgb dx dy exs) mStateChangeGBoardCellsID :: MState -> (Vector2 GLint) -> GStone -> MState mStateChangeGBoardCellsID mst v bc = let cells = gBoardCells mst gbcs = Map.insert v bc cells in mStateChangeGBoardCells mst gbcs data DGameBoard = DGameBoard { boardPosX :: GLfloat ,boardPosY :: GLfloat ,boardWidth :: GLfloat ,boardHeight :: GLfloat } deriving (Show) fdivBoardNumX :: MState -> GLfloat fdivBoardNumX mst = fromIntegral(divBoardNumX mst) fdivBoardNumY :: MState -> GLfloat fdivBoardNumY mst = fromIntegral(divBoardNumY mst) data DState = DState { windowWidth :: GLint ,windowHeight :: GLint } deriving (Show) data TexObjKey = KeyTexGameBoard | KeyTexStone deriving (Show , Ord , Eq) type TexObjGrp = Map.Map TexObjKey [TextureObject] getTextureObj :: TexObjKey -> TexObjGrp -> Int -> TextureObject getTextureObj texObjKey tObGp i = let mtexObjs = Map.lookup texObjKey tObGp mtexObjKey = Map.keys tObGp mtexObjKey0 = (mtexObjKey !! 0) in case mtexObjs of Nothing -> getTextureObj mtexObjKey0 tObGp i Just mtObs -> if (length mtObs) >= i then (mtObs !! i) else (mtObs !! 0) data KState = KState { downKey :: (Maybe Key) ,clickPos :: (Maybe (Vector2 GLfloat)) } deriving (Show) kStateChangeDownKey :: KState -> (Maybe Key) -> KState kStateChangeDownKey (KState _ b ) mkey = (KState mkey b) kStateChangePos :: KState -> (Maybe (Vector2 GLfloat)) -> KState kStateChangePos (KState a _ ) mp = (KState a mp) kStateChangeDownKP :: KState -> (Maybe Key) -> (Maybe (Vector2 GLfloat)) -> KState kStateChangeDownKP kst key pos = kStateChangeDownKey (kStateChangePos kst pos) key data Cell = Cell { cellMarginX :: GLfloat ,cellMarginY :: GLfloat } deriving (Show)