Advertisement
Amorf

Untitled

Dec 14th, 2021
809
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.29 KB | None | 0 0
  1. #ifndef PIECE_H
  2. #define PIECE_H
  3.  
  4. #include <windows.h>
  5.  
  6. //
  7. // A piece in Teris game. This class is only used by PieceSet. Other classes
  8. // access Piece through PieceSet.
  9. //
  10. // Every piece is composed by 4 POINTs, using Cartesian coordinate system.
  11. // That is, the most bottom left point is (0, 0), the values on x-axis
  12. // increase to the right, and values on y-axis increase to the top.
  13. //
  14. // To represent a piece, it is snapped to the bottom-left corner. For example,
  15. // when the 'I' piece stands vertically, the point array stores:
  16. // (0,0) (0,1) (0,2) (0,3)
  17. //
  18. class Piece
  19. {
  20. public:
  21.     // pieceId: piece type ID
  22.     // pieceRotation: how many time is the piece rotated (0-3)
  23.     // pieceColor: piece color in RGB
  24.     // apt: array of points of which the piece is composed. This constructor
  25.     //      moves these points automatically to snap the piece to bottom-left
  26.     //      corner (0,0)
  27.     // numPoints: number of points in apt
  28.     Piece(int pieceId, int pieceRotation, COLORREF pieceColor,
  29.           const POINT *apt, int numPoints = 4);
  30.     ~Piece();
  31.  
  32.     // Getters for piece properties
  33.     inline int getWidth() const { return width; }
  34.     inline int getHeight() const { return height; }
  35.     inline int getNPoints() const { return nPoints; }
  36.     inline int getId() const { return id; }
  37.     inline int getRotation() const { return rotation; }
  38.     inline COLORREF getColor() const { return color; }
  39.  
  40.     // If any of the following methods accepts a POINT pointer, make sure the
  41.     // size of the array is big enough
  42.  
  43.     // Gets the points of the piece
  44.     void getBody(POINT *apt) const;
  45.  
  46.     // Gets the bottom, left, or right part of points of the piece
  47.     int getSkirt(POINT *apt) const;
  48.     int getLeftSide(POINT *apt) const;
  49.     int getRightSide(POINT *apt) const;
  50.  
  51.     // Determines if the piece has a point (x, y)
  52.     bool isPointExists(int x, int y) const;
  53.  
  54.     // Prints a piece (for debugging)
  55.     void print() const;
  56.  
  57. protected:
  58.     // POINT array of which the piece is composed
  59.     POINT *body;
  60.  
  61.     // Number of points in body
  62.     int nPoints;
  63.  
  64.     // Make rotation more faster
  65.     int width;
  66.     int height;
  67.  
  68.     // Piece type ID and rotation
  69.     int id;
  70.     int rotation;
  71.  
  72.     // Piece color in RGB
  73.     COLORREF color;
  74. };
  75.  
  76. #endif // PIECE_H
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement