Advertisement
Amorf

Untitled

Dec 14th, 2021
952
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #ifndef PIECESET_H
  2. #define PIECESET_H
  3.  
  4. #include "Piece.h"
  5.  
  6. //
  7. // PieceSet generates 7 types of pieces. Each piece has 4 rotations, so there
  8. // are 7 x 4 = 28 configurations in total.
  9. //
  10. // All 28 configurations are kept in memory after you new PieceSet(). To get
  11. // get piece, use getPiece() or getRandomPiece().
  12. //
  13. class PieceSet
  14. {
  15. public:
  16.     // Constants
  17.     enum { NUM_ROTATIONS = 4, NUM_PIECES = 7 };
  18.  
  19.     PieceSet();
  20.     ~PieceSet();
  21.  
  22.     // Gets a specific piece
  23.     // id: one of 7 piece types (0-6)
  24.     // rotation: one of 4 rotations (0-3)
  25.     Piece *getPiece(int id, int rotation = 0) const;
  26.  
  27.     // Gets a random piece
  28.     inline Piece *getRandomPiece() const
  29.     {
  30.         return getPiece(rand() % NUM_PIECES, rand() % NUM_ROTATIONS);
  31.     }
  32.  
  33. protected:
  34.     // Stores all 28 configurations of pieces
  35.     Piece *pieces[NUM_PIECES][NUM_ROTATIONS];
  36.  
  37.     // Initializes piece rotations
  38.     void rotateAll();
  39.  
  40.     // Rotates points by 90 degrees counterclockwise
  41.     void rotate(POINT *apt, int numPoints = 4);
  42. };
  43.  
  44. #endif // PIECESET_H
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement