From e1dea7ffbff1b75025b7f781d575bd5603fc34d0 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Wed, 6 Jan 2010 17:04:24 +0200 Subject: [PATCH] Making the flow animation skippable. --- src/game.cpp | 27 ++++++++++++++++++++------- src/game.h | 5 ++++- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index d64f3aa..8fab98d 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -294,7 +294,7 @@ GameController::GameController(AvailablePieces* pieceUi, GameField* fieldUi, : pieceUi(pieceUi), fieldUi(fieldUi), timeLabel(timeLabel), doneButton(doneButton), currentPiece(ppieces), rows(0), cols(0), timeLeft(0), levelRunning(false), neededFlow(0), - startRow(0), startCol(0), startDir(DirNone), flowRow(0), flowCol(0), flowDir(DirNone), flowPreplaced(0), flowScore(0) + startRow(0), startCol(0), startDir(DirNone), flowRow(0), flowCol(0), flowDir(DirNone), flowPreplaced(0), flowScore(0), animate(true) { connect(fieldUi, SIGNAL(cellClicked(int, int)), this, SLOT(onCellClicked(int, int))); connect(pieceUi, SIGNAL(invalidPieceSelected()), @@ -304,7 +304,7 @@ GameController::GameController(AvailablePieces* pieceUi, GameField* fieldUi, connect(this, SIGNAL(pieceUsed(const Piece*)), pieceUi, SLOT(onPieceUsed(const Piece*))); - connect(doneButton, SIGNAL(clicked()), this, SLOT(levelEnds())); + connect(doneButton, SIGNAL(clicked()), this, SLOT(onDoneClicked())); // Setup the timer, but don't start it yet timer.setInterval(1000); @@ -404,7 +404,7 @@ void GameController::startLevel(QString fileName) // Clear piece selection onInvalidPieceSelected(); - doneButton->setEnabled(true); + doneButton->setText("Done"); timer.start(); levelRunning = true; file.close(); @@ -438,12 +438,25 @@ void GameController::onInvalidPieceSelected() currentPiece = ppieces; } +void GameController::onDoneClicked() +{ + // If the level was running, start flowing the liquid + if (levelRunning) + levelEnds(); + // Else, skip the flowing animation + else { + animate = false; + flowTimer.setInterval(0); + } +} + void GameController::levelEnds() { if (!levelRunning) return; - doneButton->setEnabled(false); + doneButton->setText("Next"); levelRunning = false; + animate = true; timer.stop(); // Initiate computing the flow @@ -479,7 +492,7 @@ void GameController::computeFlow() // some more time, so that the user sees the failure before we // emit levelFailed. flowDir = DirFailed; - flowTimer.setInterval(1000); + if (animate) flowTimer.setInterval(1000); return; } flowScore += 10; @@ -493,7 +506,7 @@ void GameController::computeFlow() else flowDir = DirPassed; - flowTimer.setInterval(1000); + if (animate) flowTimer.setInterval(1000); return; } @@ -518,7 +531,7 @@ void GameController::computeFlow() if (flowRow < 0 || flowCol < 0 || flowRow >= rows || flowCol >= cols) { // Out of bounds flowDir = DirFailed; - flowTimer.setInterval(1000); + if (animate) flowTimer.setInterval(1000); return; } diff --git a/src/game.h b/src/game.h index df62499..4fa333d 100644 --- a/src/game.h +++ b/src/game.h @@ -192,14 +192,16 @@ signals: void levelFailed(); private slots: + void onDoneClicked(); void onCellClicked(int row, int column); void onValidPieceSelected(const Piece* piece); void onInvalidPieceSelected(); void onTimeout(); - void levelEnds(); void computeFlow(); private: + void levelEnds(); + AvailablePieces* pieceUi; // Not owned GameField* fieldUi; // Not owned QLabel* timeLabel; // Not owned @@ -222,6 +224,7 @@ private: Direction flowDir; int flowPreplaced; int flowScore; + bool animate; }; class LevelSwitcher : public QObject -- 1.7.9.5