Tetris in XNA with F#

Saturday, April 11, 2009 by gradbot

I learned a few things on this project. One is that arrays are not the end all of data structures. My first instinct from my C++ background was to make a 2D array for the tetris game board. After wasting an hour or two I realized that it was over complicated and that a Set would work really well.

Basically each piece in the game is a set of tuple points. The game board boarder is a set of tuple points and the already fallen pieces is a set of pieces. I had to keep the concept of a piece in order to keep the color associated with each tuple point. This setup made collision detection simple. It was just a matter of Seq.union_all and Set.intersect

I'm pretty amazed by the relatively few lines of code it took me to recreate the game. The main game logic is incredibly small. Most of the code is spent setting up the system and handling user input/graphics.

Project Time: 13 hours
Project - Source Code

The game is played with the DPad and A/B buttons.

Filed under , , having