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 fixedsize 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,
ie 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 ie the null values represent the empty spots in a Tetris board or the empty spots in a
Tetris block see Figure or in general, the empty spots in any kind of structure that allows elements to be inserted at
random noncontiguous 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 x square and, therefore, can have up to
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 to 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 a and b have tiles, while the pieces in figures c and d have and tiles
respectively.
class Block
This class represents a twodimensional tetris piece dropping into the tetris well. Figure depicts some examples of
pieces. The block is practically a squaresize 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 degrees at a time
It can scale up double in size or scale down shrink in half, but cant become smaller than x
class Board
This class represents the twodimensional well of the tetris the topleft corner of the board has coordinates 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
DimitriadisZhong Project : Dynamic Arrays CS Spring
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 testgrade 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 x board:
java Game
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
