Public Member Functions | |
void | setField (IBlock[][] nField) |
boolean | moveLeft () |
boolean | moveRight () |
boolean | moveDown () |
boolean | rotate () |
Protected Member Functions | |
void | updateField () |
Protected Attributes | |
Block[] | blocks |
IBlock[][] | field |
int | turnBlock |
Package Functions | |
AStone (IBlock field[][]) | |
Private Member Functions | |
boolean | move (int down, int right, boolean first) |
void game.AStone.updateField | ( | ) | [protected] |
void game.AStone.setField | ( | IBlock | nField[][] | ) |
boolean game.AStone.move | ( | int | down, | |
int | right, | |||
boolean | first | |||
) | [private] |
References game.AStone.blocks, game.AStone.field, and game.IBlock.isEmpty().
Referenced by game.AStone.moveDown(), game.AStone.moveLeft(), and game.AStone.moveRight().
00045 { 00046 // delete blocks and set them new 00047 for (Block b : blocks) { 00048 if (first && b.coordWithin(field.length, field[0].length)) { 00049 field[b.getRow()][b.getCol()] = new emptyBlock(b.getRow(), b 00050 .getCol()); 00051 } 00052 b.move(down, right); 00053 } 00054 // now look if move can't be made 00055 for (Block b : blocks) { 00056 if (!b.coordWithin(field.length, field[0].length) 00057 || !(field[b.getRow()][b.getCol()].isEmpty())) { 00058 return !this.move(-down, -right, false); 00059 } 00060 00061 } 00062 // so now place the thing 00063 this.updateField(); 00064 return true; 00065 }
boolean game.AStone.moveLeft | ( | ) |
Implements game.IStone.
References game.AStone.move().
00067 { 00068 return move(0, -1, true); 00069 }
boolean game.AStone.moveRight | ( | ) |
Implements game.IStone.
References game.AStone.move().
00071 { 00072 return move(0, 1, true); 00073 }
boolean game.AStone.moveDown | ( | ) |
Implements game.IStone.
References game.AStone.move().
00075 { 00076 return move(1, 0, true); 00077 }
boolean game.AStone.rotate | ( | ) |
Implements game.IStone.
Reimplemented in game.quadStone.
References game.AStone.blocks, game.AStone.field, game.ABlock.getCol(), game.IBlock.getRow(), game.ABlock.getRow(), game.IBlock.isEmpty(), and game.AStone.turnBlock.
00079 { 00080 // first calculate coordinates of new blocks 00081 int turn_row = blocks[turnBlock].getRow(); 00082 int turn_col = blocks[turnBlock].getCol(); 00083 int[][] moves = new int[blocks.length][2]; 00084 for (int i = 0; i < blocks.length; i++) { 00085 moves[i][0] = turn_row - blocks[i].getRow() 00086 - (turn_col - blocks[i].getCol()); 00087 moves[i][1] = turn_col - blocks[i].getCol() 00088 + (turn_row - blocks[i].getRow()); 00089 } 00090 // clear blocks 00091 for (Block b : blocks) { 00092 field[b.getRow()][b.getCol()] = new emptyBlock(b.getRow(), b 00093 .getCol()); 00094 } 00095 00096 // check if move can be made 00097 for (int i = 0; i < blocks.length; i++) { 00098 int newrow = blocks[i].getRow() + moves[i][0]; 00099 int newcol = blocks[i].getCol() + moves[i][1]; 00100 if ((newcol < 0) || (newrow < 0) || (newrow >= field.length) 00101 || (newcol >= field[i].length) 00102 || !field[newrow][newcol].isEmpty()) { 00103 // if not re-set blocks 00104 for (int j = 0; j < blocks.length; j++) { 00105 blocks[j].move(-moves[j][0], -moves[j][1]); 00106 } 00107 continue; 00108 } 00109 } 00110 00111 // */ 00112 // now set blocks and update field 00113 00114 for (int i = 0; i < blocks.length; i++) { 00115 blocks[i].move(moves[i][0], moves[i][1]); 00116 } 00117 00118 this.updateField(); 00119 00120 return true; 00121 00122 }
Block [] game.AStone.blocks [protected] |
Referenced by game.AStone.move(), game.AStone.rotate(), and game.AStone.updateField().
IBlock [][] game.AStone.field [protected] |
Referenced by game.AStone.move(), game.AStone.rotate(), and game.AStone.updateField().
int game.AStone.turnBlock [protected] |
Referenced by game.AStone.rotate().