Showing posts with label haskell. Show all posts
Showing posts with label haskell. Show all posts

Wednesday, April 8, 2009

Reflections on Falling Blocks

There were various things I liked and didn't like about my code for Falling Blocks.

Liked:
  • The code for block rotation and row removal. The board code got a little complicated (due to an experiment that I kept), but I had tests that made getting that code correct a quick process. I got this working first and really didn't have to touch it again.
  • The way the current 'screen' is implemented - just functions in the game state. (Two functions - one like an OO MVC 'controller' and one like a 'view'.)
  • Relatively short. Under 500 lines without tests/comments. Probably could be shorter.
Didn't like:
  • Testing was hard. It seemed like there was a lot of setup for a simple test. I ended up exposing more of a given module than I wanted to make sure that functions that were just used in the module were working correctly. In the end, I wrote far fewer tests than I would have liked. I think a lot of this boils down to not factoring my code well - still trying to figure out how do to that in Haskell.
  • Also, not sure how to only test 'part' of something. If A uses B which uses C - how to test A without needing to test the rest. I want to stub or mock the rest, but don't know how.
  • Some of the code got too complicated (for example, the 'move' method isn't pretty). For a lot of the code, I didn't feel like I was 'gluing simple functions together'.
Any suggestions on the code are more than welcome.

Sunday, March 29, 2009

Falling Blocks - A Tetris clone in Haskell using SDL

Falling Blocks my first Haskell game. It is a Tetris clone that uses SDL.

While asking some questions on IRC, someone asked me if I had put the project up on Hackage. It hadn't really occurred to me before - I thought of Hackage mainly for libraries. But I decided that there could be more examples of using SDL and the Haskell bindings for it.

The code can be found as a darcs repo at:
http://patch-tag.com/publicrepos/fallingblocks

And can be found on Hackage here:
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/fallingblocks

Play is simple:
  • Use the left/right arrow keys to move the block horizontally
  • Use the up arrow to rotate the block
  • Use the down arrow to move the block down more quickly
  • Press p to pause/unpause (0.1.4 +)
  • Press q to quit.
Thank you to everyone that helped me with this - especially those that helped me get the packaging working correctly.

A few screenshots:


Finally, a video Don Stewart put up on YouTube. Ignore the errors - those should be fixed now.