...

/

Step 3: The Block class

Step 3: The Block class

Add a new class to represent and draw individual square blocks in the Tetrominos game.

Each falling piece in Tetrominos is made up of four small blocks arranged in a particular way. Let’s write and test the Block class. Create a new file in your project called Block.java. To get you started, here’s a skeleton of the code, which you may copy in:

import java.awt.Color;
import java.awt.Graphics;
class Block {
public int colorIndex;
public static Color[] colors = {Color.red, Color.blue, Color.magenta,
Color.orange, Color.green, Color.cyan, Color.yellow};
public Block(int colorIndex) {
}
public void draw(Graphics g, int scale, int x, int y) {
}
}

Task: write the constructor

Blocks ...