Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 96884eaa authored by Laurent Montel's avatar Laurent Montel 😁

Patch from Sebastian Audet

KMines Reset After Game Over.

At the end of the game you are prompted to restart the same or continue to a new one.

You have the option of saying 'no' - besides that unless you're in a competition I don't think it should matter. Mainly I proposed the change because there are times when its impossible to do anything but guess (not even statistics) and this is a midway between a 'reveal' button and just flat out spending 4 minutes on something and failing.

Differential Revision: https://phabricator.kde.org/D17860
parent f1713564
......@@ -33,6 +33,17 @@ CellItem::CellItem(KGameRenderer* renderer, QGraphicsItem* parent)
reset();
}
void CellItem::unflag()
{
m_state = KMinesState::Released;
updatePixmap();
}
void CellItem::unexplode()
{
m_exploded = false;
}
void CellItem::reset()
{
m_state = KMinesState::Released;
......
......@@ -72,6 +72,14 @@ public:
* 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
*/
......
<ui version="4.0" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GeneralOptsConfig</class>
<widget class="QWidget" name="GeneralOptsConfig" >
<property name="geometry" >
<widget class="QWidget" name="GeneralOptsConfig">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
......@@ -9,20 +10,40 @@
<height>135</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout" >
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="kcfg_UseQuestionMarks" >
<property name="text" >
<widget class="QCheckBox" name="kcfg_UseQuestionMarks">
<property name="text">
<string>Use '?' marks</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer" >
<property name="orientation" >
<widget class="QCheckBox" name="kcfg_AllowKminesReset">
<property name="text">
<string>Allow KMines Reset</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="tristate">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="kcfg_DisableScoreOnReset">
<property name="text">
<string>Disable Score on Reset</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0" >
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
......
......@@ -9,6 +9,14 @@
<label>Whether the "unsure" marker may be used.</label>
<default>true</default>
</entry>
<entry name="AllowKminesReset" type="Bool" key="kmines_reset">
<label></label>
<default>true</default>
</entry>
<entry name="DisableScoreOnReset" type="Bool" key="disable_score_on_reset">
<label></label>
<default>false</default>
</entry>
</group>
<group name="Options">
<entry name="CustomWidth" type="Int" key="custom width">
......
......@@ -33,9 +33,11 @@
#include <QStatusBar>
#include <QDesktopWidget>
#include <KLocalizedString>
#include "ui_customgame.h"
#include "ui_generalopts.h"
#include "settings.h"
/*
* Classes for config dlg pages
......@@ -185,7 +187,7 @@ void KMinesMainWindow::onGameOver(bool won)
m_gameClock->pause();
m_actionPause->setEnabled(false);
Kg::difficulty()->setGameRunning(false);
if(won)
if(won && m_scene->canScore)
{
QPointer<KScoreDialog> scoreDialog = new KScoreDialog(KScoreDialog::Name | KScoreDialog::Time, this);
scoreDialog->initFromDifficulty(Kg::difficulty());
......@@ -202,6 +204,15 @@ void KMinesMainWindow::onGameOver(bool won)
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();
}
}
}
......
......@@ -32,6 +32,22 @@ MineFieldItem::MineFieldItem(KGameRenderer* renderer)
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 );
......
......@@ -54,6 +54,10 @@ public:
* @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
*/
......
......@@ -75,6 +75,12 @@ KMinesScene::KMinesScene( QObject* parent )
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);
......
......@@ -53,6 +53,14 @@ public:
* 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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment