When a block in Tetris reaches the bottom, the block is no more: all the squares of the block will be added to another container: the ‘pile’. This ‘Pile’ class also needs a memory container to hold squares. It also needs methods to simplify the interaction with this pile.
class pile
{
private:
Memx<square> list;
5
bool canMove (C square & s, DIRECTION dir) C {}
void removeRow(int row ) C {}
public:
10 void init() {}
bool collides(C block & b, DIRECTION dir) C {}
void add (C block & b ) {}
15 int checkLines() {}
void draw () C {}
}
pile Pile;
20
It is also possible to create a test application for this class. In this app, you can manually add a few blocks to the pile and show this pile on the screen. The collides method can be tested by creating another block in the application and moving it. This is an example of a possible test:
if(Kb.bp(KB_DOWN) && !Pile.collides(myBlock, D_DOWN)) {
myBlock.move(D_DOWN);
}
The check method can be tested by calling it on pressing the space bar. Of course you first need to add enough blocks to the pile to form a solid line.