Some time ago to help people write a Tetris demo, today there is time to share the design ideas.
Analysis:
There are 7 shapes in the game, each of which can be rotated in the game to form a new shape. Each shape is made up of square blocks of color.
Data classes:
Shape: A total of 7 shapes.
Block: Block class, in fact, there is only one map properties.
About Rotation:
Looking for a rotation point for each shape, the rotation point for each shape is fixed.
The red dots are the reference points and the rows are ( x, y )
The position of the rotated blocks relative to the red block is recorded in the shape's data, and the other positions are determined directly by the red block when rotating in the game, and the entire shape movement is done in this way.
The following is the data set in the order above.
Demo Source: http://bbs.tairan.com/thread-38448-1-1.html
Design ideas for Tetris