This repository was archived by the owner on Sep 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtetrixlogic.h
More file actions
80 lines (69 loc) · 1.7 KB
/
tetrixlogic.h
File metadata and controls
80 lines (69 loc) · 1.7 KB
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
#pragma once
#include <QBasicTimer>
#include <QFrame>
#include "tetrixcube.h"
const int blockNumH = 20;
const int blockNumW = 10;
QT_BEGIN_NAMESPACE
class QLabel;
QT_END_NAMESPACE
class TetrixLogic : public QFrame
{
Q_OBJECT
public:
TetrixLogic(QWidget* parent = 0);
//QBasicTimer run_timer;
void setNextCubeLabel(QLabel* label)
{
nextCubeLabel = label;
}
public slots:
void start();
void pause();
signals:
void scoreChanged(int score);
void levelChanged(int level);
void removedLinesChanged(int lines);
protected:
void paintEvent(QPaintEvent* event) override;
void keyPressEvent(QKeyEvent* event) override;
void timerEvent(QTimerEvent* event) override;
private:
void createCube();
bool move(const TetrixCube&, int, int);
void initArea();
void cubeFall();
void removeFullLines();
void toBottom();
void painteBlock(QPainter&, int, int, TetrixShape, int flag = 1);
void promptNextCube();
void promptBottom();
bool proMove(const TetrixCube&, int, int);
int blockUnitWidth()
{
return contentsRect().width() / blockNumW;
}
int blockUnitHeight()
{
return contentsRect().height() / blockNumH;
}
bool isStarted;
bool isPaused;
int removedLines;
int score;
int level;
int refresh_time = 1000;
int cubeX;
int cubeY;
int bottomX;
int bottomY;
QBasicTimer game_timer;
TetrixCube cubeNow;
TetrixCube cubeNext;
TetrixCube cubeBottom;
TetrixShape blocks_shape[blockNumH * blockNumW];
QLabel* nextCubeLabel;
};
//游戏区域定义为Area,其中包括若干不同shape的cube
//每个cube有4个block
//每个block均含有一对坐标存储于key_points[2]数组