module States ( MState(..) ,DState(..) ,DGameBoard(..) ,TexObjGrp ,TexObjKey(..) ,getTextureObj ,fdivBoardNumX ,fdivBoardNumY ,KState(..) ,kStateChangeDownKey ,kStateChangePos ,kStateChangeDownKP ,mStateChangeEvents ,EventKey(..) ,Eventx(..) ,mStateChangeGBoardCells ,mStateChangeGBoardCellsID ,GBoardCells(..) ,EventType(..) ,GStone(..) ,GameTurn(..) ,mStateChangeGTurn ,mStateChangeGamePlayProg ,GamePlayProg(..) ,Cell(..) ,Counter(..) ,Container(..) ,containerMD ,CounterKey(..) ,GameMode(..) ,ButtonName(..) ,dContainerResionPoint ,dContainerResionPoint' ,SwitchGameMode(..) ,InputEvent(..) ,mStateChangeGMode ,switchGMode ,ButtonDisplay(..) ,EButton(..) ,kStateChangeCKey ,kStateCompareKeys ,kStateUpdatePreKey ,buttonEventBName ,dInputEventButton ,mStateChangeRandGen ) where import Graphics.Rendering.OpenGL import Graphics.UI.GLUT import System.Random import qualified Data.Map as Map import ResionMap import Control.Applicative import System.Random data MState = MState { playerStone :: GStone ,gameTurn :: GameTurn ,gamePlayProg :: GamePlayProg ,gBoardCells :: GBoardCells ,displayGameBoard :: DGameBoard ,divBoardNumX :: GLint ,divBoardNumY :: GLint ,events :: (Map.Map EventKey Eventx) ,switchGameMode :: SwitchGameMode ,gameMode :: GameMode ,randGen :: StdGen } deriving (Show) data GStone = SWhite | SBlack deriving (Show , Eq , Ord) data GameTurn = Turn1P | Turn2P deriving (Show ,Eq) data GamePlayProg = SelectCell | PuttedCell deriving (Show ,Eq , Ord) type GBoardCells = Map.Map (Vector2 GLint) GStone data EventKey = EReset | EManu deriving (Show , Eq , Ord) data Eventx = Eventx { eventID :: Int ,eventFlag :: Bool ,eventType :: EventType } deriving (Show) data EventType = Continue | AppOnce deriving (Show ,Eq) data GameMode = GameTitle | GamePlay1P | GamePlay2P | GameEnd deriving (Show , Eq , Ord) type SwitchGameMode = (Map.Map (GameMode , InputEvent) GameMode) switchGMode :: SwitchGameMode -> GameMode -> InputEvent -> GameMode switchGMode sg gm iev = let gmf = Map.lookup (gm ,iev) sg in case gmf of Nothing -> gm Just x -> x data InputEvent = ButtonEvent ButtonName | KeyPushEvent Key deriving (Show , Eq , Ord) buttonEventBName :: InputEvent -> Maybe ButtonName buttonEventBName ie = case ie of ButtonEvent a -> Just a KeyPushEvent b -> Nothing dInputEventButton :: InputEvent -> Bool dInputEventButton ie = case ie of ButtonEvent a -> True KeyPushEvent b -> False mStateChangeEvents :: MState -> (Map.Map EventKey Eventx) -> MState mStateChangeEvents (MState ps gt gpp gbcs dgb dx dy _ sgm gm rg) exs = (MState ps gt gpp gbcs dgb dx dy exs sgm gm rg) mStateChangeGBoardCells :: MState -> GBoardCells-> MState mStateChangeGBoardCells (MState ps gt gpp _ dgb dx dy exs sgm gm rg) gbcs = (MState ps gt gpp gbcs dgb dx dy exs sgm gm rg) mStateChangeGBoardCellsID :: MState -> (Vector2 GLint) -> GStone -> MState mStateChangeGBoardCellsID mst v bc = let cells = gBoardCells mst gbcs = Map.insert v bc cells in mStateChangeGBoardCells mst gbcs mStateChangeGTurn :: MState -> GameTurn-> MState mStateChangeGTurn (MState ps _ gpp gbcs dgb dx dy exs sgm gm rg) gt = (MState ps gt gpp gbcs dgb dx dy exs sgm gm rg) mStateChangeGamePlayProg :: MState -> GamePlayProg -> MState mStateChangeGamePlayProg (MState ps gt _ gbcs dgb dx dy exs sgm gm rg) gpp = (MState ps gt gpp gbcs dgb dx dy exs sgm gm rg) mStateChangeGMode :: MState -> GameMode -> MState mStateChangeGMode (MState ps gt gpp gbcs dgb dx dy exs sgm _ rg) gm = (MState ps gt gpp gbcs dgb dx dy exs sgm gm rg) mStateChangeRandGen :: MState -> StdGen -> MState mStateChangeRandGen (MState ps gt gpp gbcs dgb dx dy exs sgm gm _) rg = (MState ps gt gpp gbcs dgb dx dy exs sgm gm rg) data DGameBoard = DGameBoard { boardPosX :: GLfloat ,boardPosY :: GLfloat ,boardWidth :: GLfloat ,boardHeight :: GLfloat ,boardCell :: Cell } 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 ,eButtons :: (Map.Map ButtonName EButton) ,eCounter :: (Map.Map CounterKey Counter) } deriving (Show) data CounterKey = CBlack | CWhite deriving (Show , Eq , Ord) data EButton = EButton {buttonContainer :: Container ,buttonConti :: Bool ----連続入力を認めるか ,texObjKey :: TexObjKey } deriving (Show , Eq) data ButtonName = ButtonStart1P | ButtonStart2P deriving (Show , Eq , Ord) type ButtonDisplay = (Map.Map GameMode [ButtonName]) data TexObjKey = KeyTexGameBoard | KeyTexStone | KeyTexNum | KeyButtonStart1P | KeyButtonStart2P 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)) ,cKey :: (Maybe Key) ,preKey :: (Maybe Key) } deriving (Show) kStateChangeDownKey :: KState -> (Maybe Key) -> KState kStateChangeDownKey (KState _ b ck pk) mkey = (KState mkey b ck pk) kStateChangePos :: KState -> (Maybe (Vector2 GLfloat)) -> KState kStateChangePos (KState a _ ck pk) mp = (KState a mp ck pk) kStateChangeDownKP :: KState -> (Maybe Key) -> (Maybe (Vector2 GLfloat)) -> KState kStateChangeDownKP kst key pos = kStateChangeDownKey (kStateChangePos kst pos) key kStateChangeCKey :: KState -> (Maybe Key) -> KState kStateChangeCKey (KState a mp _ pk) ck = (KState a mp ck pk) kStateCompareKeys :: KState -> Maybe Bool kStateCompareKeys (KState k mp ck pk ) = (==) <$> ck <*> pk kStateUpdatePreKey :: KState -> KState kStateUpdatePreKey (KState k mp ck pk ) = (KState k mp k ck ) data Container = Container { containerPosX :: GLfloat ,containerPosY :: GLfloat ,containerWidth :: GLfloat ,containerHeight :: GLfloat ,containerMarginX :: GLfloat ,containerMarginY :: GLfloat } deriving (Show , Eq) dContainerResionPoint :: Container -> (Vector2 GLfloat) -> Bool dContainerResionPoint (Container x y w h mx my) v = containIntervalCC2 (Vector2 x y) (Vector2 (x + w) (y + h)) v dContainerResionPoint' :: Container -> (Vector2 GLfloat) -> Bool dContainerResionPoint' (Container x y w h mx my) v = containIntervalCC2 (Vector2 (x + mx) (y + my)) (Vector2 (x + w - mx) (y + h - my)) v data Cell = Cell { cellMarginX :: GLfloat ,cellMarginY :: GLfloat } deriving (Show , Eq ) data Counter = Counter { counterContainer :: Container ,counterNumDegit :: GLint ,counterTexKey :: TexObjKey } deriving (Show , Eq ) containerMD :: GLfloat -> GLfloat -> GLfloat -> GLfloat -> Container containerMD x y z w = Container x y z w 0.0 0.0