Formatting only
This commit is contained in:
		
							parent
							
								
									ccbd9d8e36
								
							
						
					
					
						commit
						b3d812bee5
					
				
					 1 changed files with 119 additions and 101 deletions
				
			
		| 
						 | 
				
			
			@ -45,7 +45,8 @@ data TVisual = Normal | HardDrop
 | 
			
		|||
-- App definition and execution
 | 
			
		||||
 | 
			
		||||
app :: App UI Tick Name
 | 
			
		||||
app = App { appDraw = drawUI
 | 
			
		||||
app = App
 | 
			
		||||
  { appDraw         = drawUI
 | 
			
		||||
  , appChooseCursor = neverShowCursor
 | 
			
		||||
  , appHandleEvent  = handleEvent
 | 
			
		||||
  , appStartEvent   = return
 | 
			
		||||
| 
						 | 
				
			
			@ -79,8 +80,8 @@ handleEvent ui (VtyEvent (V.EvKey (V.KChar 'h') [])) = exec (shift Left) ui
 | 
			
		|||
handleEvent ui (VtyEvent (V.EvKey (V.KChar 'j') [])) = exec (shift Down) ui
 | 
			
		||||
handleEvent ui (VtyEvent (V.EvKey V.KUp         [])) = exec rotate ui
 | 
			
		||||
handleEvent ui (VtyEvent (V.EvKey (V.KChar 'k') [])) = exec rotate ui
 | 
			
		||||
handleEvent ui (VtyEvent (V.EvKey (V.KChar ' ') [])) = continue $ ui & game %~ execTetris hardDrop
 | 
			
		||||
                                                                     & locked .~ True
 | 
			
		||||
handleEvent ui (VtyEvent (V.EvKey (V.KChar ' ') [])) =
 | 
			
		||||
  continue $ ui & game %~ execTetris hardDrop & locked .~ True
 | 
			
		||||
handleEvent ui (VtyEvent (V.EvKey (V.KChar 'r') [])) = restart ui
 | 
			
		||||
handleEvent ui (VtyEvent (V.EvKey (V.KChar 'q') [])) = halt ui
 | 
			
		||||
handleEvent ui (VtyEvent (V.EvKey V.KEsc        [])) = halt ui
 | 
			
		||||
| 
						 | 
				
			
			@ -117,19 +118,22 @@ restart ui = do
 | 
			
		|||
 | 
			
		||||
drawUI :: UI -> [Widget Name]
 | 
			
		||||
drawUI ui =
 | 
			
		||||
  [ C.vCenter $ vLimit 22 $ hBox [ padLeft Max $ padRight (Pad 2) $ drawStats (ui ^. game)
 | 
			
		||||
  [ C.vCenter $ vLimit 22 $ hBox
 | 
			
		||||
      [ padLeft Max $ padRight (Pad 2) $ drawStats (ui ^. game)
 | 
			
		||||
      , drawGrid ui
 | 
			
		||||
      , padRight Max $ padLeft (Pad 2) $ drawInfo (ui ^. game)
 | 
			
		||||
      ]
 | 
			
		||||
  ]
 | 
			
		||||
 | 
			
		||||
drawGrid :: UI -> Widget Name
 | 
			
		||||
drawGrid ui = hLimit 22
 | 
			
		||||
drawGrid ui =
 | 
			
		||||
  hLimit 22
 | 
			
		||||
    $ withBorderStyle BS.unicodeBold
 | 
			
		||||
    $ B.borderWithLabel (str "Tetris")
 | 
			
		||||
    $ vBox rows
 | 
			
		||||
 where
 | 
			
		||||
    rows = [foldr (<+>) emptyWidget $ M.filterWithKey (inRow r) gmap
 | 
			
		||||
  rows =
 | 
			
		||||
    [ foldr (<+>) emptyWidget $ M.filterWithKey (inRow r) gmap
 | 
			
		||||
    | r <- [boardHeight, boardHeight - 1 .. 1]
 | 
			
		||||
    ]
 | 
			
		||||
  inRow r (V2 _ y) _ = r == y
 | 
			
		||||
| 
						 | 
				
			
			@ -137,9 +141,9 @@ drawGrid ui = hLimit 22
 | 
			
		|||
  brdMap  = draw Normal . Just <$> g ^. board
 | 
			
		||||
  hrdMap  = blkMap (evalTetris hardDroppedBlock g) HardDrop
 | 
			
		||||
  cBlkMap = blkMap (g ^. block) Normal
 | 
			
		||||
    blkMap b v = M.fromList . map (, draw v . Just $ b ^. shape) $ coords b
 | 
			
		||||
  draw    = drawMCell (ui ^. preview) InGrid
 | 
			
		||||
  g       = ui ^. game
 | 
			
		||||
  blkMap b v = M.fromList . map (, draw v . Just $ b ^. shape) $ coords b
 | 
			
		||||
 | 
			
		||||
emptyCellMap :: Map Coord (Widget Name)
 | 
			
		||||
emptyCellMap = M.fromList cws
 | 
			
		||||
| 
						 | 
				
			
			@ -147,7 +151,8 @@ emptyCellMap = M.fromList cws
 | 
			
		|||
  cws = [ ((V2 x y), ew) | x <- [1 .. boardWidth], y <- [1 .. boardHeight] ]
 | 
			
		||||
  ew  = drawMCell Nothing InGrid Normal Nothing
 | 
			
		||||
 | 
			
		||||
drawMCell :: Maybe String -> CellLocation -> TVisual -> Maybe Tetrimino -> Widget Name
 | 
			
		||||
drawMCell
 | 
			
		||||
  :: Maybe String -> CellLocation -> TVisual -> Maybe Tetrimino -> Widget Name
 | 
			
		||||
drawMCell _  InGrid      _ Nothing  = withAttr emptyAttr cw
 | 
			
		||||
drawMCell _  InNextShape _ Nothing  = withAttr emptyAttr ecw
 | 
			
		||||
drawMCell mp _           v (Just t) = drawCell mp t v
 | 
			
		||||
| 
						 | 
				
			
			@ -185,45 +190,58 @@ hcw :: Widget Name
 | 
			
		|||
hcw = str "◤◢"
 | 
			
		||||
 | 
			
		||||
drawStats :: Game -> Widget Name
 | 
			
		||||
drawStats g = hLimit 22
 | 
			
		||||
drawStats g =
 | 
			
		||||
  hLimit 22
 | 
			
		||||
    $ withBorderStyle BS.unicodeBold
 | 
			
		||||
    $ B.borderWithLabel (str "Stats")
 | 
			
		||||
  $ vBox [ drawStat "Score" $ g ^. score
 | 
			
		||||
    $ vBox
 | 
			
		||||
        [ drawStat "Score" $ g ^. score
 | 
			
		||||
        , padTop (Pad 1) $ drawStat "Level" $ g ^. level
 | 
			
		||||
        , drawLeaderBoard g
 | 
			
		||||
        ]
 | 
			
		||||
 | 
			
		||||
drawStat :: String -> Int -> Widget Name
 | 
			
		||||
drawStat s n = padLeftRight 1
 | 
			
		||||
  $ str s <+> (padLeft Max $ str $ show n)
 | 
			
		||||
drawStat s n = padLeftRight 1 $ str s <+> (padLeft Max $ str $ show n)
 | 
			
		||||
 | 
			
		||||
drawLeaderBoard :: Game -> Widget Name
 | 
			
		||||
drawLeaderBoard _ = emptyWidget
 | 
			
		||||
 | 
			
		||||
drawInfo :: Game -> Widget Name
 | 
			
		||||
drawInfo g = hLimit 18 -- size of next piece box
 | 
			
		||||
  $ vBox [ drawNextShape (g ^. nextShape)
 | 
			
		||||
  $ vBox
 | 
			
		||||
    [ drawNextShape (g ^. nextShape)
 | 
			
		||||
    , padTop (Pad 2) $ drawHelp
 | 
			
		||||
    , padTop (Pad 1) $ drawGameOver g
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
drawNextShape :: Tetrimino -> Widget Name
 | 
			
		||||
drawNextShape t = withBorderStyle BS.unicodeBold
 | 
			
		||||
drawNextShape t =
 | 
			
		||||
  withBorderStyle BS.unicodeBold
 | 
			
		||||
    $   B.borderWithLabel (str "Next")
 | 
			
		||||
  $ padTopBottom 1 $ padLeftRight 4
 | 
			
		||||
    $   padTopBottom 1
 | 
			
		||||
    $   padLeftRight 4
 | 
			
		||||
    $   vLimit 4
 | 
			
		||||
  $ vBox $ mkRow <$> [0,-1]
 | 
			
		||||
    $   vBox
 | 
			
		||||
    $   mkRow
 | 
			
		||||
    <$> [0, -1]
 | 
			
		||||
 where
 | 
			
		||||
    mkRow y = hBox $ drawMCell Nothing InNextShape Normal . cellAt . (`V2` y) <$> [-2..1]
 | 
			
		||||
  mkRow y =
 | 
			
		||||
    hBox
 | 
			
		||||
      $   drawMCell Nothing InNextShape Normal
 | 
			
		||||
      .   cellAt
 | 
			
		||||
      .   (`V2` y)
 | 
			
		||||
      <$> [-2 .. 1]
 | 
			
		||||
  cellAt (V2 x y) = if (V2 x y) `elem` cs then Just t else Nothing
 | 
			
		||||
  blk = Block t (V2 0 0) (relCells t)
 | 
			
		||||
  cs  = blk ^. to coords
 | 
			
		||||
 | 
			
		||||
drawHelp :: Widget Name
 | 
			
		||||
drawHelp = withBorderStyle BS.unicodeBold
 | 
			
		||||
drawHelp =
 | 
			
		||||
  withBorderStyle BS.unicodeBold
 | 
			
		||||
    $ B.borderWithLabel (str "Help")
 | 
			
		||||
    $ padTopBottom 1
 | 
			
		||||
  $ vBox $ map (uncurry drawKeyInfo)
 | 
			
		||||
    $ vBox
 | 
			
		||||
    $ map (uncurry drawKeyInfo)
 | 
			
		||||
    $ [ ("Left"   , "h, ←")
 | 
			
		||||
      , ("Right"  , "l, →")
 | 
			
		||||
      , ("Down"   , "j, ↓")
 | 
			
		||||
| 
						 | 
				
			
			@ -239,12 +257,14 @@ drawKeyInfo action keys =
 | 
			
		|||
    <+> (padLeft Max $ padRight (Pad 1) $ str keys)
 | 
			
		||||
 | 
			
		||||
drawGameOver :: Game -> Widget Name
 | 
			
		||||
drawGameOver g = if (isGameOver g)
 | 
			
		||||
drawGameOver g =
 | 
			
		||||
  if (isGameOver g)
 | 
			
		||||
  then padLeftRight 4 $ withAttr gameOverAttr $ str "GAME OVER"
 | 
			
		||||
  else emptyWidget
 | 
			
		||||
 | 
			
		||||
theMap :: AttrMap
 | 
			
		||||
theMap = attrMap V.defAttr
 | 
			
		||||
theMap = attrMap
 | 
			
		||||
  V.defAttr
 | 
			
		||||
  [ (iAttr       , tToColor I `on` tToColor I)
 | 
			
		||||
  , (oAttr       , tToColor O `on` tToColor O)
 | 
			
		||||
  , (tAttr       , tToColor T `on` tToColor T)
 | 
			
		||||
| 
						 | 
				
			
			@ -252,8 +272,6 @@ theMap = attrMap V.defAttr
 | 
			
		|||
  , (zAttr       , tToColor Z `on` tToColor Z)
 | 
			
		||||
  , (jAttr       , tToColor J `on` tToColor J)
 | 
			
		||||
  , (lAttr       , tToColor L `on` tToColor L)
 | 
			
		||||
  -- attributes for hard drop preview (would be VERY clean if I could figure out how to
 | 
			
		||||
  -- query for default background color.. alas
 | 
			
		||||
  , (ihAttr      , fg $ tToColor I)
 | 
			
		||||
  , (ohAttr      , fg $ tToColor O)
 | 
			
		||||
  , (thAttr      , fg $ tToColor T)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue