diff --git a/src/libreminesgameengine.cpp b/src/libreminesgameengine.cpp index 20f480a..029017a 100644 --- a/src/libreminesgameengine.cpp +++ b/src/libreminesgameengine.cpp @@ -259,7 +259,7 @@ void LibreMinesGameEngine::vResetPrincipalMatrix() principalMatrix.clear(); } -bool LibreMinesGameEngine::bCleanCell(const uchar _X, const uchar _Y) +bool LibreMinesGameEngine::bCleanCell(const uchar _X, const uchar _Y, const bool recursive) { if(principalMatrix[_X][_Y].flagState == FlagState::NoFlag && principalMatrix[_X][_Y].value == CellValue::MINE) @@ -274,7 +274,7 @@ bool LibreMinesGameEngine::bCleanCell(const uchar _X, const uchar _Y) { // Unlock the cell principalMatrix[_X][_Y].isHidden = false; - Q_EMIT SIGNAL_showCell(_X, _Y); + Q_EMIT SIGNAL_showCell(_X, _Y, recursive); // If the state of the cell is CellValue::ZERO, unlock all neighbor cells if(principalMatrix[_X][_Y].value == CellValue::ZERO) @@ -555,7 +555,7 @@ void LibreMinesGameEngine::SLOT_cleanCell(const uchar _X, const uchar _Y) SLOT_startTimer(); bFirst = false; } - bCleanCell(_X, _Y); + bCleanCell(_X, _Y, false); } void LibreMinesGameEngine::SLOT_changeFlagState(const uchar _X, const uchar _Y) @@ -614,6 +614,8 @@ void LibreMinesGameEngine::SLOT_startTimer() void LibreMinesGameEngine::SLOT_cleanNeighborCells(const uchar _X, const uchar _Y) { + + bool recursive = false; // Clean all hided and unflaged neighbor flags for(short i=_X-1; i<=_X+1; i++) { @@ -629,8 +631,10 @@ void LibreMinesGameEngine::SLOT_cleanNeighborCells(const uchar _X, const uchar _ if(cell.isHidden && cell.flagState == FlagState::NoFlag) { - if(!bCleanCell(i, j)) + if(!bCleanCell(i, j, recursive)) return; + + recursive = true; } } } diff --git a/src/libreminesgameengine.h b/src/libreminesgameengine.h index 57d61ca..59b4dfa 100644 --- a/src/libreminesgameengine.h +++ b/src/libreminesgameengine.h @@ -64,7 +64,15 @@ class LibreMinesGameEngine: public QObject private: void vResetPrincipalMatrix(); - bool bCleanCell(const uchar _X, const uchar _Y); + + /** + * @brief Clear the cell in the #_X, #_Y position. + * Create the condition of game lost if the cell is a MINE. + * Clear all neighbor cells if the cell is ZERO + * + * @param recursive - Indicates this cell is being cleared along with another cell. + */ + bool bCleanCell(const uchar _X, const uchar _Y, const bool recursive=true); void vGameLost(const uchar _X, const uchar _Y); void vGameWon(); @@ -92,7 +100,7 @@ class LibreMinesGameEngine: public QObject bool bGameActive; Q_SIGNALS: - void SIGNAL_showCell(const uchar _X, const uchar _Y); + void SIGNAL_showCell(const uchar _X, const uchar _Y, const bool recursive); void SIGNAL_endGameScore(LibreMinesScore score, int iCorrectFlags, int iWrongFlags, diff --git a/src/libreminesgui.cpp b/src/libreminesgui.cpp index 7e0f539..fa485c1 100644 --- a/src/libreminesgui.cpp +++ b/src/libreminesgui.cpp @@ -1169,7 +1169,7 @@ void LibreMinesGui::SLOT_onCellLabelClicked(const QMouseEvent *const e) } -void LibreMinesGui::SLOT_showCell(const uchar _X, const uchar _Y) +void LibreMinesGui::SLOT_showCell(const uchar _X, const uchar _Y, const bool recursive) { principalMatrix[_X][_Y].button->hide(); @@ -1180,7 +1180,10 @@ void LibreMinesGui::SLOT_showCell(const uchar _X, const uchar _Y) } - Q_EMIT(sound->SIGNAL_releaseCell()); + if(!recursive) + { + Q_EMIT(sound->SIGNAL_releaseCell()); + } } void LibreMinesGui::SLOT_endGameScore(LibreMinesScore score, @@ -1963,5 +1966,4 @@ void LibreMinesGui::vUpdatePreferences() } sound->setVolume(preferences->optionSoundVolume()); - sound->setMuted(preferences->optionSoundVolume() == 0); } diff --git a/src/libreminesgui.h b/src/libreminesgui.h index 6345491..4c0dd0c 100644 --- a/src/libreminesgui.h +++ b/src/libreminesgui.h @@ -181,7 +181,7 @@ private Q_SLOTS: void SLOT_onCellLabelReleased(const QMouseEvent*const e); void SLOT_onCellLabelClicked(const QMouseEvent*const e); - void SLOT_showCell(const uchar _X, const uchar _Y); + void SLOT_showCell(const uchar _X, const uchar _Y, const bool recursive); void SLOT_endGameScore(LibreMinesScore score, int iCorrectFlags, int iWrongFlags, diff --git a/src/soundeffects.cpp b/src/soundeffects.cpp index ce84737..91def3c 100644 --- a/src/soundeffects.cpp +++ b/src/soundeffects.cpp @@ -4,14 +4,13 @@ SoundEffects::SoundEffects(QObject* parent) : QObject( parent ), - soundEffects( {&soundGameBegin, &soundGameWon, &soundGameLost, &soundClockTick, + soundEffects( {&soundGameBegin, &soundGameWon, &soundGameLost, &soundKeyboardControllMove, &soundReleaseCell, &soundFlagCell} ) { soundGameBegin.setSource(QUrl("qrc:/sound_effects/clock_tick.wav")); soundGameWon.setSource(QUrl("qrc:/sound_effects/game_won.wav")); soundGameLost.setSource(QUrl("qrc:/sound_effects/game_lost.wav")); - soundClockTick.setSource(QUrl("qrc:/sound_effects/clock_tick.wav")); soundKeyboardControllMove.setSource(QUrl("qrc:/sound_effects/move.wav")); soundReleaseCell.setSource(QUrl("qrc:/sound_effects/release_cell.wav")); @@ -23,8 +22,6 @@ SoundEffects::SoundEffects(QObject* parent) : connect(this, &SoundEffects::SIGNAL_gameLost, &soundGameLost, &QSoundEffect::play); - connect(this, &SoundEffects::SIGNAL_clockTick, - &soundClockTick, &QSoundEffect::play); connect(this, &SoundEffects::SIGNAL_keyboardControllerMove, &soundKeyboardControllMove, &QSoundEffect::play); @@ -41,13 +38,7 @@ void SoundEffects::setVolume(const int vol) for(QSoundEffect* sound : soundEffects) { sound->setVolume(vol/100.f); + sound->setMuted(vol == 0); } } -void SoundEffects::setMuted(const bool mute) -{ - for(QSoundEffect* sound : soundEffects) - { - sound->setMuted(mute); - } -} diff --git a/src/soundeffects.h b/src/soundeffects.h index a5dbc71..8a82c22 100644 --- a/src/soundeffects.h +++ b/src/soundeffects.h @@ -12,14 +12,12 @@ class SoundEffects : public QObject SoundEffects(QObject* parent = nullptr); void setVolume(const int vol); - void setMuted(const bool mute); Q_SIGNALS: void SIGNAL_gameBegin(); void SIGNAL_gameWon(); void SIGNAL_gameLost(); - void SIGNAL_clockTick(); void SIGNAL_keyboardControllerMove(); void SIGNAL_releaseCell(); @@ -29,7 +27,6 @@ class SoundEffects : public QObject QSoundEffect soundGameBegin; QSoundEffect soundGameWon; QSoundEffect soundGameLost; - QSoundEffect soundClockTick; QSoundEffect soundKeyboardControllMove; QSoundEffect soundReleaseCell;