|
001 packagepackage is used to name the directory or folder a class is in scg.ch13.pieces;
002
003 importimport means to make the classes and/or packages available in this program fang2.sprites.CompositeSprite;
004 importimport means to make the classes and/or packages available in this program fang2.sprites.RectangleSprite;
005
006 importimport means to make the classes and/or packages available in this program java.awt.Color;
007 importimport means to make the classes and/or packages available in this program java.util.ArrayList;
008
009 importimport means to make the classes and/or packages available in this program scg.ch13.core.Board;
010
011 importimport means to make the classes and/or packages available in this program scg.ch13.util.Position;
012
013 /**
014 * The Piece abstraction made manifest. This represents a generic piece
015 * as a 5 x 5 grid. The individual piece constructors handle making any
016 * given Tetris piece.
017 */
018 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects Piece
019 extendsextends means to customize or extend the functionality of a class CompositeSprite {open braces start code blocks and must be matched with a close brace
020 /** number of different kinds of pieces. */
021 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) intint is the type for whole numbers and it is short for integer PIECE_COUNT =this assignment operator makes the left side equal to the right side 7;
022
023 /** size, in CompositeSprite screens, of each square */
024 privateprivate is used to restrict access to the current class only staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) doubledouble is the type for numbers that can contain decimal fractions squareEdgeSize =this assignment operator makes the left side equal to the right side 0.20;
025
026 /** the board thisthis means the current object (the implicit parameter) piece is moving on */
027 privateprivate is used to restrict access to the current class only Board board;
028
029 /**
030 * 4 facings * 5 rows * 5 columns: each facing has a 5 x 5 two-dimensional
031 * description of the piece in that facing. Blocks are either nullnull is the value used to refer to a non-existant object
032 * (empty) or non-nullnull is the value used to refer to a non-existant object (full), referring to a {open braces start code blocks and must be matched with a close brace@link RectangleSprite}close braces end code blocks and must match an earlier open brace
033 * that goes in that {open braces start code blocks and must be matched with a close brace@link Position}close braces end code blocks and must match an earlier open brace.
034 */
035 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) ArrayList<ArrayList<ArrayList<RectangleSprite>>this performs a bit-wise right shift> blocksByFacing;
036
037 /** The number of rows (columns) in thisthis means the current object (the implicit parameter) {open braces start code blocks and must be matched with a close brace@link Piece}close braces end code blocks and must match an earlier open brace's grid */
038 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) intint is the type for whole numbers and it is short for integer rows;
039 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) intint is the type for whole numbers and it is short for integer columns;
040
041 /** The current facing [brackets are typically used to declare, initialize and index (indicate which element of) arrays0-3]brackets are typically used to declare, initialize and index (indicate which element of) arrays of the piece */
042 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer facing;
043
044 /** Current position of thisthis means the current object (the implicit parameter) {open braces start code blocks and must be matched with a close brace@link Piece}close braces end code blocks and must match an earlier open brace (in unit-squares) */
045 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) Position position;
046
047 /**
048 * 4 blocks in a tetramino so there are 4 different lists in thisthis means the current object (the implicit parameter). 4
049 * facings so 4 different positions forfor is a looping structure for repeatedly executing a block of code each block. These are the only
050 * non-empty locations in the cells forfor is a looping structure for repeatedly executing a block of code each facing. Note that the
051 * every block appears, by reference, in each facing of cells.
052 * Protected so that subclasses can set the value after calling the
053 * {open braces start code blocks and must be matched with a close brace@link Piece}close braces end code blocks and must match an earlier open brace constructor.
054 */
055 protectedprotected is used to restrict access to the current class and subclasses only ArrayList<ArrayList<Position>>this performs a bit-wise right shift blockPositionByFacing;
056
057 /**
058 * 4 facings so 4 different offsets from a given board location to
059 * place the piece there.
060 */
061 protectedprotected is used to restrict access to the current class and subclasses only ArrayList<Position> initialOffsetByFacing;
062
063 /**
064 * Construct a newnew is used to create objects by calling the constructor {open braces start code blocks and must be matched with a close brace@link Piece}close braces end code blocks and must match an earlier open brace with the given facing and color.
065 *
066 * @paramthis is the Javadoc tag for documenting the purpose of parameters facing initial facing; will be taken modulo 4.
067 * @paramthis is the Javadoc tag for documenting the purpose of parameters color color of regular blocks; pivot will be darker
068 */
069 protectedprotected is used to restrict access to the current class and subclasses only Piece(intint is the type for whole numbers and it is short for integer facing, Color color) {open braces start code blocks and must be matched with a close brace
070 thisthis means the current object (the implicit parameter).rows =this assignment operator makes the left side equal to the right side 5;
071 thisthis means the current object (the implicit parameter).columns =this assignment operator makes the left side equal to the right side 5;
072 setColor(color);
073 position =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Position(0, 0);
074 thisthis means the current object (the implicit parameter).facing =this assignment operator makes the left side equal to the right side facing %this divides the left side by the right side and evaluates to the remainder 4;// make sure its safe
075 setRotationDegrees(90 * thisthis means the current object (the implicit parameter).facing);
076 blocksByFacing =this assignment operator makes the left side equal to the right side
077 newnew is used to create objects by calling the constructor ArrayList<ArrayList<ArrayList<RectangleSprite>>this performs a bit-wise right shift>();
078 // for each facing, insert an empty blocks grid
079 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer f =this assignment operator makes the left side equal to the right side 0; f !=this is the not equals operator which evaluates to true if both sides are different 4; ++this is the increment operator, which increases the variable by 1f) {open braces start code blocks and must be matched with a close brace
080 blocksByFacing.add(initBlocks());
081 }close braces end code blocks and must match an earlier open brace
082 }close braces end code blocks and must match an earlier open brace
083
084 /**
085 * Get the orientation thisthis means the current object (the implicit parameter) block would have ifif executes the next statement only if the condition in parenthesis evaluates to true it were turned 90
086 * degrees anti-clockwise from the given orientation.
087 *
088 * @paramthis is the Javadoc tag for documenting the purpose of parameters orientation starting orientation
089 *
090 * @returnnull starting orientation one turn anti-clockwise
091 */
092 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) intint is the type for whole numbers and it is short for integer turnCCW(intint is the type for whole numbers and it is short for integer orientation) {open braces start code blocks and must be matched with a close brace
093 returnreturn means to provide the result of the method and/or cease execution of the method immediately (orientation +adds two numbers together or concatenates Strings together 3) %this divides the left side by the right side and evaluates to the remainder 4;
094 }close braces end code blocks and must match an earlier open brace
095
096 /**
097 * Return the block value at the given position. Value depends on
098 * current facing of the {open braces start code blocks and must be matched with a close brace@link Piece}close braces end code blocks and must match an earlier open brace.
099 *
100 * @paramthis is the Javadoc tag for documenting the purpose of parameters row the row (inside thisthis means the current object (the implicit parameter) piece) forfor is a looping structure for repeatedly executing a block of code which a block
101 * value is required.
102 * @paramthis is the Javadoc tag for documenting the purpose of parameters column column (inside thisthis means the current object (the implicit parameter) piece) forfor is a looping structure for repeatedly executing a block of code which a block value
103 * is required.
104 *
105 * @returnnull the block at that location: nullnull is the value used to refer to a non-existant object ifif executes the next statement only if the condition in parenthesis evaluates to true no block, {open braces start code blocks and must be matched with a close brace@link
106 * RectangleSprite}close braces end code blocks and must match an earlier open brace reference to the block there otherwise
107 */
108 publicpublic is used to indicate unrestricted access (any other class can have access) RectangleSprite blockAt(intint is the type for whole numbers and it is short for integer row, intint is the type for whole numbers and it is short for integer column) {open braces start code blocks and must be matched with a close brace
109 returnreturn means to provide the result of the method and/or cease execution of the method immediately getBlocks().get(row).get(column);
110 }close braces end code blocks and must match an earlier open brace
111
112 /**
113 * Can the piece move down without colliding?
114 *
115 * @returnnull truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true it can; falsefalse is a value for the boolean type and means not true otherwise
116 */
117 publicpublic is used to indicate unrestricted access (any other class can have access) intint is the type for whole numbers and it is short for integer canMoveDown() {open braces start code blocks and must be matched with a close brace
118 returnreturn means to provide the result of the method and/or cease execution of the method immediately board.canMoveTo(thisthis means the current object (the implicit parameter), getRow() +adds two numbers together or concatenates Strings together 1, getColumn(),
119 getFacing());
120 }close braces end code blocks and must match an earlier open brace
121
122 /**
123 * Can the piece move left without colliding?
124 *
125 * @returnnull truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true it can; falsefalse is a value for the boolean type and means not true otherwise
126 */
127 publicpublic is used to indicate unrestricted access (any other class can have access) intint is the type for whole numbers and it is short for integer canMoveLeft() {open braces start code blocks and must be matched with a close brace
128 returnreturn means to provide the result of the method and/or cease execution of the method immediately board.canMoveTo(thisthis means the current object (the implicit parameter), getRow(), getColumn() - 1,
129 getFacing());
130 }close braces end code blocks and must match an earlier open brace
131
132 /**
133 * Can the piece move right without colliding?
134 *
135 * @returnnull truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true it can; falsefalse is a value for the boolean type and means not true otherwise
136 */
137 publicpublic is used to indicate unrestricted access (any other class can have access) intint is the type for whole numbers and it is short for integer canMoveRight() {open braces start code blocks and must be matched with a close brace
138 returnreturn means to provide the result of the method and/or cease execution of the method immediately board.canMoveTo(thisthis means the current object (the implicit parameter), getRow(), getColumn() +adds two numbers together or concatenates Strings together 1,
139 getFacing());
140 }close braces end code blocks and must match an earlier open brace
141
142 /**
143 * Can the piece, in its current orientation, rotate anti-clockwise
144 * safely?
145 *
146 * @returnnull truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true the piece can rotate safely; falsefalse is a value for the boolean type and means not true otherwise
147 */
148 publicpublic is used to indicate unrestricted access (any other class can have access) intint is the type for whole numbers and it is short for integer canRotateCCW() {open braces start code blocks and must be matched with a close brace
149 returnreturn means to provide the result of the method and/or cease execution of the method immediately board.canMoveTo(thisthis means the current object (the implicit parameter), getRow(), getColumn(),
150 turnCCW(getFacing()));
151 }close braces end code blocks and must match an earlier open brace
152
153 /**
154 * Get the current column (offset from the left of the boar) in unit
155 * squares.
156 *
157 * @returnnull current column in unit squares from the left edge of the
158 * board
159 */
160 publicpublic is used to indicate unrestricted access (any other class can have access) intint is the type for whole numbers and it is short for integer getColumn() {open braces start code blocks and must be matched with a close brace
161 returnreturn means to provide the result of the method and/or cease execution of the method immediately position.getColumn();
162 }close braces end code blocks and must match an earlier open brace
163
164 /**
165 * Get the number of columns in thisthis means the current object (the implicit parameter) {open braces start code blocks and must be matched with a close brace@link Piece}close braces end code blocks and must match an earlier open brace
166 *
167 * @returnnull the number of block columns
168 */
169 publicpublic is used to indicate unrestricted access (any other class can have access) intint is the type for whole numbers and it is short for integer getColumnSize() {open braces start code blocks and must be matched with a close brace
170 returnreturn means to provide the result of the method and/or cease execution of the method immediately columns;
171 }close braces end code blocks and must match an earlier open brace
172
173 /**
174 * The current facing of the {open braces start code blocks and must be matched with a close brace@link Piece}close braces end code blocks and must match an earlier open brace
175 *
176 * @returnnull the facing
177 */
178 publicpublic is used to indicate unrestricted access (any other class can have access) intint is the type for whole numbers and it is short for integer getFacing() {open braces start code blocks and must be matched with a close brace
179 returnreturn means to provide the result of the method and/or cease execution of the method immediately facing;
180 }close braces end code blocks and must match an earlier open brace
181
182 /**
183 * Get the initial value forfor is a looping structure for repeatedly executing a block of code the column. Depends on shape and facing
184 * of the {open braces start code blocks and must be matched with a close brace@link Piece}close braces end code blocks and must match an earlier open brace
185 *
186 * @returnnull initial column number in unit squares from the left
187 */
188 publicpublic is used to indicate unrestricted access (any other class can have access) intint is the type for whole numbers and it is short for integer getInitialColumn() {open braces start code blocks and must be matched with a close brace
189 returnreturn means to provide the result of the method and/or cease execution of the method immediately initialOffsetByFacing.get(facing).getColumn();
190 }close braces end code blocks and must match an earlier open brace
191
192 /**
193 * Get the initial value forfor is a looping structure for repeatedly executing a block of code the row. Depends on shape and facing of
194 * the {open braces start code blocks and must be matched with a close brace@link Piece}close braces end code blocks and must match an earlier open brace
195 *
196 * @returnnull initial row number in unit squares down from top
197 */
198 publicpublic is used to indicate unrestricted access (any other class can have access) intint is the type for whole numbers and it is short for integer getInitialRow() {open braces start code blocks and must be matched with a close brace
199 returnreturn means to provide the result of the method and/or cease execution of the method immediately initialOffsetByFacing.get(facing).getRow();
200 }close braces end code blocks and must match an earlier open brace
201
202 /**
203 * Get the current row (offset from the top of the board) in unit
204 * squares.
205 *
206 * @returnnull current row in unit squares down from top
207 */
208 publicpublic is used to indicate unrestricted access (any other class can have access) intint is the type for whole numbers and it is short for integer getRow() {open braces start code blocks and must be matched with a close brace
209 returnreturn means to provide the result of the method and/or cease execution of the method immediately position.getRow();
210 }close braces end code blocks and must match an earlier open brace
211
212 /**
213 * Get the number of rows in thisthis means the current object (the implicit parameter) {open braces start code blocks and must be matched with a close brace@link Piece}close braces end code blocks and must match an earlier open brace
214 *
215 * @returnnull the number of block rows
216 */
217 publicpublic is used to indicate unrestricted access (any other class can have access) intint is the type for whole numbers and it is short for integer getRowSize() {open braces start code blocks and must be matched with a close brace
218 returnreturn means to provide the result of the method and/or cease execution of the method immediately rows;
219 }close braces end code blocks and must match an earlier open brace
220
221 /**
222 * Is the given position in the piece full in the current facing?
223 *
224 * @paramthis is the Javadoc tag for documenting the purpose of parameters row the row (inside thisthis means the current object (the implicit parameter) piece) forfor is a looping structure for repeatedly executing a block of code which a block
225 * value is required.
226 * @paramthis is the Javadoc tag for documenting the purpose of parameters column column (inside thisthis means the current object (the implicit parameter) piece) forfor is a looping structure for repeatedly executing a block of code which a block value
227 * is required.
228 *
229 * @returnnull truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true position is full (!this is the not operator, which changes true to false and false to trueempty); falsefalse is a value for the boolean type and means not true otherwise
230 */
231 publicpublic is used to indicate unrestricted access (any other class can have access) booleanboolean is a type that is either true or false hasBlock(intint is the type for whole numbers and it is short for integer row, intint is the type for whole numbers and it is short for integer column) {open braces start code blocks and must be matched with a close brace
232 returnreturn means to provide the result of the method and/or cease execution of the method immediately hasBlock(row, column, getFacing());
233 }close braces end code blocks and must match an earlier open brace
234
235 /**
236 * Is the given position in the piece when in the given facing full?
237 *
238 * @paramthis is the Javadoc tag for documenting the purpose of parameters row the row (inside thisthis means the current object (the implicit parameter) piece) forfor is a looping structure for repeatedly executing a block of code which a block
239 * value is required.
240 * @paramthis is the Javadoc tag for documenting the purpose of parameters column column (inside thisthis means the current object (the implicit parameter) piece) forfor is a looping structure for repeatedly executing a block of code which a block value
241 * is required.
242 * @paramthis is the Javadoc tag for documenting the purpose of parameters facing the hypothetical facing of the {open braces start code blocks and must be matched with a close brace@link Piece}close braces end code blocks and must match an earlier open brace
243 *
244 * @returnnull truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true position is full (!this is the not operator, which changes true to false and false to trueempty); falsefalse is a value for the boolean type and means not true otherwise
245 */
246 publicpublic is used to indicate unrestricted access (any other class can have access) booleanboolean is a type that is either true or false hasBlock(intint is the type for whole numbers and it is short for integer row, intint is the type for whole numbers and it is short for integer column, intint is the type for whole numbers and it is short for integer facing) {open braces start code blocks and must be matched with a close brace
247 returnreturn means to provide the result of the method and/or cease execution of the method immediately (getBlocks(facing).get(row).get(column) !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object);
248 }close braces end code blocks and must match an earlier open brace
249
250 /**
251 * Move the piece down one row. NO ERROR CHECKING!this is the not operator, which changes true to false and false to true
252 */
253 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value moveDown() {open braces start code blocks and must be matched with a close brace
254 setRow(getRow() +adds two numbers together or concatenates Strings together 1);
255 }close braces end code blocks and must match an earlier open brace
256
257 /**
258 * Move the piece left one column. NO ERROR CHECKING!this is the not operator, which changes true to false and false to true
259 */
260 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value moveLeft() {open braces start code blocks and must be matched with a close brace
261 setColumn(getColumn() - 1);
262 }close braces end code blocks and must match an earlier open brace
263
264 /**
265 * Move the piece right one column. NO ERROR CHECKING!this is the not operator, which changes true to false and false to true
266 */
267 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value moveRight() {open braces start code blocks and must be matched with a close brace
268 setColumn(getColumn() +adds two numbers together or concatenates Strings together 1);
269 }close braces end code blocks and must match an earlier open brace
270
271 /**
272 * Rotate the piece in the anti-clockwise direction. Updates facing
273 * and rotates the sprite. NO ERROR CHECKING!this is the not operator, which changes true to false and false to true
274 */
275 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value rotateCCW() {open braces start code blocks and must be matched with a close brace
276 facing =this assignment operator makes the left side equal to the right side turnCCW(facing);
277 rotateDegrees(-90);
278 }close braces end code blocks and must match an earlier open brace
279
280 /**
281 * Set the board referred to by thisthis means the current object (the implicit parameter) piece.
282 *
283 * @paramthis is the Javadoc tag for documenting the purpose of parameters board the newnew is used to create objects by calling the constructor {open braces start code blocks and must be matched with a close brace@link Board}close braces end code blocks and must match an earlier open brace reference
284 */
285 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setBoard(Board board) {open braces start code blocks and must be matched with a close brace
286 thisthis means the current object (the implicit parameter).board =this assignment operator makes the left side equal to the right side board;
287 }close braces end code blocks and must match an earlier open brace
288
289 /**
290 * Set the column value. ALWAYS use thisthis means the current object (the implicit parameter) method to update column.
291 *
292 * @paramthis is the Javadoc tag for documenting the purpose of parameters column the newnew is used to create objects by calling the constructor column value
293 */
294 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setColumn(intint is the type for whole numbers and it is short for integer column) {open braces start code blocks and must be matched with a close brace
295 position.setColumn(column);
296 board.setPieceLocation(thisthis means the current object (the implicit parameter));
297 }close braces end code blocks and must match an earlier open brace
298
299 /**
300 * Set the row value. ALWAYS use thisthis means the current object (the implicit parameter) method to update row.
301 *
302 * @paramthis is the Javadoc tag for documenting the purpose of parameters row the newnew is used to create objects by calling the constructor row value
303 */
304 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setRow(intint is the type for whole numbers and it is short for integer row) {open braces start code blocks and must be matched with a close brace
305 position.setRow(row);
306 board.setPieceLocation(thisthis means the current object (the implicit parameter));
307 }close braces end code blocks and must match an earlier open brace
308
309 /**
310 * Initialize one empty grid representing thisthis means the current object (the implicit parameter) piece.
311 *
312 * @returnnull a grid of nullnull is the value used to refer to a non-existant object locations rows by columns in size
313 */
314 privateprivate is used to restrict access to the current class only ArrayList<ArrayList<RectangleSprite>>this performs a bit-wise right shift initBlocks() {open braces start code blocks and must be matched with a close brace
315 ArrayList<ArrayList<RectangleSprite>>this performs a bit-wise right shift grid =this assignment operator makes the left side equal to the right side
316 newnew is used to create objects by calling the constructor ArrayList<ArrayList<RectangleSprite>>this performs a bit-wise right shift();
317 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer r =this assignment operator makes the left side equal to the right side 0; r !=this is the not equals operator which evaluates to true if both sides are different rows; ++this is the increment operator, which increases the variable by 1r) {open braces start code blocks and must be matched with a close brace
318 grid.add(initRow());
319 }close braces end code blocks and must match an earlier open brace
320 returnreturn means to provide the result of the method and/or cease execution of the method immediately grid;
321 }close braces end code blocks and must match an earlier open brace
322
323 /**
324 * Initalize one empty row representing thisthis means the current object (the implicit parameter) piece
325 *
326 * @returnnull a row of nullnull is the value used to refer to a non-existant object locations columns entries longlong is the type for whole numbers (they have a larger range than int)
327 */
328 privateprivate is used to restrict access to the current class only ArrayList<RectangleSprite> initRow() {open braces start code blocks and must be matched with a close brace
329 ArrayList<RectangleSprite> row =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ArrayList<RectangleSprite>();
330 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer c =this assignment operator makes the left side equal to the right side 0; c !=this is the not equals operator which evaluates to true if both sides are different columns; ++this is the increment operator, which increases the variable by 1c) {open braces start code blocks and must be matched with a close brace
331 row.add(nullnull is the value used to refer to a non-existant object);
332 }close braces end code blocks and must match an earlier open brace
333 returnreturn means to provide the result of the method and/or cease execution of the method immediately row;
334 }close braces end code blocks and must match an earlier open brace
335
336 /**
337 * Generates the {open braces start code blocks and must be matched with a close brace@link RectangleSprite}close braces end code blocks and must match an earlier open brace objects that appear inside
338 * thisthis means the current object (the implicit parameter) {open braces start code blocks and must be matched with a close brace@link CompositeSprite}close braces end code blocks and must match an earlier open brace. There are two types of blocks, BLOCK
339 * and PIVOT, each with a slightly different color. The piece is
340 * always constructed in the reference orientation, facing 0.
341 */
342 protectedprotected is used to restrict access to the current class and subclasses only voidvoid means the method does not return a value generateBlocks() {open braces start code blocks and must be matched with a close brace
343 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer blockNdx =this assignment operator makes the left side equal to the right side 0;
344 blockNdx !=this is the not equals operator which evaluates to true if both sides are different blockPositionByFacing.size();
345 ++this is the increment operator, which increases the variable by 1blockNdx) {open braces start code blocks and must be matched with a close brace
346 ArrayList<Position> blockPositions
347 =this assignment operator makes the left side equal to the right side blockPositionByFacing.get(blockNdx);
348
349 // Position block # blockNdx in its 0 facing; rotate sprite
350 // for other views
351 intint is the type for whole numbers and it is short for integer row =this assignment operator makes the left side equal to the right side blockPositions.get(0).getRow();
352 intint is the type for whole numbers and it is short for integer column =this assignment operator makes the left side equal to the right side blockPositions.get(0).getColumn();
353
354 // block at position (2, 2) is centered at location (0.0, 0.0)
355 doubledouble is the type for numbers that can contain decimal fractions y =this assignment operator makes the left side equal to the right side (row - 2) * squareEdgeSize;
356 doubledouble is the type for numbers that can contain decimal fractions x =this assignment operator makes the left side equal to the right side (column - 2) * squareEdgeSize;
357
358 // create the block
359 RectangleSprite block
360 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(squareEdgeSize, squareEdgeSize);
361 block.setLocation(x, y);
362
363 // color pivot darker; pivot is center square
364 ifif executes the next statement only if the condition in parenthesis evaluates to true ((row ==this is the comparison operator which evaluates to true if both sides are the same getRowSize() / 2) &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) (column ==this is the comparison operator which evaluates to true if both sides are the same getColumnSize() / 2)) {open braces start code blocks and must be matched with a close brace
365 block.setColor(getColor().darker());
366 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false {open braces start code blocks and must be matched with a close brace
367 block.setColor(getColor());
368 }close braces end code blocks and must match an earlier open brace
369 addSprite(block);
370
371 // populate all four facings with the new block
372 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer facingNdx =this assignment operator makes the left side equal to the right side 0; facingNdx !=this is the not equals operator which evaluates to true if both sides are different 4; ++this is the increment operator, which increases the variable by 1facingNdx) {open braces start code blocks and must be matched with a close brace
373 intint is the type for whole numbers and it is short for integer facingRowNdx =this assignment operator makes the left side equal to the right side blockPositions.get(facingNdx).getRow();
374 intint is the type for whole numbers and it is short for integer facingColNdx =this assignment operator makes the left side equal to the right side blockPositions.get(facingNdx).getColumn();
375 ArrayList<ArrayList<RectangleSprite>>this performs a bit-wise right shift facingBlocks
376 =this assignment operator makes the left side equal to the right side blocksByFacing.get(facingNdx);
377 ArrayList<RectangleSprite> blocksRow =this assignment operator makes the left side equal to the right side
378 facingBlocks.get(facingRowNdx);
379 blocksRow.set(facingColNdx, block);
380 }close braces end code blocks and must match an earlier open brace
381 }close braces end code blocks and must match an earlier open brace
382 }close braces end code blocks and must match an earlier open brace
383
384 /**
385 * Get the blocks grid corresponding to the current facing of the
386 * {open braces start code blocks and must be matched with a close brace@link Piece}close braces end code blocks and must match an earlier open brace.
387 *
388 * @returnnull the blocks grid (two-dimensional list of list of {open braces start code blocks and must be matched with a close brace@link
389 * RectangleSprite}close braces end code blocks and must match an earlier open brace references)
390 */
391 privateprivate is used to restrict access to the current class only ArrayList<ArrayList<RectangleSprite>>this performs a bit-wise right shift getBlocks() {open braces start code blocks and must be matched with a close brace
392 returnreturn means to provide the result of the method and/or cease execution of the method immediately getBlocks(thisthis means the current object (the implicit parameter).facing);
393 }close braces end code blocks and must match an earlier open brace
394
395 /**
396 * Get the blocks grid corresponding to a given facing.
397 *
398 * @returnnull the blocks grid (two-dimensional list of list of {open braces start code blocks and must be matched with a close brace@link
399 * RectangleSprite}close braces end code blocks and must match an earlier open brace references)
400 */
401 privateprivate is used to restrict access to the current class only ArrayList<ArrayList<RectangleSprite>>this performs a bit-wise right shift getBlocks(intint is the type for whole numbers and it is short for integer facing) {open braces start code blocks and must be matched with a close brace
402 returnreturn means to provide the result of the method and/or cease execution of the method immediately blocksByFacing.get(facing);
403 }close braces end code blocks and must match an earlier open brace
404
405 /**
406 * Set the facing of the {open braces start code blocks and must be matched with a close brace@link Piece}close braces end code blocks and must match an earlier open brace; protectedprotected is used to restrict access to the current class and subclasses only because it is not
407 * part of the interfaceinterface is a named collection of declared methods, just the {open braces start code blocks and must be matched with a close brace@link #rotateCW()}close braces end code blocks and must match an earlier open brace and {open braces start code blocks and must be matched with a close brace@link
408 * #rotateCCW()}close braces end code blocks and must match an earlier open brace methods are exposed.
409 *
410 * @paramthis is the Javadoc tag for documenting the purpose of parameters facing the newnew is used to create objects by calling the constructor facing value; well be reduced modulus 4.
411 */
412 protectedprotected is used to restrict access to the current class and subclasses only voidvoid means the method does not return a value setFacing(intint is the type for whole numbers and it is short for integer facing) {open braces start code blocks and must be matched with a close brace
413 thisthis means the current object (the implicit parameter).facing =this assignment operator makes the left side equal to the right side facing %this divides the left side by the right side and evaluates to the remainder 4;
414 }close braces end code blocks and must match an earlier open brace
415 }close braces end code blocks and must match an earlier open brace
416
417 //Uploaded on Mon Mar 29 21:40:43 EDT 2010
|