Commit 5e9bd5a1 authored by Julian Helfferich's avatar Julian Helfferich 💬
Browse files

Refresh items also on game over

If items are not refreshed, the final piece (causing the game to be
over) will be invisible. With this change, it will be correctly
displayed, making it obvious why the game is over.
parent 2d6f98c5
......@@ -14,6 +14,7 @@
#include "Testing/MockGraphics.h"
#include "Testing/MockSingleGame.h"
#include "Testing/MockSound.h"
#include "Testing/MockSvgItem.h"
#include "Testing/TestingKBlocksItemGroup.h"
......@@ -22,6 +23,7 @@ class testKBlocksItemGroup : public QObject
Q_OBJECT
private slots:
void updateGameShouldProcessGameActionsOnGameOver();
void updateGameShouldRefreshItemsOnGameOver();
void stopGameShouldProcessRemainingGameActions();
};
......@@ -48,6 +50,29 @@ void testKBlocksItemGroup::updateGameShouldProcessGameActionsOnGameOver()
QCOMPARE( mock->numberOfPickGameActionCalls, 1 );
}
void testKBlocksItemGroup::updateGameShouldRefreshItemsOnGameOver()
{
/**
* When updateGame is called, the final piece might just have been
* placed, causing the game to be over. If refreshItems() is not
* called, the final piece will be invisible. The correct behavior
* is to fully display the final piece, making it clear how and
* where it conflicted with the pieces on the field.
*/
std::unique_ptr<SingleGameInterface> pSingleGame( new MockSingleGame() );
std::unique_ptr<GraphicsInterface> pGraphics( new MockGraphics() );
std::unique_ptr<SoundInterface> pSound( new MockSound() );
TestingKBlocksItemGroup itemGroup(0, pSingleGame.get(), pGraphics.get(), pSound.get() );
MockSvgItem *svgItem = new MockSvgItem();
itemGroup.replaceFreezeCells(svgItem);
itemGroup.callUpdateGame();
QVERIFY(svgItem->updateSelfCalled);
}
void testKBlocksItemGroup::stopGameShouldProcessRemainingGameActions()
{
/**
......
......@@ -156,6 +156,7 @@ void KBlocksItemGroup::updateGame()
bool hasRemovedLines = updateLayout();
if (gameResult == GameResult_Game_Over) {
refreshItems();
mUpdateTimer.stop();
return;
}
......
......@@ -23,7 +23,11 @@ class KGameTheme;
class MockGraphics : public GraphicsInterface
{
public:
MockGraphics() : mRenderer(new QSvgRenderer()) {};
MockGraphics() : mRenderer(new QSvgRenderer())
{
m_PlayArea_NumberOfBlocks_X = 1;
m_PlayArea_NumberOfBlocks_Y = 1;
}
virtual ~MockGraphics() = default;
public:
......
/******************************************************************************
* KBlocks, a falling blocks game by KDE *
* Copyright (C) 2010-2021 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. *
******************************************************************************/
#ifndef MOCKSVGITEM_H
#define MOCKSVGITEM_H
#include "SvgItemInterface.h"
class MockSvgItem : public SvgItemInterface
{
public:
MockSvgItem() : updateSelfCalled(false) {}
virtual ~MockSvgItem() = default;
public:
bool updateSelf() override { updateSelfCalled = true; return true; }
void startOpAnim() override {}
void stopOpAnim() override {}
void startPosAnim(QPointF) override {}
void execPosAnim(qreal) override {}
void stopPosAnim() override {}
bool updateSelfCalled;
};
#endif //MOCKSVGITEM_H
......@@ -12,6 +12,7 @@
#define TESTINGKBLOCKSITEMGROUP_H
#include "KBlocksItemGroup.h"
#include "SvgItemInterface.h"
class TestingKBlocksItemGroup : public KBlocksItemGroup
{
......@@ -25,6 +26,19 @@ public:
{
KBlocksItemGroup::updateGame();
}
void replaceFreezeCells(SvgItemInterface* newItem)
{
for (int i = 0; i < mMaxFreezeCellNum; i++) {
removeFromGroup(maFreezeCells[i]);
delete maFreezeCells[i];
}
for (int i = 0; i < mMaxFreezeCellNum; i++) {
maFreezeCells[i] = newItem;
addToGroup(maFreezeCells[i]);
}
}
};
#endif // TESTINGKBLOCKSITEMGROUP_H
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