Friday 13 February 2009

Tetris : the implementation of a classical game in Objective-C/Cocoa

First of all the source code of the game can be found here. Background for the game can be found on wikipedia.

This implementation is a first attempt to implement it, in this version I was more intrested to get it to work than in the nice graphical aspects.
As you can see in the picture , it surely won't win a prize as the most sexy application :-).



This game again is an implementation of the classical MVC design pattern, with the difference that their are 2 views.

The model is a TetrisBoard (subclass of Board) on which you can move a piece (the so-called Tetrominoe (superclass of a set of pieces)).
The tetrominoe is the abstract superclass of all the tetrominoe's. It's very handy to model the pieces as a class, later on I can add things like a skin, or a another way of rotating. 

There are 2 views, the TetrisView and the TetrominoeView. The first one is the graphical representation of the  TetrisBoard; the second shows the next tetrominoe.

The model and the view(s) are connected via the TetrisController.

2 comments:

  1. jezus, herman, tetris, zal eens in opleiding moeten komen, kun je hiervoor een MVC van smalltalk gebruiken ... ;-) , gr Jan

    ReplyDelete
  2. Ja inderdaad, ben me een beetje aan het amuseren met de Iphone, Ipod e.d. Deze was een POC , ik ben het nu een beetje sexier aan het maken en misschien publiceer ik het wel op AppStore.

    Ik heb trouwens nog veel meer in petto

    ReplyDelete