Write a console with Rust Tetris

I. Summary

Currently supports Win10 console and Ubuntu terminal normal display (not tried other platforms, different terminals may cause confusion to sort);

Diagram:

Code address: https: //github.com/Silentdoer/RustTetris

Second, the realization principle

2.1 fundamental principle is actually a two-dimensional Vec, namely Vec <Vec <CanvasPixel >>, each CanvasPixel represents a showcase of the smallest units, such as diagrams, ;

Each block is a CanvasPiece 2.2, i.e., each of four CanvasPixel CanvasPiece, each has its own CanvasPiece origin coordinates, is determined for a subsequent rotation or the like;

2.3 Each box next fall is actually determine the coordinates Piece inside it in the Canvas (Map) is blank or , is is not allowed to explain decline (of course, this part of the judgment there are other cases to consider, such as not part, or Piece next display coordinate is actually a part of its own and the like);

2.4 rotating each block are also the origin of the coordinate rotation whether and the like determines whether the sector can be determined whether the rotation;

2.5 Each time the box when no longer have to determine whether the fall can be eliminated, eliminate the Canvas to be down;

2.6 If the new Piece not fall, y-axis is negative and there Pixel, the game is described;

2.7. . . The above are some of the main content is determined, the code can be seen particularly in the canvas_piece can_rotate, rotate, can_dropdown, dropdown, in_self these methods;

Guess you like

Origin www.cnblogs.com/silentdoer/p/12160871.html