patternjavaMinor
Tetris clone in Java
Viewed 0 times
tetrisjavaclone
Problem
I have a representation for each initial shape as an
Here is an example of the latter
I was then wondering whether to move the rotated shapes into individual
What would be the most suitable approach in my case in terms of scalability and code correctness?
Enum with points and another for each rotated shape in the same Enum.Here is an example of the latter
Enum://
// * *
// *
// *
J_SHAPE_SOUTH(new Point[] {
new Point(2, 0),
new Point(2, 1),
new Point(2, 2),
new Point(3, 2)
}),
//
// * *
// *
// *
L_SHAPE_SOUTH(new Point[] {
new Point(1, 2),
new Point(2, 0),
new Point(2, 1),
new Point(2, 2)
});I was then wondering whether to move the rotated shapes into individual
Enums, say RotatedJShape, or simply keep all the rotated shapes in the same Enum. My concern is that some shapes like the I-shape only has one rotated condition, so it seems pointless to have an Enum for that shape.What would be the most suitable approach in my case in terms of scalability and code correctness?
Solution
Ages ago I did a Tetris clone, and my idea for a data structure was this:
A circular linked list of matrices.
How do you rotate? Walk the list...
You can have a single array of these lists (one per each block type), and your game logic's notion of the "current piece" is a reference to something inside that table. That way the game logic can have no knowledge of the different shapes, and you declare a small array that defines what the shapes are.
A circular linked list of matrices.
How do you rotate? Walk the list...
You can have a single array of these lists (one per each block type), and your game logic's notion of the "current piece" is a reference to something inside that table. That way the game logic can have no knowledge of the different shapes, and you declare a small array that defines what the shapes are.
Context
StackExchange Code Review Q#2265, answer score: 9
Revisions (0)
No revisions yet.