-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtetrisboard.h
82 lines (67 loc) · 1.79 KB
/
tetrisboard.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
81
82
#ifndef TETRISBOARD_H_147891934_73291965_168
#define TETRISBOARD_H_147891934_73291965_168
#include "tetrispiece.h"
#include <QFrame>
#include <QBasicTimer>
#include <QTimerEvent>
#include <QPainter>
#include <QEvent>
#include <QKeyEvent>
//#include <QGamepad>
class TetrisBoard : public QFrame
{
Q_OBJECT
public:
explicit TetrisBoard(QWidget *parent = nullptr);
signals:
void scoreChanged(int score);
void levelChanged(int level);
void linesRemovedChanged(int numLines);
public slots:
void start();
void pause();
/*
private slots:
void bLeft();
void bRight();
void bRotateLeft();
void bRotateRight();
void bDropDown();
void bDown();
void bStart();
void bPause();
void bQuit();
*/
private:
enum Coordinates { Height = 22, Width = 10 };
TetrisShape& shapeAt(int x, int y) { return board[x][y]; }
inline int timeout() const { return 500/(level + 1); }
inline int squareHeight() const { return contentsRect().height() / Height; }
inline int squareWidth() const { return contentsRect().width() / Width ; }
void draw(QPainter& painter, int x, int y, TetrisShape shape) const;
bool tryMove(const TetrisPiece& piece, int x, int y);
void removeFullLines();
void pieceDropped();
void newPiece();
void oneLineDown();
void clear();
bool started;
bool paused;
bool waiting; // waiting a new piece
int level;
int score;
int linesRemoved;
int curX;
int curY;
int pieceNum;
TetrisPiece current;
TetrisPiece next;
TetrisShape board[Width][Height];
QBasicTimer timer;
//QGamepad gamepad;
protected:
void paintEvent(QPaintEvent *event) override;
void timerEvent(QTimerEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
};
#endif