24sp的skeleton 和之前的不一样,搜不到(可能是我不会搜),磕磕绊绊写出来了,记录一下,方便和我一样的初学者参考;
更新:原来去github搜一下就行了= =
Task 1
public boolean emptySpaceExists() {
// TODO: Task 2. Fill in this function.
int size = board.size();
for(int i = 0; i < size; i++){
for(int j = 0; j < size; j++){
if(board.tile(i,j) == null) return true;
}
}
return false;
}
Task 2
public boolean maxTileExists() {
// TODO: Task 3. Fill in this function.
int size = board.size();
for(int i = 0; i < size; i++){
for(int j = 0; j < size; j++){
if(board.tile(i,j) == null) continue;
else {
Tile t = tile(i,j);
if(t.value() == MAX_PIECE) return true;
}
}
}
return false;
}
Task 3
public boolean atLeastOneMoveExists() {
// TODO: Fill in this function.
if(emptySpaceExists()) return true;
int size = board.size();
for(int i = 0; i<size-1; i++){
for(int j = 0; j<size-1; j++){
if(tile(i,j).value() == tile(i+1,j).value() || tile(i,j).value() == tile(i,j+1).value())
return true;
}
}
if(size > 1){
if(tile(size-1,size-1).value() == tile(size-2, size-1).value() || tile(size-1,size-1).value() == tile(size-1, size-2).value() )
return true;
}
return false;
}
Task 5, 6, and 10
public void moveTileUpAsFarAsPossible(int x, int y) {
Tile currTile = board.tile(x, y);
int myValue = currTile.value();
int targetY = y;
// TODO: Tasks 5, 6, and 10. Fill in this function.
int r = y;
while(r + 1 < size()){
if(tile(x, r+1) == null) r += 1;
else {
if(tile(x, r+1).value() == currTile.value() && !tile(x, r+1).wasMerged()) {
r += 1;
score = score + 2*currTile.value();
}
break;
}
}
if(r != y) board.move(x, r, currTile);
}
Task 7
public void tiltColumn(int x) {
// TODO: Task 7. Fill in this function.
for (int r = size() -1 ; r >= 0; r--){
if(tile(x,r) != null){
moveTileUpAsFarAsPossible(x, r);
}
}
}
Task 8 and 9
public void tilt(Side side) {
// TODO: Tasks 8 and 9. Fill in this function.
board.setViewingPerspective(side);
for (int x=0; x<size(); x++){
tiltColumn(x);
}
board.setViewingPerspective(Side.NORTH);
}