Question: public class DynamicArray { public DynamicArray ( int size ) / / O ( 1 ) public void set ( int index, T obj )

public class DynamicArray
{
public DynamicArray(int size)// O(1)
public void set(int index, T obj)// O(1)
public T get(int index)// O(1)
public int size()// O(1)
}
public class Tile
{
private byte color;
public Tile(byte color)
{
this.color = color;
}
public byte getColor()
{
return color;
}
}
public class Block
{
private DynamicArray> block; // the internal storage of the block data
public Block(int y, int x, int size)// this contructor creates a 2D placeholder of null values; these values will be populated later with calls to setTile()-- O(block_size)
public Block(int y, int x, int size, byte color)// overloaded constuctor that creates a 2D matrix with actual tile objects; no need to call setTile afterwards -- O(block_size)
public int getSize()// returns the length of the side of block -- O(1)
public int getY()// returns the top-left Y-coordinate of the block -- O(1)
public int getX()// returns the top-left X-coordinate of the block -- O(1)
public void setTile(int y, int x, Tile t)// sets the tile at location y,x -- O(1)
public Tile getTile(int y, int x)// gets the tile from location y,x -- O(1)
public void drop()// drops the block by one row -- O(block_size)
public void moveLeft()// moves the block one spot to the left -- O(block_size)
public void moveRight()// moves the block one spot to the right -- O(block_size)
public void rotate()// rotates the block 90 degrees clockwise -- O(block_size)
public void flipVertical()// flips the block vertically -- O(block_size)
public void flipHorizontal()// flips the block horizontally -- O(block_size)
public Block scaleUp()// scales up the block (double size)-- O(block_size)
public Block scaleDown()// scales down the block (half size)-- O(block_size)
}
public class Tetris
{
public static boolean canMoveLeft(Board board, Block block)// O(board_size)
public static boolean canMoveRight(Board board, Block block)// O(board_size)
public static boolean canflipVertical(Board board, Block block)// O(board_size)
public static boolean canflipHorizontal(Board board, Block block)// O(board_size)
public static boolean canRotate(Board board, Block block)// O(board_size)
public static boolean canScaleDown(Board board, Block block)// O(board_size)
public static boolean canScaleUp(Board board, Block block)// O(board_size)
public static boolean canDrop(Board board, Block block)// O(board_size)
public static boolean isGameOver(Board board, Block block)// O(board_size)
}
public class Board
{
private DynamicArray> board; // the internal storage of the board data
public Board(int height, int width)// this contructor creates a 2D placeholder of null values; these values will be populated later with calls to setTile()-- O(height * width)
public int getWidth()// returns the width of the board -- O(1)
public int getHeight()// returns the height of the board -- O(1)
public void setTile(int y, int x, Tile t)// sets the tile at location y,x -- O(1)
public Tile getTile(int y, int x)// gets the tile from location y,x -- O(1)
public void consolidate(Block block)// when the dropping block has reached its final location, this method will consolidate it into the tetris well -- O(block_size)
public void clearRows()// clear any/all rows that are complete and shifts the above tiles down -- O(board_size)
public void reward()// applies the reward as explained in the project description -- O(board_size)
public void penalize()// applies the penalty as explained in the project description -- O(board_size)
}
This is the game code provided by the instructor
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.util.Random;
public final class Game extends JPanel
{
private static Board board;
private static Block block;
private static Random rand = new Random();
private final static Color[] color ={
Color.black, Color.red, Color.green, Color.blue, Color.cyan, Color.magenta, Color.orange, Color.yellow, Color.pink, Color.white
};
@Override
public void paintComponent(Graphics g)
{
drawBoard(g);
drawBlock(g);
}
private void drawBoard(Graphics g)
{
for (int y=0; y

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!