Changeset 20003 for lang/haskell

Show
Ignore:
Timestamp:
09/27/08 09:31:17 (2 months ago)
Author:
mokehehe
Message:

ソースの文字コードを utf-8 に変更

Location:
lang/haskell/tetris
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • lang/haskell/tetris/Board.hs

    r20002 r20003  
    4444blockCell BlockT = Cyan 
    4545 
    46 -- �����Ńu���b�N���randBlockType = randN (length blockTypes) >>= return . (blockTypes !!) 
     46-- 乱数でブロックを選ぶ 
     47randBlockType = randN (length blockTypes) >>= return . (blockTypes !!) 
    4748 
    4849blockTypes = [BlockI, BlockO, BlockS, BlockZ, BlockJ, BlockL, BlockT] 
  • lang/haskell/tetris/Main.hs

    r20002 r20003  
    1515screenHeight = 400 
    1616 
    17 -- �^�C�}�̊Ԋu 
     17-- タイマの間隔 
    1818timerInterval = 1000 `div` frameRate 
    1919 
    2020-------------------------------- 
    21 -- �G���g�� 
     21-- エントリ 
    2222 
    2323data GameStat = Title | Game | GameOver 
     
    2828        padRef <- newIORef newPad 
    2929 
    30         --GLUT�̏���initialDisplayMode $= [RGBAMode, DoubleBuffered] 
     30        --GLUTの初期化 
     31        initialDisplayMode $= [RGBAMode, DoubleBuffered] 
    3132        initialWindowSize $= Size screenWidth screenHeight 
    3233 
    33         --�E�B���h�E���createWindow "Tetris in Haskell & GLUT" 
     34        --ウィンドウを作る 
     35        createWindow "Tetris in Haskell & GLUT" 
    3436 
    35         --�\���Ɏg���R�[���o�b�N�֐��̎w��displayCallback $= display gameStatRef playerRef 
     37        --表示に使うコールバック関数の指定 
     38        displayCallback $= display gameStatRef playerRef 
    3639 
    37         --�L�[�{�[�h���E�X�̃R�[���o�b�N 
     40        --キーボードやマウスのコールバック 
    3841        keyboardMouseCallback $= Just (keyboardProc padRef) 
    3942 
    40         --�^�C�}���setTimerProc gameStatRef playerRef padRef 
     43        --タイマを作る 
     44        setTimerProc gameStatRef playerRef padRef 
    4145 
    42         --GLUT�̃��C�����[�v�ɓ�ainLoop 
     46        --GLUTのメインループに入る 
     47        mainLoop 
    4348 
    4449 
    45 --�L�[����� 
     50--キー入力の処理 
    4651keyboardProc _ (Char 'q') _ _ _ = exitWith ExitSuccess 
    4752keyboardProc padRef key Down _ _ = modifyIORef padRef (\pad -> pad { pressed = union [key] (pressed pad) }) 
     
    5055 
    5156 
    52 -- �^�C�}���荞�ݐݒ�etTimerProc gameStatRef playerRef padRef = do 
     57-- タイマ割り込み設定 
     58setTimerProc gameStatRef playerRef padRef = do 
    5359        writeIORef gameStatRef Title 
    5460        setNext $ titleProc 
     
    5763                setNext = addTimerCallback timerInterval 
    5864 
    59                 -- �^�C�g�� 
     65                -- タイトル 
    6066                titleProc = do 
    6167                        modifyIORef padRef updatePad 
     
    7278                                        setNext $ titleProc 
    7379 
    74                 -- �Q�[���� 
     80                -- ゲーム中 
    7581                gameProc = do 
    7682                        modifyIORef padRef updatePad 
     
    8894                                        setNext $ gameoverProc 
    8995 
    90                 -- �Q�[���I�[�o�[ 
     96                -- ゲームオーバー 
    9197                gameoverProc = gameoverProc2 0 
    9298                gameoverProc2 y = do 
     
    121127 
    122128 
    123 -- ������� 
     129-- 文字列表示 
    124130putText x y str = 
    125131        preservingMatrix $ do 
     
    129135 
    130136 
    131 -- �\�� 
     137-- 表示 
    132138display gameStatRef playerRef = do 
    133139        gameStat <- readIORef gameStatRef 
    134140        player <- readIORef playerRef 
    135141 
    136         --�w�i��ɂ���clear [ColorBuffer] 
     142        --背景を黒にする 
     143        clear [ColorBuffer] 
    137144 
    138         --�P�ʍs��ǂݍ���  loadIdentity 
     145        --単位行列を読み込む 
     146        loadIdentity 
    139147 
    140         --�\�� 
     148        --表示 
    141149        renderPlayer player 
    142150 
     
    156164        putText 200 240 "ROT: Space, Z" 
    157165 
    158         --�o�b�t�@�̓�� 
     166        --バッファの入れ替え 
    159167        swapBuffers 
  • lang/haskell/tetris/Pad.hs

    r20002 r20003  
    1717 
    1818data Pad = Pad { 
    19         pressed :: [Key],       -- ���݉��������[ 
    20         btn :: Int,                     -- ���������^�� 
    21         obtn :: Int,            -- �O�񉟂������{�^�� 
    22         trig :: Int,            -- �����ꂽ�u�Ԃ̃{�^�� 
    23         rpt :: Int,                     -- �����ꑱ���Ă��^�� 
    24         rptc :: Int                     -- ���s�[�g�p�J�E���^ 
     19        pressed :: [Key],       -- 現在押されてるキー 
     20        btn :: Int,                     -- 押されてるボタン 
     21        obtn :: Int,            -- 前回押されてたボタン 
     22        trig :: Int,            -- 押された瞬間のボタン 
     23        rpt :: Int,                     -- 押され続けてるボタン 
     24        rptc :: Int                     -- リピート用カウンタ 
    2525} 
    2626 
     
    5151                btnValue _                      =       0 
    5252 
    53 repeatCnt1 = 7          -- ���s�[�g�������repeatCnt2 = 1                -- ���s�[�g�Q��ȍ~�̎���repeatBtn = padL .|. padR         -- ���s�[�g�Ŏg���{�^�� 
     53repeatCnt1 = 7          -- リピート初回の時間 
     54repeatCnt2 = 1          -- リピート2回目以降の時間 
     55repeatBtn = padL .|. padR               -- リピートで使うボタン 
    5456 
    5557updatePad pad = 
  • lang/haskell/tetris/Player.hs

    r20002 r20003  
    1111-- constant definition 
    1212 
    13 -- �t���[�����[�g 
     13-- フレームレート 
    1414frameRate = 40 
    1515 
    16 -- �Z���̕\���T�C�Y 
     16-- セルの表示サイズ 
    1717cellWidth  = 16 
    1818cellHeight = 16 
    1919 
    20 -- �f�t�H���g�̗������x 
     20-- デフォルトの落下速度 
    2121defaultFallSpeed = 1 
    2222 
    23 -- �������E���^ 
     23-- 落ちるカウンタ 
    2424blockFallCount = 40 
    2525 
    26 -- �u���b�N�����n���Ă����肳���܂ł̎���fixedTimer = frameRate `div` 2 
     26-- ブロックが着地してから固定されるまでの時間 
     27fixedTimer = frameRate `div` 2 
    2728 
    2829-------------------------------- 
     
    3940scaleColor s (r,g,b) = (s*r, s*g, s*b) 
    4041 
    41 -- ���̈����Ԃ� 
     42-- 矩形領域塗りつぶし 
    4243fill x y w h (r,g,b) = do 
    4344        color3i r g b 
     
    5354                iy2 = fromInteger $ toInteger $ y + h 
    5455 
    55 -- �Z������i���Â��� 
     56-- セルを描く(明暗あり) 
    5657renderCell col@(r,g,b) ix iy = do 
    5758        fill x y (cellWidth-1) (cellHeight-1) col 
     
    7374                y = iy * cellHeight 
    7475 
    75 -- �t�B�[���h�`��enderBoard board = mapM_ lineProc $ zip [0..] board 
     76-- フィールド描画 
     77renderBoard board = mapM_ lineProc $ zip [0..] board 
    7678        where 
    7779                lineProc (iy, line) = mapM_ (cellProc iy) $ zip [0..] line 
     
    7981                cellProc iy (ix, cell)  = renderCell (cellColor cell) ix iy 
    8082 
    81 -- �u���b�N��‚��ŕ`��enderBlockTypeCol col blktype ix iy rot = do 
     83-- ブロックを色つきで描画 
     84renderBlockTypeCol col blktype ix iy rot = do 
    8285        sequence_ $ concat $ idxmap2 proc pat 
    8386        where 
     
    112115} 
    113116 
    114 -- �u���b�N��b�h�ňړ� 
     117-- ブロックをパッドで移動 
    115118updateBlock :: Board -> Pad -> Block -> Block 
    116119updateBlock board pad block = 
     
    164167                oldycnt = ycnt block 
    165168 
    166 -- �u���b�N���n�ʂɂ‚��ČŒ肳�ꂽ���H 
     169-- ブロックが地面について固定されたか? 
    167170isBlockFixed block = (fixedcnt block) > fixedTimer 
    168171 
    169 -- ���쒆�̃u���b�N�`��enderBlock block = 
     172-- 操作中のブロック描画 
     173renderBlock block = 
    170174        renderBlockType (blktype_of block) (x block) (y block) (rot block) 
    171175 
    172 -- �S�[�X�g�u���b�N�`��enderGhostBlock board block = 
     176-- ゴーストブロック描画 
     177renderGhostBlock board block = 
    173178        renderBlockTypeCol col (blktype_of block) (x block) landY (rot block) 
    174179        where 
     
    220225        } 
    221226 
    222 -- �ʏ펞 
     227-- 通常時 
    223228updatePlayerNormal 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        -- 接地したとき:フィールドに格納して次のブロックを出す 
    226232        | otherwise     = do 
    227233                if null filled 
     
    239245                filled = getFilledLines storedBoard 
    240246 
    241 -- ���������C������������ԑ҂� 
     247-- そろったラインを消した後の時間待ち 
    242248updatePlayerErase filled pad player = 
    243249        if (not $ null filled) && (cnt player) < (frameRate `div` 2) 
     
    248254                score' = (score player) + 10 * square (length filled) 
    249255 
    250 -- ���������C������ĉ��ɋl�߂������ԑ҂� 
     256-- そろったラインを消して下に詰めた後の時間待ち 
    251257updatePlayerErase2 pad player = 
    252258        if (cnt player) < (frameRate `div` 2) 
     
    254260                else    setupNextBlock player 
    255261 
    256 -- ���S 
     262-- 死亡 
    257263updatePlayerDead pad player = return player 
    258264 
    259 -- ���̃u���b�N��� 
     265-- 次のブロックを出す 
    260266setupNextBlock player = do 
    261267        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         -- 詰まってる:死亡 
    264272                        let storedBoard = storeBlock board nxtblk (x nxtBlock) (y nxtBlock) (rot nxtBlock) 
    265273                        return $ player { board_of = storedBoard, stat = PlDead, updater = updatePlayerDead } 
    266274        where 
    267                 nxtblk = nxtblktype player              -- ���̃u���b�N�̎� 
     275                nxtblk = nxtblktype player              -- 次のブロックの種類 
    268276                nxtBlock = newBlock nxtblk nxtFallSpd 
    269277                nxtFallSpd = if curFallSpd < blockFallCount then curFallSpd + 1 else defaultFallSpeed 
     
    272280 
    273281 
    274 -- �X�V 
     282-- 更新 
    275283updatePlayer :: Pad -> Player -> IO Player 
    276284updatePlayer pad player = (updater player) pad player