import java.awt.*; import java.util.*; /** An immutable representation of a tetris piece in a particular rotation. Each piece is defined by the blocks that make up its body. See the Tetris-Architecture.html for an overview. This is the starter file version -- a few simple things are filled in already @author Nick Parlante @author Eric Chown @author Laura Toma @version November 30, 2007 */ public final class Piece { /* Implementation notes: -The starter code does out a few simple things for you -Store the body as a Point[] array -Do not assume there are 4 points in the body -- use array.length to keep the code general */ private static final int ROTATIONS = 4; private Point[] body; // The body of the piece, each point is a coordinate specifying a block private int[] skirt; // Each element specifies how high the piece will land in the corresponding column private int width; // The width of the piece for the current rotation private int height; // The height of the piece for the current rotation private Piece next; // The "next" rotation - note this is how a "piece" is really a list static private Piece[] pieces; // singleton array of first rotations //The list of rotations available static private LinkedList rotations = new LinkedList(); /** Defines a new piece given the Points that make up its body. Makes its own copy of the array and the Point inside it. Does not set up the rotations. This constructor is PRIVATE -- if a client wants a piece object, they must use Piece.getPieces(). getPieces() will therefore make all of the calls to the constructor. As with all constructors, your variables should be initialized here. This means you'll need to calculate width and height as well as setting up the skirt (doing these things once in the constructor means you don't have to do them on the fly during game play). The one exception to this is the "next" variable. You'll want to set that in the pieceRow method. */ private Piece(Point[] points) { // copies the array of points into the "body" body = new Point[points.length]; width = 1; height = 1; for (int i=0; i bodY) { skirt[bodX] = bodY; } } } /** This is where most of your work will be done. pieceRow takes * the initial rotation of a piece and should create all of the * rest of the rotations in a kind of circular list. Essentially * you get the body array of the initial configuration of the * Piece, you need to calculate the other body arrays. */ public static Piece pieceRow(Piece starter) { rotations.add(starter); int num = (starter.getBody()).length; Piece prevPiece = starter; Point[] prevBody = prevPiece.getBody(); int h = prevPiece.getHeight(); int tLen = prevBody.length; String tempStr = new String(""); for (int i=0; i