package eecs2030.lab4; import java.awt.Color; import java.util.ArrayList; import java.util.List; /** * The standard 3x3 S-shaped Tetris block. * * @author EECS2030 Fall 2016 * */ public class SBlock extends Block { private List grids; private int gridIndex; /** * Create an S-block tetrimino at the given position and the given * color. The S-block is created with the starting orientation * as shown in the lab description. * * @param pos the position of the S-block * @param col the color of the S-block */ public SBlock(Point2 pos, Color col) { super(3, pos, col); this.grids = new ArrayList(); BlockGrid g = this.grid; g.set(0, 1); g.set(0, 2); g.set(1, 0); g.set(1, 1); this.grids.add(g); g = new BlockGrid(3); g.set(0, 1); g.set(1, 1); g.set(1, 2); g.set(2, 2); this.grids.add(g); g = new BlockGrid(3); g.set(1, 1); g.set(1, 2); g.set(2, 0); g.set(2, 1); this.grids.add(g); g = new BlockGrid(3); g.set(0, 0); g.set(1, 0); g.set(1, 1); g.set(2, 1); this.grids.add(g); this.gridIndex = 0; } /** * Spins the block to the left (counter clockwise) by 90 degrees about its * center of rotation. The S * block center of rotation is 1.5 units right and 1.5 units down from the * top left corner of the 3x3 grid. * */ @Override public void spinLeft() { this.gridIndex--; if (this.gridIndex == -1) { this.gridIndex = 3; } this.grid = this.grids.get(this.gridIndex); } /** * Spins the block to the right (clockwise) by 90 degrees about its center * of rotation. The S block * center of rotation is 1.5 units right and 1.5 units down from the top * left corner of the 3x3 grid. * */ @Override public void spinRight() { this.gridIndex++; if (this.gridIndex == 4) { this.gridIndex = 0; } this.grid = this.grids.get(this.gridIndex); } }