Question: public class DynamicArray { public DynamicArray ( int size ) / / O ( 1 ) public void set ( int index, T obj )
public class DynamicArray
public DynamicArrayint size O
public void setint index, T obj O
public T getint index O
public int size O
public class Tile
private byte color;
public Tilebyte color
this.color color;
public byte getColor
return color;
public class Block
private DynamicArray block; the internal storage of the block data
public Blockint y int x int size this contructor creates a D placeholder of null values; these values will be populated later with calls to setTile Oblocksize
public Blockint y int x int size, byte color overloaded constuctor that creates a D matrix with actual tile objects; no need to call setTile afterwards Oblocksize
public int getSize returns the length of the side of block O
public int getY returns the topleft Ycoordinate of the block O
public int getX returns the topleft Xcoordinate of the block O
public void setTileint y int x Tile t sets the tile at location yx O
public Tile getTileint y int x gets the tile from location yx O
public void drop drops the block by one row Oblocksize
public void moveLeft moves the block one spot to the left Oblocksize
public void moveRight moves the block one spot to the right Oblocksize
public void rotate rotates the block degrees clockwise Oblocksize
public void flipVertical flips the block vertically Oblocksize
public void flipHorizontal flips the block horizontally Oblocksize
public Block scaleUp scales up the block double size Oblocksize
public Block scaleDown scales down the block half size Oblocksize
public class Tetris
public static boolean canMoveLeftBoard board, Block block Oboardsize
public static boolean canMoveRightBoard board, Block block Oboardsize
public static boolean canflipVerticalBoard board, Block block Oboardsize
public static boolean canflipHorizontalBoard board, Block block Oboardsize
public static boolean canRotateBoard board, Block block Oboardsize
public static boolean canScaleDownBoard board, Block block Oboardsize
public static boolean canScaleUpBoard board, Block block Oboardsize
public static boolean canDropBoard board, Block block Oboardsize
public static boolean isGameOverBoard board, Block block Oboardsize
public class Board
private DynamicArray board; the internal storage of the board data
public Boardint height, int width this contructor creates a D placeholder of null values; these values will be populated later with calls to setTile Oheight width
public int getWidth returns the width of the board O
public int getHeight returns the height of the board O
public void setTileint y int x Tile t sets the tile at location yx O
public Tile getTileint y int x gets the tile from location yx O
public void consolidateBlock block when the dropping block has reached its final location, this method will consolidate it into the tetris well Oblocksize
public void clearRows clear anyall rows that are complete and shifts the above tiles down Oboardsize
public void reward applies the reward as explained in the project description Oboardsize
public void penalize applies the penalty as explained in the project description Oboardsize
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 paintComponentGraphics g
drawBoardg;
drawBlockg;
private void drawBoardGraphics g
for int y; y
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
