Show
Ignore:
Timestamp:
10/03/08 01:04:54 (3 months ago)
Author:
mokehehe
Message:

Existence 型を使って書き換え

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/haskell/nario/Main.hs

    r20453 r20534  
     1{-# OPTIONS_GHC -fglasgow-exts #-} 
     2 
    13-- Nario 
    24 
     
    7476 
    7577---- 
     78data ObjWrapper = forall a. Actor a => ObjWrapper a     -- 存在型aの動く範囲を型クラスDuckに制限 
     79 
     80updateActors :: [ObjWrapper] -> [(ObjWrapper, [Event])] 
     81updateActors = map (\(ObjWrapper x) -> let (x', ev') = update x in (ObjWrapper x', ev')) 
     82 
     83renderActors :: ImageResource -> Int -> Surface -> [ObjWrapper] -> IO () 
     84renderActors imgres ofsx sur = mapM_ (\(ObjWrapper x) -> render x imgres ofsx sur) 
    7685 
    7786 
     
    8190                pl :: Player, 
    8291                fld :: Field, 
    83                 actors :: [Actor], 
     92                actors :: [ObjWrapper], 
    8493                time :: Int 
    8594        } 
     
    134143                                time' = max 0 (time gs - one `div` 25) 
    135144                                (pl', ev) = updatePlayer kp (fld gs) (pl gs) 
    136                                 actors_updates = map updateActor (actors gs) 
     145                                actors_updates = updateActors (actors gs) 
    137146                                actors' = map fst actors_updates 
    138147                                ev' = concatMap snd actors_updates 
     
    153162                        where 
    154163                                fld' = fieldSet (fld gs) cx cy '*' 
    155                                 actors' = (newAnimBlock cx cy) : actors gs 
     164                                actors' = (ObjWrapper $ newAnimBlock cx cy) : actors gs 
    156165                f gs (EvSetField cx cy c) = gs { fld = fld' } 
    157166                        where 
     
    170179        renderPlayer sur imgres scrx (pl gs) 
    171180 
    172         mapM_ (\act -> renderActor act imgres scrx sur) (actors gs) 
     181        renderActors imgres scrx sur (actors gs) 
    173182        return () 
    174183