Commit fc3fd5cd authored by Julian Helfferich's avatar Julian Helfferich 💬
Browse files

Call updateLayout() also in stopGame()

Calling updateLayout() means that all remaining game actions are
processed when the game is intended to be stopped. This has the effect
that the play area is updated before the highscore window is shown,
not at a later time.

BUG: 407244
parent 49397678
......@@ -21,14 +21,16 @@ class testKBlocksItemGroup : public QObject
{
Q_OBJECT
private slots:
void testUpdateGameShouldProcessGameActionsOnGameOver();
void updateGameShouldProcessGameActionsOnGameOver();
void stopGameShouldProcessRemainingGameActions();
};
void testKBlocksItemGroup::testUpdateGameShouldProcessGameActionsOnGameOver()
void testKBlocksItemGroup::updateGameShouldProcessGameActionsOnGameOver()
{
/**
* When the game is stopped (on game over), updateLayout needs to be
* called. Otherwise, the play area does not show where the last item
* When updateGame is called, updateLayout should be called even
* when the game is over. Otherwise, some game actions are not
* processed and the play area does not show where the last item
* has moved, causing the game to be over.
*
* See bug 407244
......@@ -46,6 +48,27 @@ void testKBlocksItemGroup::testUpdateGameShouldProcessGameActionsOnGameOver()
QCOMPARE( mock->numberOfPickGameActionCalls, 1 );
}
void testKBlocksItemGroup::stopGameShouldProcessRemainingGameActions()
{
/**
* When the game is stopped (on game over), updateLayout needs to be
* called. Otherwise, the play area is updated only after highscore
* has been shown.
*
* See bug 407244
*/
std::unique_ptr<SingleGameInterface> pSingleGame( new MockSingleGame() );
std::unique_ptr<GraphicsInterface> pGraphics( new MockGraphics() );
std::unique_ptr<SoundInterface> pSound( new MockSound() );
KBlocksItemGroup itemGroup(0, pSingleGame.get(), pGraphics.get(), pSound.get() );
itemGroup.stopGame();
MockSingleGame *mock = dynamic_cast<MockSingleGame*>(pSingleGame.get());
QCOMPARE( mock->numberOfPickGameActionCalls, 1 );
}
QTEST_MAIN(testKBlocksItemGroup)
#include "test_KBlocksItemGroup.moc"
/***************************************************************************
* KBlocks, a falling blocks game by KDE *
* Copyright (C) 2010 Mauricio Piacentini <mauricio@tabuleiro.com> *
* Zhongjie Cai <squall.leonhart.cai@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
/******************************************************************************
* KBlocks, a falling blocks game by KDE *
* Copyright (C) 2010-2021 Mauricio Piacentini <mauricio@tabuleiro.com> *
* Zhongjie Cai <squall.leonhart.cai@gmail.com> *
* Julian Helfferich <julian.helfferich@mailbox.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
******************************************************************************/
#include "GraphicsInterface.h"
#include "SoundInterface.h"
......@@ -133,6 +134,7 @@ void KBlocksItemGroup::startGame()
void KBlocksItemGroup::stopGame()
{
updateGame();
mUpdateTimer.stop();
}
......
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