Commit 283a4c99 authored by Julian Helfferich's avatar Julian Helfferich 💬
Browse files

Use SceneInterface also in KBlocksWin

The goal is still to be able to use a MockScene in KBlocksWin that can
be used in unit testing.
parent 454ad0ad
......@@ -38,6 +38,7 @@ set(kblockscore_SRCS
KBlocksSvgItem.cpp
KBlocksView.cpp
KBlocksWin.cpp
SceneInterface.cpp
utils.cpp
)
......
......@@ -25,7 +25,6 @@
#include "GameLogicInterface.h"
#include "KBlocksDefine.h"
#include "SceneInterface.h"
class KBlocksScene : public SceneInterface
......@@ -39,28 +38,24 @@ public:
KBlocksItemGroup *getItemGroup(int index);
KBlocksScore *getScoreHandler(int index);
void createGameItemGroups(int groupCount, bool snapshotMode = false);
void deleteGameItemGroups();
void createGameItemGroups(int groupCount, bool snapshotMode = false) override;
void deleteGameItemGroups() override;
void setGamesPerLine(int count);
void setGameAnimEnabled(bool flag);
void setWaitForAllUpdate(bool flag);
void setUpdateInterval(int interval);
void setSoundsEnabled(bool enabled);
void setGamesPerLine(int count) override;
void setGameAnimEnabled(bool flag) override;
void setWaitForAllUpdate(bool flag) override;
void setUpdateInterval(int interval) override;
void setSoundsEnabled(bool enabled) override;
void readSettings(const QSize &viewSize) override;
void viewScaled(const QSize &newsize);
void startGame();
void stopGame();
void pauseGame(bool flag, bool fromUI = false);
void startGame() override;
void stopGame() override;
void addScore(int gameIndex, int lineCount);
void pauseGame(bool flag, bool fromUI = false) override;
signals:
void scoreChanged(int index, int points, int lines, int level);
void isHighscore(int index, int points, int level);
void addScore(int gameIndex, int lineCount) override;
private:
void updateDimensions();
......@@ -77,8 +72,8 @@ private slots:
void readyForAction(int groupID);
public slots:
void playMoveSound();
void playDropSound();
void playMoveSound() override;
void playDropSound() override;
protected:
void drawBackground(QPainter *painter, const QRectF &rect) override;
......@@ -111,4 +106,3 @@ private:
};
#endif
/***************************************************************************
* KBlocks, a falling blocks game by KDE *
* Copyright (C) 2009 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) 2009-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 "KBlocksWin.h"
#include <limits.h>
......@@ -30,6 +31,8 @@
#define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API
#include <libkdegamesprivate/kgamethemeselector.h>
#include "KBlocksScene.h"
#include "SceneInterface.h"
#include "settings.h"
KBlocksWin::KBlocksWin(KBlocksGameLogic *p, KBlocksPlayManager *pM, int capacity, int gamecount) : KXmlGuiWindow()
......@@ -51,9 +54,9 @@ KBlocksWin::KBlocksWin(KBlocksGameLogic *p, KBlocksPlayManager *pM, int capacity
mpGameScene = new KBlocksScene(mpGameLogic, capacity);
connect(mpKBPlayer, &KBlocksKeyboardPlayer::blockMoved,
mpGameScene, &KBlocksScene::playMoveSound);
mpGameScene, &SceneInterface::playMoveSound);
connect(mpKBPlayer, &KBlocksKeyboardPlayer::blockDropped,
mpGameScene, &KBlocksScene::playDropSound);
mpGameScene, &SceneInterface::playDropSound);
mpGameView = new KBlocksView(mpGameScene, this);
mpGameView->show();
......
/***************************************************************************
* KBlocks, a falling blocks game by KDE *
* Copyright (C) 2009 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) 2009-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. *
******************************************************************************/
#ifndef KBLOCKSWIN_H
#define KBLOCKSWIN_H
#include <KXmlGuiWindow>
#include "KBlocksScene.h"
#include "KBlocksView.h"
#include "KBlocksKeyboardPlayer.h"
......@@ -22,6 +22,7 @@
#include "KBlocksGameLogic.h"
#include "KBlocksPlayManager.h"
class QLabel;
class SceneInterface;
class KBlocksWin : public KXmlGuiWindow
{
Q_OBJECT
......@@ -38,9 +39,11 @@ public:
void addScore(int gameIndex, int lineCount);
protected slots:
void stopGame();
private slots:
void startGame();
void stopGame();
void pauseGame();
void singleGame();
......@@ -69,7 +72,7 @@ private:
bool mGameAnim;
bool mWaitForAll;
KBlocksScene *mpGameScene = nullptr;
SceneInterface *mpGameScene = nullptr;
KBlocksView *mpGameView = nullptr;
KBlocksGameLogic *mpGameLogic = nullptr;
......
/******************************************************************************
* KBlocks, a falling blocks game by KDE *
* Copyright (C) 2009-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. *
******************************************************************************/
#include "SceneInterface.h"
SceneInterface::SceneInterface()
: QGraphicsScene()
{
}
......@@ -15,12 +15,32 @@
class SceneInterface : public QGraphicsScene
{
Q_OBJECT
public:
SceneInterface() = default;
SceneInterface();
virtual ~SceneInterface() = default;
public:
virtual void createGameItemGroups(int, bool snapshotMode = false) = 0;
virtual void deleteGameItemGroups() = 0;
virtual void setGamesPerLine(int) = 0;
virtual void setGameAnimEnabled(bool) = 0;
virtual void setWaitForAllUpdate(bool) = 0;
virtual void setUpdateInterval(int) = 0;
virtual void setSoundsEnabled(bool) = 0;
virtual void readSettings(const QSize&) = 0;
virtual void startGame() = 0;
virtual void stopGame() = 0;
virtual void pauseGame(bool, bool fromUI = false) = 0;
virtual void addScore(int, int) = 0;
signals:
void scoreChanged(int index, int points, int lines, int level);
void isHighscore(int index, int points, int level);
public slots:
virtual void playMoveSound() = 0;
virtual void playDropSound() = 0;
};
#endif // SCENEINTERFACE_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