Created
February 4, 2021 07:51
-
-
Save znxkznxk1030/d8ec287f6c175510eb091650fcd78e4f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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