Rename currBlock -> block
This commit is contained in:
		
							parent
							
								
									7bea4fc3be
								
							
						
					
					
						commit
						4de0c3d8d3
					
				
					 1 changed files with 12 additions and 12 deletions
				
			
		| 
						 | 
					@ -46,7 +46,7 @@ type Board = Map Coord Tetrimino
 | 
				
			||||||
-- | Game state
 | 
					-- | Game state
 | 
				
			||||||
data Game = Game
 | 
					data Game = Game
 | 
				
			||||||
  { _level :: Int
 | 
					  { _level :: Int
 | 
				
			||||||
  , _currBlock :: Block
 | 
					  , _block :: Block
 | 
				
			||||||
  , _nextShape :: Tetrimino
 | 
					  , _nextShape :: Tetrimino
 | 
				
			||||||
  , _nextShapeBag :: Seq.Seq Tetrimino
 | 
					  , _nextShapeBag :: Seq.Seq Tetrimino
 | 
				
			||||||
  , _rowClears :: Seq.Seq Int
 | 
					  , _rowClears :: Seq.Seq Int
 | 
				
			||||||
| 
						 | 
					@ -136,7 +136,7 @@ initGame lvl = do
 | 
				
			||||||
  (s2, bag2) <- bagFourTetriminoEach bag1
 | 
					  (s2, bag2) <- bagFourTetriminoEach bag1
 | 
				
			||||||
  return $
 | 
					  return $
 | 
				
			||||||
    Game { _level = lvl
 | 
					    Game { _level = lvl
 | 
				
			||||||
         , _currBlock = initBlock s1
 | 
					         , _block = initBlock s1
 | 
				
			||||||
         , _nextShape = s2
 | 
					         , _nextShape = s2
 | 
				
			||||||
         , _nextShapeBag = bag2
 | 
					         , _nextShapeBag = bag2
 | 
				
			||||||
         , _score = 0
 | 
					         , _score = 0
 | 
				
			||||||
| 
						 | 
					@ -144,10 +144,10 @@ initGame lvl = do
 | 
				
			||||||
         , _board = mempty }
 | 
					         , _board = mempty }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
isGameOver :: Game -> Bool
 | 
					isGameOver :: Game -> Bool
 | 
				
			||||||
isGameOver g = currBlockStopped g && g ^. currBlock ^. origin == startOrigin
 | 
					isGameOver g = blockStopped g && g ^. block ^. origin == startOrigin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
timeStep :: Game -> IO Game
 | 
					timeStep :: Game -> IO Game
 | 
				
			||||||
timeStep g = if (currBlockStopped g)
 | 
					timeStep g = if (blockStopped g)
 | 
				
			||||||
                then return . coreUpdater $ g
 | 
					                then return . coreUpdater $ g
 | 
				
			||||||
                else stopUpdater . coreUpdater $ g
 | 
					                else stopUpdater . coreUpdater $ g
 | 
				
			||||||
  where
 | 
					  where
 | 
				
			||||||
| 
						 | 
					@ -192,17 +192,17 @@ points n = 800
 | 
				
			||||||
-- | Handle counterclockwise block rotation (if possible)
 | 
					-- | Handle counterclockwise block rotation (if possible)
 | 
				
			||||||
-- Allows wallkicks: http://tetris.wikia.com/wiki/TGM_rotation
 | 
					-- Allows wallkicks: http://tetris.wikia.com/wiki/TGM_rotation
 | 
				
			||||||
rotate :: Game -> Game
 | 
					rotate :: Game -> Game
 | 
				
			||||||
rotate g = g & currBlock .~ nextB
 | 
					rotate g = g & block .~ nextB
 | 
				
			||||||
  where nextB     = fromMaybe blk $ getFirst . mconcat $ bs
 | 
					  where nextB     = fromMaybe blk $ getFirst . mconcat $ bs
 | 
				
			||||||
        bs        = map ($ blk) safeFuncs
 | 
					        bs        = map ($ blk) safeFuncs
 | 
				
			||||||
        safeFuncs = map (mkSafe .) funcs
 | 
					        safeFuncs = map (mkSafe .) funcs
 | 
				
			||||||
        mkSafe b  = if isValidBlockPosition b brd then First (Just b) else First Nothing
 | 
					        mkSafe b  = if isValidBlockPosition b brd then First (Just b) else First Nothing
 | 
				
			||||||
        funcs     = [rotate', rotate' . translate Left, rotate' . translate Right]
 | 
					        funcs     = [rotate', rotate' . translate Left, rotate' . translate Right]
 | 
				
			||||||
        blk       = g ^. currBlock
 | 
					        blk       = g ^. block
 | 
				
			||||||
        brd       = g ^. board
 | 
					        brd       = g ^. board
 | 
				
			||||||
 | 
					
 | 
				
			||||||
currBlockStopped :: Game -> Bool
 | 
					blockStopped :: Game -> Bool
 | 
				
			||||||
currBlockStopped g = isStopped (g ^. board) (g ^. currBlock)
 | 
					blockStopped g = isStopped (g ^. board) (g ^. block)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- | Check if a block on a board is stopped from further gravitation
 | 
					-- | Check if a block on a board is stopped from further gravitation
 | 
				
			||||||
isStopped :: Board -> Block -> Bool
 | 
					isStopped :: Board -> Block -> Bool
 | 
				
			||||||
| 
						 | 
					@ -211,21 +211,21 @@ isStopped b = any (`M.member` b) . map (translate Down) . blockCoords
 | 
				
			||||||
-- | Freeze current block
 | 
					-- | Freeze current block
 | 
				
			||||||
freezeBlock :: Game -> Game
 | 
					freezeBlock :: Game -> Game
 | 
				
			||||||
freezeBlock g = g & board %~ (M.union blkMap)
 | 
					freezeBlock g = g & board %~ (M.union blkMap)
 | 
				
			||||||
  where blk    = g ^. currBlock
 | 
					  where blk    = g ^. block
 | 
				
			||||||
        blkMap = M.fromList $ zip (blk ^. to blockCoords) (repeat $ blk ^. shape)
 | 
					        blkMap = M.fromList $ zip (blk ^. to blockCoords) (repeat $ blk ^. shape)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- | Replace currBlock with next block
 | 
					-- | Replace block with next block
 | 
				
			||||||
nextBlock :: Game -> IO Game
 | 
					nextBlock :: Game -> IO Game
 | 
				
			||||||
nextBlock g = do
 | 
					nextBlock g = do
 | 
				
			||||||
  (t, ts) <- bagFourTetriminoEach (g ^. nextShapeBag)
 | 
					  (t, ts) <- bagFourTetriminoEach (g ^. nextShapeBag)
 | 
				
			||||||
  return $
 | 
					  return $
 | 
				
			||||||
    g & currBlock    .~ initBlock (g ^. nextShape)
 | 
					    g & block        .~ initBlock (g ^. nextShape)
 | 
				
			||||||
      & nextShape    .~ t
 | 
					      & nextShape    .~ t
 | 
				
			||||||
      & nextShapeBag .~ ts
 | 
					      & nextShapeBag .~ ts
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- | Try to shift current block; if shifting not possible, leave block where it is
 | 
					-- | Try to shift current block; if shifting not possible, leave block where it is
 | 
				
			||||||
shift :: Direction -> Game -> Game
 | 
					shift :: Direction -> Game -> Game
 | 
				
			||||||
shift d g = g & currBlock %~ shiftBlock
 | 
					shift d g = g & block %~ shiftBlock
 | 
				
			||||||
  where shiftBlock b = if isValidBlockPosition (translate d b) (g ^. board)
 | 
					  where shiftBlock b = if isValidBlockPosition (translate d b) (g ^. board)
 | 
				
			||||||
                          then translate d b
 | 
					                          then translate d b
 | 
				
			||||||
                          else b
 | 
					                          else b
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue