Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Board.java public int getWidth(){ // returns the width of the board -- O(1) return board.size()>0?board.get(0).size():0; } public

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 row = block.get(y);
            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)

{
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

To determine whether a block can move all the way to the right or left edge of the board you need to consider the positions of the blocks tiles and th... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OCP Oracle Certified Professional Java SE 11 Developer Practice Tests Exam 1Z0 819 And Upgrade Exam 1Z0 817

Authors: Scott Selikoff, Jeanne Boyarsky

1st Edition

1119696135, 978-1119696131

More Books

Students also viewed these Algorithms questions

Question

In SW instruction, data is written from

Answered: 1 week ago