forked from alvarosamudio/Tetris-DTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget.h
80 lines (66 loc) · 1.3 KB
/
widget.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef WIDGET_H
#define WIDGET_H
#include <DWidget>
const int BLOCK_SIZE=25;
const int MARGIN=5;
const int AREA_ROW=20;
const int AREA_COL=12;
enum Direction
{
UP,
DOWN,
LEFT,
RIGHT,
SPACE
};
struct Border
{
int ubound;
int dbound;
int lbound;
int rbound;
};
struct block_point
{
int pos_x;
int pos_y;
};
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
void InitGame();
void StartGame();
void GameOver();
void ResetBlock();
void BlockMove(Direction dir);
void BlockRotate(int block[4][4]);
void CreateBlock(int block[4][4],int block_id);
void GetBorder(int block[4][4],Border &border);
void ConvertStable(int x,int y);
bool IsCollide(int x,int y,Direction dir);
public:
explicit Widget(QWidget *parent = 0);
~Widget();
virtual void paintEvent(QPaintEvent *event);
virtual void timerEvent(QTimerEvent *event);
virtual void keyPressEvent(QKeyEvent *event);
private:
Ui::Widget *ui;
private:
int game_area[AREA_ROW][AREA_COL];
block_point block_pos;
int cur_block[4][4];
Border cur_border;
int next_block[4][4];
bool isStable;
int score;
int game_timer;
int paint_timer;
int speed_ms;
int refresh_ms;
};
#endif // WIDGET_H