Question: class DynamicArray A generic class that implements a dynamic array. This is the only place in your entire code that you re allowed to declare

class DynamicArray
A generic class that implements a dynamic array. This is the only place in your entire code that youre allowed to declare
and use a fixed-size array.
This is not the typical dynamic arraylist that we discuss in the class. This one is allowed to have null values at any index,
i.e. the empty spots are not necessarily contiguous and located at the end of the array. This also means that we wont use
the operations add and remove but we will work directly with get and set.
The empty spots in the array (i.e. the null values) represent the empty spots in a Tetris board or the empty spots in a
Tetris block (see Figure 1) or, in general, the empty spots in any kind of structure that allows elements to be inserted at
random (non-contiguous) locations.
class Tile
The code is provided, you just need to add comments to pass the javadoc checker
This class represent a single tile of a tetris piece. A piece initially occupies a 3x3 square and, therefore, can have up to 9
tiles. Each tile has a certain color and all the tiles of a piece have the same color. The color is stored as a plain number and
takes values in the range from 1 to 9. You dont have to do anything for the rendering of the tile though, the GUI will take
care of it. Example: The pieces in figures 1a and 1b have 5 tiles, while the pieces in figures 1c and 1d have 6 and 3 tiles
respectively.
class Block
This class represents a two-dimensional tetris piece dropping into the tetris well. Figure 1 depicts some examples of
pieces. The block is practically a square-size placeholder for the Tile objects. But not all the spots are necessarily
occupied. When the block is generated, we randomly pick the spots that will be filled in with tiles. All the tiles of a block
must have the same color. Lastly, the block is dynamic which means that while its dropping into the well it can transform
in the following ways:
It can move left or right (one spot at a time)
It can flip vertically or horizontally
It can rotate clockwise (90 degrees at a time)
It can scale up (double in size) or scale down (shrink in half, but cant become smaller than 2x2).
class Board
This class represents the two-dimensional well of the tetris (the top-left corner of the board has coordinates 0,0). It is
practically a placeholder for the tiles of the blocks that consolidate into the well when the drop stops. However, this well
is dynamic and can change its content when certain moves on the block are made:
Every time the player scales up the block, the player is rewarded with one row of tiles being removed from the
board. The row to be removed is the row with the highest number of consolidated tiles. In case of a tie, remove
the lowest row.
Every time the player scales down the block, the player is penalized with an incomplete row inserted to the board.
The row to be inserted is a duplicate of the row having the fewest consolidated tiles (in case of a tie, pick the
4
Dimitriadis/Zhong Project 1: Dynamic Arrays CS 310 Spring 2024
highest row). This insertion will effectively shift the tiles up by one row and, as a result, the available room (if
any) for maneuvering the coming blocks will shrink by one row.
class Tetris
This class implements the rules of the tetris game and validates the actions that the player is trying to make. For example,
if the player tries to move left but the piece has already reached the left border of the well, the move is not permitted. The
class has methods for validating all possible actions that the user can take as well as a method for checking if the game is
over.
class Game
The code is provided, you just need to add comments to pass the javadoc checker
This class is responsible for initializing the game, for running the GUI, and for handling the events. There is nothing you
need to do here. If your other classes work correctly, the game will play just fine.
Feel free to edit the GUI if you want to add extra features or tweak the existing ones; were not going to test/grade this
class.
During debugging, you can comment out parts of the GUI if you havent yet implemented the respective methods it
invokes.
After compiling the files, you can run the game with the following command that creates a 20x15 board:
java Game 2015
You can obviously change the two command line arguments to create boards of different sizes. It is highly recommended
that you test your code with various dimensions, not just the ones above.

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!