Philosophical Design Questions for OOP-Tetris -
You are writing a Tetris program in Java. Regarding the following aspects, how do you set up your class design?
- Piece Class: An piece of an internal array that determines the size of the piece, vs. seven
piece
Squares, one for each piece, they are all sub-squares of a normal Paes class. - Piece Class Representation: Create an array of 4 examples of a <4>
block
, represent a square of one piece, and each < It has its place on the board in the code> block (in the graphical coordinates) vs. 4x4 array wherenull
means that there is no block there, and the location is determined - Location:
In the block
theblock
oron the board code> arrays make its place versus. Know the locations of the
piece
andboards
to theblocks
which include them. - Generating a piece: is a static method of the grinding class
getRandomPiece
, or aPieceFactory
, on which you Create an exampleZenerlandam Method
method - Regulating the current piece: Use the
e> proxy
pattern, so that it needs access, everything that just proxy , Or thegetCurrentPiece
method is on theboard
class and at any time calls you want to do something with the current piece.
This is not a homework. I just want to differentiate my introduction to the CS course from college and I want to see what people generally believe. What would be thought of "good" OOP designs? Ignore the fact that this is an introduction to the course - how will you do this?
First of all, I will not give a subclass of piece
class because it Unnecessary fragment
class without using heritage should be able to describe any shape. IMHO, this is not exactly what part was created for and it just complicates things.
Second, I do not store the x / y coordinate in the blocks
objects because it has two blocks in the same place fragment
class block object Hold a grid (i.e. 2D array). The X / Y coordinates will be indexed to 2D arrays.
To get a random piece, for Static Method vs. Factory Object, I want to go to the simple fact with the Factory Object that junk can be junky for factory object testing.
I will treat the board as a large piece
object board
class as a member variable, large piece
The current piece is played, and the current piece can be played, and the next piece can be played, the structure is used to avoid this heritage.
Comments
Post a Comment