Battle Tetris

Battle Tetris is a simple, no-frills, two-player Tetris clone. The premiss is simple. You and a opponent battle against each other head-to-head. Each time a player makes a two or four line combo, two or four lines of junk is added to the opponent’s pile. First pile to the top looses.

I wrote this program as a challenge to try to figure out the logic of the classic Tetris game. After several failed attemps, I finally got it. This program has several unique archatectural features. First off, the TetrisBoard class is a self contained class representing the game. It handles all game logic and collision checking, as well as serving as a viewport for the board to draw itself on.

When it came to the board, I came to the conclusion that it was nothing more than a two dimensional array of Block objects, and the falling chunk was just a moving formation of blocks. I modled this with the Block and Chunk classes. The trick to the Chunk class is that it does not model any particular type of falling chunk. Instead, it treats itself as simply a formation of Block objects and thus can be configured in any way imaginable at runtime. To create the unique Chunk formations used in the game, I used the abstract factory pattern and a class called ChunkFactory. The job of the ChunkFactory is to create a new random chunk formation upon request. Feel free to add your own formations here.