Skip to content

Instantly share code, notes, and snippets.

@znxkznxk1030
Created February 4, 2021 07:51
Show Gist options
  • Save znxkznxk1030/d8ec287f6c175510eb091650fcd78e4f to your computer and use it in GitHub Desktop.
Save znxkznxk1030/d8ec287f6c175510eb091650fcd78e4f to your computer and use it in GitHub Desktop.
{-# LANGUAGE RecordWildCards #-}
module Block (
Shape(..),
Block(..),
genblock,
block2coords
) where
data Shape = I | L | J | O | S | Z | T deriving(Eq)
data Block = Block {shape :: Shape, rotate :: Int, coords :: (Int, Int)}
genblock :: Block
genblock = Block I 0 (5, 2)
getShape :: Block -> Shape
getShape Block{..} = shape
getRotate :: Block -> Int
getRotate Block{..} = rotate
getCoords :: Block -> (Int, Int)
getCoords Block{..} = coords
block2coords :: Block -> [(Int, Int)]
block2coords block
| shape == I && rotate == 0 = [ (x, y - 1), (x, y), (x, y + 1), (x, y + 2) ]
| shape == I && rotate == 1 = [ (x - 1, y), (x, y), (x + 1, y), (x + 1, y) ]
| otherwise = []
where shape = getShape block
rotate = getRotate block
(x, y) = getCoords block
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment