Advertisement
Amorf

Untitled

Dec 14th, 2021
726
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.55 KB | None | 0 0
  1. #ifndef LEVEL_H
  2. #define LEVEL_H
  3.  
  4. #include "DrawEngine.h"
  5. #include "PieceSet.h"
  6. #include <windows.h>
  7.  
  8. //
  9. // Level stores current snapshot of the game, including the dropping piece,
  10. // the next piece, the piece generator (PieceSet), the position of the
  11. // dropping piece, the width and height of the level, the dropping speed,
  12. // and a two-dimentional color array that is used to represent the canvas.
  13. //
  14. class Level
  15. {
  16. public:
  17.     // de: used to draw the level
  18.     // width & height: level size in cells
  19.     Level(DrawEngine &de, int width = 10, int height = 20);
  20.     ~Level();
  21.  
  22.     // Draws the level
  23.     void drawBoard() const;
  24.  
  25.     // Rotates the dropping piece, returns true if successful
  26.     bool rotate();
  27.  
  28.     // Moves the dropping piece, returns true if successful
  29.     // cxDistance is horizontal movement, positive value is right
  30.     // cyDistance is vertical movement, positive value is up (normally it's
  31.     // negaive)
  32.     bool move(int cxDistance, int cyDistance);
  33.  
  34.     // Updates the level based on the current speed
  35.     void timerUpdate();
  36.  
  37.     bool isGameOver();
  38.  
  39.     // Draw different kinds of info
  40.     void drawSpeed() const;
  41.     void drawScore() const;
  42.     void drawNextPiece() const;
  43.  
  44. protected:
  45.     // Places a piece somewhere
  46.     // If there isn't enough space, does nothing and returns false
  47.     bool place(int x, int y, const Piece &piece);
  48.  
  49.     // Clears a piece on the canvas
  50.     void clear(const Piece& piece);
  51.  
  52.     // Releases the next dropping piece
  53.     void dropRandomPiece();
  54.  
  55.     // Checks if the piece hits the boundary
  56.     bool isHitBottom() const;
  57.     bool isHitLeft() const;
  58.     bool isHitRight() const;
  59.  
  60.     // Checks if a piece can move to a position
  61.     bool isCovered(const Piece &piece, int x, int y) const;
  62.  
  63.     // Clears "full" rows, returns the number of rows being cleared
  64.     int clearRows();
  65.  
  66.     COLORREF **board;    // The cavnas, the drawing board
  67.     DrawEngine &de;      // Does graphics stuffs
  68.     PieceSet pieceSet;   // Piece generator
  69.     Piece *current;      // Current dropping piece
  70.     Piece *next;         // Next piece
  71.     int width;           // Level width (in cells)
  72.     int height;          // Level height
  73.     int posX;            // X coordinate of dropping piece (Cartesian system)
  74.     int posY;            // Y coordinate of dropping piece
  75.     int speed;           // Drop a cell every _speed_ millisecs
  76.     double lastTime;     // Last time updated
  77.     double currentTime;  // Current update time
  78.     int score;           // Player's score
  79. };
  80.  
  81. #endif // LEVEL_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement