Friday, April 15, 2011

How much time does it take to implement a simple Tetris game?

There’s been a short discussion on one of console forums on how long does it take to implement a simple Tetris game. Personally I’ve never done this before but if you think about it, there are just few things to take care of. It should not take long then.

But how long exactly? An hour? Ten hours?

Well, let’s start with the list of requirements:

  • the game should be “playable” which means that common Tetris rules must be implemented
  • blocks should appear randomly at the top of the board
  • blocks should automatically move down until they are blocked by the border of the board or by other blocks
  • blocks should be “movable”, legal moves include “right/left/rotate” but only if they are legal (move does not position a block in an illegal position)
  • completely filled lines should automatically disappear causing all the lines above to move down
  • the game should count your score (depending on the number of cleared lines) and should end when it’s illegal to introduce a new block after the previous one has been blocked

My first rough estimation was 2-3 hours but I’ve decided to accept the challenge.

It turned out that the implementation, starting from complete scratch and ending up with playable game (screenshot below) took around 100 minutes (1 hour and 40 minutes). No prior preparations, no available code snippets, just me, the C# compiler and all the classes from the System.Windows.Forms namespace.

Can you stand for the challenge? How much time do you need to imlement such simple game in your favourite language/technology (assuming that you have never done that before so you will not just be rewriting some of your prior ideas)?

Well, happy coding. Share your comments on that.

Download binary & source code here (25kB). The game is playable so have fun. Study the sources only if you do not plan to try on your own first :)

1 comment:

drx said...

W 0:30 słychać strzały.