diff --git a/cellitem.h b/cellitem.h --- a/cellitem.h +++ b/cellitem.h @@ -72,6 +72,14 @@ * I.e. resets revealed state */ void unreveal() { m_state = KMinesState::Released; updatePixmap(); } + /** + * Removes the flag + */ + void unflag(); + /** + * Stops the mine from being exploded + */ + void unexplode(); /** * @return whether this cell is revealed */ diff --git a/cellitem.cpp b/cellitem.cpp --- a/cellitem.cpp +++ b/cellitem.cpp @@ -33,6 +33,17 @@ reset(); } +void CellItem::unflag() +{ + m_state = KMinesState::Released; + updatePixmap(); +} + +void CellItem::unexplode() +{ + m_exploded = false; +} + void CellItem::reset() { m_state = KMinesState::Released; diff --git a/generalopts.ui b/generalopts.ui --- a/generalopts.ui +++ b/generalopts.ui @@ -1,28 +1,49 @@ - + + GeneralOptsConfig - - + + 0 0 316 135 - + - - + + Use '?' marks - - + + + Allow KMines Reset + + + true + + + false + + + + + + + Disable Score on Reset + + + + + + Qt::Vertical - + 20 40 diff --git a/kmines.kcfg b/kmines.kcfg --- a/kmines.kcfg +++ b/kmines.kcfg @@ -9,6 +9,14 @@ true + + + true + + + + false + diff --git a/mainwindow.cpp b/mainwindow.cpp --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -33,9 +33,11 @@ #include #include +#include #include "ui_customgame.h" #include "ui_generalopts.h" +#include "settings.h" /* * Classes for config dlg pages @@ -185,7 +187,7 @@ m_gameClock->pause(); m_actionPause->setEnabled(false); Kg::difficulty()->setGameRunning(false); - if(won) + if(won && m_scene->canScore) { QPointer scoreDialog = new KScoreDialog(KScoreDialog::Name | KScoreDialog::Time, this); scoreDialog->initFromDifficulty(Kg::difficulty()); @@ -202,6 +204,15 @@ scoreDialog->exec(); delete scoreDialog; + } else if (!won) + { + //ask to reset + if (Settings::allowKminesReset() && QMessageBox::question(this, i18n("Reset?"), i18n("Reset the Game?")) == QMessageBox::Yes){ + m_scene->reset(); + m_gameClock->restart(); + m_actionPause->setEnabled(true); + m_scene->canScore = !Settings::disableScoreOnReset(); + } } } diff --git a/minefielditem.h b/minefielditem.h --- a/minefielditem.h +++ b/minefielditem.h @@ -54,6 +54,10 @@ * @param numMines number of mines */ void initField( int numRows, int numCols, int numMines ); + /** + * Resets mines to the intial state. + */ + void resetMines(); /** * Resizes this graphics item so it fits in given rect */ diff --git a/minefielditem.cpp b/minefielditem.cpp --- a/minefielditem.cpp +++ b/minefielditem.cpp @@ -32,6 +32,22 @@ setFlag(QGraphicsItem::ItemHasNoContents); } +void MineFieldItem::resetMines() +{ + m_gameOver = false; + m_numUnrevealed = m_numRows*m_numCols; + + for(CellItem* item : m_cells) { + item->unreveal(); + item->unflag(); + item->unexplode(); + } + + m_flaggedMinesCount = 0; + emit flaggedMinesCountChanged(m_flaggedMinesCount); +} + + void MineFieldItem::initField( int numRows, int numCols, int numMines ) { numMines = qMin(numMines, numRows*numCols - MINIMAL_FREE ); diff --git a/scene.h b/scene.h --- a/scene.h +++ b/scene.h @@ -53,6 +53,14 @@ * Toggles paused state for all cells in the field item */ void setGamePaused(bool paused); + /** + * Resets the scene + */ + void reset(); + /** + * Represents if the scores should be considered for the highscores + */ + bool canScore; KGameRenderer& renderer() {return m_renderer;} Q_SIGNALS: diff --git a/scene.cpp b/scene.cpp --- a/scene.cpp +++ b/scene.cpp @@ -75,6 +75,12 @@ setBackgroundBrush(m_renderer.spritePixmap(QStringLiteral( "mainWidget" ), sceneRect().size().toSize())); } +void KMinesScene::reset() +{ + m_fieldItem->resetMines(); + m_messageItem->forceHide(); +} + void KMinesScene::resizeScene(int width, int height) { setSceneRect(0, 0, width, height);