Board.java public int getWidth(){ // returns the width of the board -- O(1)
Question:
Board.java
public int getWidth(){ // returns the width of the board -- O(1)
return board.size()>0?board.get(0).size():0;
}
public int getHeight(){ // returns the height of the board -- O(1)
return board.size();
}
public void setTile(int y, int x, Tile t){ // sets the tile at location y,x -- O(1)
if (y >= 0 && y < board.size() && x >= 0 && x < board.get(y).size()) {
board.get(y).set(x, t);
}
}
public Tile getTile(int y, int x){ // gets the tile from location y,x -- O(1)
// return board.get(y).get(x);
if (y >= 0 && y < board.size() && x >= 0 && x < board.get(y).size()) {
return board.get(y).get(x);
} else {
throw new RuntimeException("Invalid indices provided for getTile");
}
}
Block.java
public int getY()
{
return y;
}
public int getX()
{
return x;
}
public void setTile(int y, int x, Tile t)
{
block.get(y).set(x, t);
}
public Tile getTile(int y, int x) {
if (isValidIndex(y, x)) {
DynamicArray
if (row != null && x < row.size()) {
return row.get(x);
} else {
// Handle invalid column index
throw new RuntimeException("Invalid column index provided for getTile");
}
} else {
// Handle invalid row index
throw new RuntimeException("Invalid row index provided for getTile");
}
}
When I have a block that has many null values, such as:
[x] [] []
[] [] []
[] [] []
since there are no tiles on the right side, the block can not move all the way to the right. however, I want the block reach to the edge on the right side, even if the block has many null values on the right edge.
Tetris.java
public static boolean canMoveRight(Board board, Block block) // O(board_size)
{
}
When I have a block that has many null values, such as:
[] [] [x]
[] [] []
[] [] []
since there are no tiles on the leftside, the block can not move all the way to the left. however, I want the block reach to the edge on the leftside, even if the block has many null values on the left edge.
Tetris.java
public static boolean canMoveLeft(Board board, Block block) // O(board_size)
{
}
OCP Oracle Certified Professional Java SE 11 Developer Practice Tests Exam 1Z0 819 And Upgrade Exam
ISBN: 9781119696131
1st Edition
Authors: Scott Selikoff, Jeanne Boyarsky