summaryrefslogtreecommitdiffstats
path: root/src/snake.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/snake.cpp')
-rw-r--r--src/snake.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/snake.cpp b/src/snake.cpp
index 5246a3c..9c7fefa 100644
--- a/src/snake.cpp
+++ b/src/snake.cpp
@@ -126,10 +126,10 @@ GameCore::GameCore(QWidget *widget)
}
qDebug() << "Field:" << _width << _height;
addFood();
- QTimer *t = new QTimer(widget);
- t->start(15);
+ _t = new QTimer(widget);
+ _t->start(15);
// GAME
- QTimer::connect(t, &QTimer::timeout, [this]() {
+ QTimer::connect(_t, &QTimer::timeout, [this]() {
//
static int tick = 0;
++tick;
@@ -392,6 +392,10 @@ GameCore::GameCore(QWidget *widget)
GameCore::~GameCore()
{
free(_field);
+ if(_t->isActive()) {
+ _t->stop();
+ }
+ _widget->update();
}
void GameCore::scanDir(Snake *snake, int dx, int dy, const Cell* &what, int &dist)
@@ -453,6 +457,15 @@ void GameCore::initField()
_widget->update();
}
+void GameCore::pauseAndResume()
+{
+ if(_t->isActive()) {
+ _t->stop();
+ } else {
+ _t->start();
+ }
+}
+
void GameCore::addFood()
{
for (int i = 0; i < 10; ++i) {