Tetris Base Game

Dependencies:   4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player

Committer:
jsanchez307
Date:
Wed Nov 30 21:57:25 2022 +0000
Revision:
0:1858f2b100fd
Tetris Skeleton V 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jsanchez307 0:1858f2b100fd 1 #ifndef _BOARD_
jsanchez307 0:1858f2b100fd 2 #define _BOARD_
jsanchez307 0:1858f2b100fd 3
jsanchez307 0:1858f2b100fd 4 // ------ Includes -----
jsanchez307 0:1858f2b100fd 5
jsanchez307 0:1858f2b100fd 6 #include "Pieces.h"
jsanchez307 0:1858f2b100fd 7
jsanchez307 0:1858f2b100fd 8 // ------ Defines -----
jsanchez307 0:1858f2b100fd 9
jsanchez307 0:1858f2b100fd 10 #define BOARD_LINE_WIDTH 6 // Width of each of the two lines that delimit the board
jsanchez307 0:1858f2b100fd 11 #define BLOCK_SIZE 6 // Width and Height of each block of a piece
jsanchez307 0:1858f2b100fd 12 #define BOARD_POSITION 50 // Center position of the board from the left of the screen
jsanchez307 0:1858f2b100fd 13 #define BOARD_WIDTH 10 // Board width in blocks
jsanchez307 0:1858f2b100fd 14 #define BOARD_HEIGHT 20 // Board height in blocks
jsanchez307 0:1858f2b100fd 15 #define MIN_VERTICAL_MARGIN 8 // Minimum vertical margin for the board limit
jsanchez307 0:1858f2b100fd 16 #define MIN_HORIZONTAL_MARGIN 20 // Minimum horizontal margin for the board limit
jsanchez307 0:1858f2b100fd 17 #define PIECE_BLOCKS 5 // Number of horizontal and vertical blocks of a matrix piece
jsanchez307 0:1858f2b100fd 18
jsanchez307 0:1858f2b100fd 19
jsanchez307 0:1858f2b100fd 20 // --------------------------------------------------------------------------------
jsanchez307 0:1858f2b100fd 21 // Board
jsanchez307 0:1858f2b100fd 22 // --------------------------------------------------------------------------------
jsanchez307 0:1858f2b100fd 23
jsanchez307 0:1858f2b100fd 24 class Board
jsanchez307 0:1858f2b100fd 25 {
jsanchez307 0:1858f2b100fd 26 public:
jsanchez307 0:1858f2b100fd 27
jsanchez307 0:1858f2b100fd 28 Board (Pieces *pPieces, int pScreenHeight);
jsanchez307 0:1858f2b100fd 29
jsanchez307 0:1858f2b100fd 30 int GetXPosInPixels (int pPos);
jsanchez307 0:1858f2b100fd 31 int GetYPosInPixels (int pPos);
jsanchez307 0:1858f2b100fd 32 bool IsFreeBlock (int pX, int pY);
jsanchez307 0:1858f2b100fd 33 bool IsPossibleMovement (int pX, int pY, int pPiece, int pRotation);
jsanchez307 0:1858f2b100fd 34 void StorePiece (int pX, int pY, int pPiece, int pRotation);
jsanchez307 0:1858f2b100fd 35 int DeletePossibleLines ();
jsanchez307 0:1858f2b100fd 36 bool IsGameOver ();
jsanchez307 0:1858f2b100fd 37
jsanchez307 0:1858f2b100fd 38 private:
jsanchez307 0:1858f2b100fd 39
jsanchez307 0:1858f2b100fd 40 // enum holds no value besides the described properties
jsanchez307 0:1858f2b100fd 41 enum { POS_FREE, POS_FILLED }; // POS_FREE = free position of the board; POS_FILLED = filled position of the board
jsanchez307 0:1858f2b100fd 42 int mBoard [BOARD_WIDTH][BOARD_HEIGHT]; // Board that contains the pieces
jsanchez307 0:1858f2b100fd 43 Pieces *mPieces;
jsanchez307 0:1858f2b100fd 44 int mScreenHeight;
jsanchez307 0:1858f2b100fd 45
jsanchez307 0:1858f2b100fd 46 void InitBoard();
jsanchez307 0:1858f2b100fd 47 void DeleteLine (int pY);
jsanchez307 0:1858f2b100fd 48 };
jsanchez307 0:1858f2b100fd 49
jsanchez307 0:1858f2b100fd 50 #endif