-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameboard.cpp
38 lines (29 loc) · 900 Bytes
/
gameboard.cpp
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
#include "gameboard.h"
#include "game.h"
#include <QColor>
GameBoard::GameBoard(Game *game, QWidget *parent) : QWidget(parent), _game(game) {
connect(_game,SIGNAL(changed()),this,SLOT(update()));
setMinimumSize(_game->size());
setFocusPolicy(Qt::StrongFocus);
_pen = QPen(QColor(220,220,220));
_pen.setWidth(2);
_scoreController = new ScoreController(_game, this);
}
void GameBoard::paintEvent(QPaintEvent * /* event */ ) {
if (_game->started()){
QPainter painter;
painter.begin(this);
painter.setPen(_pen);
_game->draw(painter);
_scoreController->show();
painter.end();
} else {
_scoreController->hide();
}
}
void GameBoard::keyPressEvent ( QKeyEvent * event ) {
_game->keyPressed(event->key());
}
void GameBoard::keyReleaseEvent ( QKeyEvent * event ) {
_game->keyReleased(event->key());
}