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

Replace KBlocksGameLogic with GameLogicInterface in KBlocksWin

To be able to sense the actions performed on the game logic element, I
want to be able to replace the GameLogic with a Mock object.
parent 2702d854
......@@ -5,6 +5,7 @@ set(kblockscore_SRCS
AI/KBlocksAIPlanner.cpp
AI/KBlocksAIPlannerExtend.cpp
AI/KBlocksAIPlayer.cpp
GameLogicInterface.cpp
KBlocksAnimator.cpp
KBlocksAnimDrop.cpp
KBlocksAnimFade.cpp
......
/******************************************************************************
* 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. *
******************************************************************************/
#include "GameLogicInterface.h"
GameLogicInterface::GameLogicInterface()
: maGameList(nullptr)
{
}
/***************************************************************************
* KBlocks, a falling blocks game by KDE *
* Copyright (C) 2010 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 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 GAME_LOGIC_INTERFACE
#define GAME_LOGIC_INTERFACE
#include <QObject>
#include "SingleGameInterface.h"
class GameLogicInterface
class GameLogicInterface : public QObject
{
Q_OBJECT
public:
GameLogicInterface() : maGameList(nullptr) {};
GameLogicInterface();
virtual ~GameLogicInterface() {};
public:
......@@ -24,12 +28,21 @@ public:
virtual int levelUpGame(int) = 0;
virtual int updateGame(int *) = 0;
virtual void setGameSeed(int) = 0;
virtual void setGameStandbyMode(bool) = 0;
virtual bool startGame(int) = 0;
virtual bool stopGame() = 0;
virtual void pauseGame(bool) = 0;
virtual void continueGame() = 0;
virtual bool deleteSingleGames() = 0;
signals:
void allGamesStopped();
protected:
SingleGameInterface **maGameList;
};
......
/***************************************************************************
* KBlocks, a falling blocks game by KDE *
* Copyright (C) 2010 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 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 KBLOCKSGAMELOGIC_H
#define KBLOCKSGAMELOGIC_H
#include <stdlib.h>
#include <QObject>
#include "GameLogicInterface.h"
#include "SingleGameInterface.h"
......@@ -23,7 +23,7 @@
#include "KBlocksSingleGame.h"
class KBlocksGameLogic : public QObject, public GameLogicInterface
class KBlocksGameLogic : public GameLogicInterface
{
Q_OBJECT
......@@ -42,10 +42,10 @@ public:
int levelUpGame(int level) override;
int updateGame(int *lineList) override;
void setGameSeed(int seed);
void setGameSeed(int seed) override;
void setGamePunish(bool flag);
void setGameStandbyMode(bool flag);
void setGameStandbyMode(bool flag) override;
void setGameInterval(int interval);
void setInitInterval(int interval);
void setLevelUpInterval(int interval);
......@@ -55,14 +55,11 @@ public:
void pauseGame(bool pauseFlag) override;
void continueGame() override;
bool deleteSingleGames();
bool deleteSingleGames() override;
public slots:
bool stopGame() override;
signals:
void allGamesStopped();
private:
void createSingleGames(int gameCount);
......
......@@ -31,11 +31,12 @@
#define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API
#include <libkdegamesprivate/kgamethemeselector.h>
#include "GameLogicInterface.h"
#include "KBlocksScene.h"
#include "SceneInterface.h"
#include "settings.h"
KBlocksWin::KBlocksWin(KBlocksGameLogic *p, KBlocksPlayManager *pM, int capacity, int gamecount) : KXmlGuiWindow()
KBlocksWin::KBlocksWin(GameLogicInterface *p, KBlocksPlayManager *pM, int capacity, int gamecount) : KXmlGuiWindow()
{
//Use up to 3MB for global application pixmap cache
QPixmapCache::setCacheLimit(3 * 1024);
......@@ -46,7 +47,7 @@ KBlocksWin::KBlocksWin(KBlocksGameLogic *p, KBlocksPlayManager *pM, int capacity
mMaxGameCapacity = capacity;
mGameCount = gamecount;
mpGameLogic = p;
connect(mpGameLogic, &KBlocksGameLogic::allGamesStopped,
connect(mpGameLogic, &GameLogicInterface::allGamesStopped,
this, &KBlocksWin::onAllGamesStopped);
mpPlayManager = pM;
......
......@@ -19,16 +19,16 @@
#include "KBlocksKeyboardPlayer.h"
#include "AI/KBlocksAIPlayer.h"
#include "KBlocksGameLogic.h"
#include "KBlocksPlayManager.h"
class QLabel;
class GameLogicInterface;
class SceneInterface;
class KBlocksWin : public KXmlGuiWindow
{
Q_OBJECT
public:
KBlocksWin(KBlocksGameLogic *p, KBlocksPlayManager *pM, int capacity, int gamecount);
KBlocksWin(GameLogicInterface *p, KBlocksPlayManager *pM, int capacity, int gamecount);
~KBlocksWin();
public:
......@@ -65,6 +65,12 @@ private:
protected:
void closeEvent(QCloseEvent *event) override;
protected:
SceneInterface *mpGameScene = nullptr;
KBlocksView *mpGameView = nullptr;
KBlocksKeyboardPlayer *mpKBPlayer = nullptr;
private:
int mMaxGameCapacity;
int mGameCount;
......@@ -72,13 +78,9 @@ private:
bool mGameAnim;
bool mWaitForAll;
SceneInterface *mpGameScene = nullptr;
KBlocksView *mpGameView = nullptr;
KBlocksGameLogic *mpGameLogic = nullptr;
GameLogicInterface *mpGameLogic = nullptr;
KBlocksPlayManager *mpPlayManager = nullptr;
KBlocksKeyboardPlayer *mpKBPlayer = nullptr;
KBlocksAIPlayer *mpAIPlayer = nullptr;
QAction *m_pauseAction = nullptr;
......
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