Retro_Gameboy
The purpose of this project is to create a GameBoy with classic games.
Tetris.h
Go to the documentation of this file.
1 #ifndef TETRIS_H
2 #define TETRIS_H
3 #include "GameGenerics.h"
4 
5 class Tetris : public GameGenerics
6 {
7 
8  private:
9 
11  static const int M = 20;
12 
14  static const int N = 10;
15 
18  int field[M][N];
19 
20  // __ __
21  // | 0| 1|
22  // |__|__|
23  // | 2| 3|
24  // |__|__|
25  // | 4| 5|
26  // |__|__|
27  // | 6| 7|
28  // |__|__|
29 
40  const int figures[7][4] =
41  {
42  1,3,5,7, // I
43  2,4,5,7, // Z
44  3,5,4,6, // S
45  3,5,4,7, // T
46  2,3,5,7, // L
47  3,5,7,6, // J
48  2,3,4,5, // O
49 
50  };
51 
53  struct Point
54  {
55  int x, y;
56  };
57 
59  Point a[4];
60 
62  Point b[4];
63 
67  bool Check();
68 
70  void MoveTile( const int position = 0 );
71 
73  void RotateTile( const bool rotate = false );
74 
76  float MoveDownTilePerClick( float timer, const float delay, int& colorNum );
77 
79  void CheckLines();
80 
82  void Draw( Sprite& sprite, Sprite& background, Sprite& frame, RenderWindow& window, const int& colorNum );
83 
84  // Event Handler.
85  void EventHandler( bool& rotate, int& dx, RenderWindow& window );
86 
89  virtual int CalculateScore();
90 
91  public:
94  Tetris();
95 
97  void PlayTetris();
98 
99 
100 };
101 
102 #endif
Definition: Tetris.h:6
void MoveTile(const int position=0)
Move shapes horizontally.
Definition: Tetris.cpp:130
Tetris()
Default constructor. Used to intialize arrays.
Definition: Tetris.cpp:3
void Draw(Sprite &sprite, Sprite &background, Sprite &frame, RenderWindow &window, const int &colorNum)
Draw UI and shapes.
Definition: Tetris.cpp:242
const int figures[7][4]
Define 7 x 4 rectangle[ 7 rows, 4 coloumns] This defines the shapes. For example, these are the follo...
Definition: Tetris.h:40
float MoveDownTilePerClick(float timer, const float delay, int &colorNum)
Move shapes down for each tick.
Definition: Tetris.cpp:175
void EventHandler(bool &rotate, int &dx, RenderWindow &window)
Definition: Tetris.cpp:83
int field[M][N]
Define a 10 x 20 rectangle. This is use as the background for the game.
Definition: Tetris.h:18
static const int N
Define length of a rectangle.
Definition: Tetris.h:14
void RotateTile(const bool rotate=false)
Allow user to rotate shapes.
Definition: Tetris.cpp:148
Point a[4]
Use to move shapes.
Definition: Tetris.h:59
virtual int CalculateScore()
Pure virtual function inherited from GameGenerics.h Each game calculate scores differently and theref...
Definition: Tetris.cpp:235
bool Check()
Check the boundaries.
Definition: Tetris.cpp:112
void PlayTetris()
Play Tetris Game.
Definition: Tetris.cpp:25
static const int M
Define width of a rectangle.
Definition: Tetris.h:11
Point b[4]
Keep a backup.
Definition: Tetris.h:62
void CheckLines()
Reduce line upon completion.
Definition: Tetris.cpp:208
Denotes x and y points.
Definition: Tetris.h:54