Changeset 20003 for lang/haskell/tetris/Player.hs
- Timestamp:
- 09/27/08 09:31:17 (3 months ago)
- Files:
-
- 1 modified
-
lang/haskell/tetris/Player.hs (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/haskell/tetris/Player.hs
r20002 r20003 11 11 -- constant definition 12 12 13 -- �t���[�����[�g13 -- フレームレート 14 14 frameRate = 40 15 15 16 -- �Z���̕\���T�C�Y16 -- セルの表示サイズ 17 17 cellWidth = 16 18 18 cellHeight = 16 19 19 20 -- �f�t�H���g�̗������x20 -- デフォルトの落下速度 21 21 defaultFallSpeed = 1 22 22 23 -- �������E���^23 -- 落ちるカウンタ 24 24 blockFallCount = 40 25 25 26 -- �u���b�N�����n���Ă����肳���܂ł̎���fixedTimer = frameRate `div` 2 26 -- ブロックが着地してから固定されるまでの時間 27 fixedTimer = frameRate `div` 2 27 28 28 29 -------------------------------- … … 39 40 scaleColor s (r,g,b) = (s*r, s*g, s*b) 40 41 41 -- ���̈����Ԃ�42 -- 矩形領域塗りつぶし 42 43 fill x y w h (r,g,b) = do 43 44 color3i r g b … … 53 54 iy2 = fromInteger $ toInteger $ y + h 54 55 55 -- �Z������i���Â���56 -- セルを描く(明暗あり) 56 57 renderCell col@(r,g,b) ix iy = do 57 58 fill x y (cellWidth-1) (cellHeight-1) col … … 73 74 y = iy * cellHeight 74 75 75 -- �t�B�[���h�`��enderBoard board = mapM_ lineProc $ zip [0..] board 76 -- フィールド描画 77 renderBoard board = mapM_ lineProc $ zip [0..] board 76 78 where 77 79 lineProc (iy, line) = mapM_ (cellProc iy) $ zip [0..] line … … 79 81 cellProc iy (ix, cell) = renderCell (cellColor cell) ix iy 80 82 81 -- �u���b�N����ŕ`��enderBlockTypeCol col blktype ix iy rot = do 83 -- ブロックを色つきで描画 84 renderBlockTypeCol col blktype ix iy rot = do 82 85 sequence_ $ concat $ idxmap2 proc pat 83 86 where … … 112 115 } 113 116 114 -- �u���b�N��b�h�ňړ�117 -- ブロックをパッドで移動 115 118 updateBlock :: Board -> Pad -> Block -> Block 116 119 updateBlock board pad block = … … 164 167 oldycnt = ycnt block 165 168 166 -- �u���b�N���n�ʂɂ��ČŒ肳�ꂽ���H169 -- ブロックが地面について固定されたか? 167 170 isBlockFixed block = (fixedcnt block) > fixedTimer 168 171 169 -- ���쒆�̃u���b�N�`��enderBlock block = 172 -- 操作中のブロック描画 173 renderBlock block = 170 174 renderBlockType (blktype_of block) (x block) (y block) (rot block) 171 175 172 -- �S�[�X�g�u���b�N�`��enderGhostBlock board block = 176 -- ゴーストブロック描画 177 renderGhostBlock board block = 173 178 renderBlockTypeCol col (blktype_of block) (x block) landY (rot block) 174 179 where … … 220 225 } 221 226 222 -- �ʏ펞227 -- 通常時 223 228 updatePlayerNormal pad player 224 -- �ʏ�| not (isBlockFixed block) = return $ player { block_of = block' } 225 -- �ڒn�����Ƃ��F�t�B�[���h�Ɋi�[���Ď��̃u���b�N��� 229 -- 通常 230 | not (isBlockFixed block) = return $ player { block_of = block' } 231 -- 接地したとき:フィールドに格納して次のブロックを出す 226 232 | otherwise = do 227 233 if null filled … … 239 245 filled = getFilledLines storedBoard 240 246 241 -- ���������C������������ԑ҂�247 -- そろったラインを消した後の時間待ち 242 248 updatePlayerErase filled pad player = 243 249 if (not $ null filled) && (cnt player) < (frameRate `div` 2) … … 248 254 score' = (score player) + 10 * square (length filled) 249 255 250 -- ���������C������ĉ��ɋl�߂������ԑ҂�256 -- そろったラインを消して下に詰めた後の時間待ち 251 257 updatePlayerErase2 pad player = 252 258 if (cnt player) < (frameRate `div` 2) … … 254 260 else setupNextBlock player 255 261 256 -- ���S262 -- 死亡 257 263 updatePlayerDead pad player = return player 258 264 259 -- ���̃u���b�N���265 -- 次のブロックを出す 260 266 setupNextBlock player = do 261 267 if canMove board nxtblk (x nxtBlock) (y nxtBlock) (rot nxtBlock) 262 then do -- �o������ nxt' <- randBlockType -- ���̎��̃u���b�N�𗐐��őI�� return $ player { block_of = nxtBlock, nxtblktype = nxt', stat = PlNormal, updater = updatePlayerNormal } 263 else do -- �l�܂�Ă����S 268 then do -- 登場できる 269 nxt' <- randBlockType -- 次の次のブロックを乱数で選ぶ 270 return $ player { block_of = nxtBlock, nxtblktype = nxt', stat = PlNormal, updater = updatePlayerNormal } 271 else do -- 詰まってる:死亡 264 272 let storedBoard = storeBlock board nxtblk (x nxtBlock) (y nxtBlock) (rot nxtBlock) 265 273 return $ player { board_of = storedBoard, stat = PlDead, updater = updatePlayerDead } 266 274 where 267 nxtblk = nxtblktype player -- ���̃u���b�N�̎�275 nxtblk = nxtblktype player -- 次のブロックの種類 268 276 nxtBlock = newBlock nxtblk nxtFallSpd 269 277 nxtFallSpd = if curFallSpd < blockFallCount then curFallSpd + 1 else defaultFallSpeed … … 272 280 273 281 274 -- �X�V282 -- 更新 275 283 updatePlayer :: Pad -> Player -> IO Player 276 284 updatePlayer pad player = (updater player) pad player
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)