17.2 Blocks

Now add a code file ‘block’ in the folder ‘Tetris parts/objects’. Create the class block in that file. Just like a square, a block has a position and a type. But in addition, a block is a bunch of squares. So you need a container for squares inside a block.

And then there are methods.  eeClassblock needs a create method, just like a square. And we also provide a second create method with other arguments to copy an existing block.

We also need methods to move, rotate and draw a block. And finally we need a method to retrieve the type of a block and a method which returns the list of squares inside the block. These methods only contain a return statement. Because your test application will not work as long as these methods don’t contain a return statement, they are already present in the code below. The result is this class:

 
class block 
{ 
private
   VecI2        pos    ; 
5   BLOCK_TYPE   type   ; 
   Mems<square> squares; 
 
public
   void create(C VecI2 & pos  , BLOCK_TYPE type) { } 
10   void create(C block & other                 ) { } 
 
   void move  (DIRECTION dir)   { } 
   void rotate(             )   { } 
   void draw  (             ) C { } 
15 
   BLOCK_TYPE       getType   () C { return type   ; } 
   C Mems<square> & getSquares() C { return squares; } 
}  

Add this code in the file ‘block’ that you created before. Now create a new application ‘block tester’. Add code in this application to test a block. This time you do not need a container. Just declare a block and use the create, move, rotate and draw methods. The extra create method and the methods getSquares() and {eeFuncgetType() should not be used yet.