ref #98 rename the IPlayer to the PlayableObject

This commit is contained in:
Andrei Yankovich 2021-08-04 16:47:55 +03:00
parent 68d1203d6b
commit 621aab73d4
14 changed files with 52 additions and 93 deletions

View File

@ -58,11 +58,6 @@ void IWorld::render(unsigned int tbfMsec) {
_ItemsMutex.unlock();
if (_player->isDead()) {
emit sigGameFinished(_player->getCurrentStatus());
}
updateWorld();
int waitTime = 1000 / _targetFps - tbfMsec;
@ -101,7 +96,7 @@ void IWorld::setPlayer(QObject *newPlayer) {
if (_player == newPlayer)
return;
auto newPlayerObject = dynamic_cast<IPlayer*>(newPlayer);
auto newPlayerObject = dynamic_cast<PlayableObject*>(newPlayer);
if (!newPlayerObject) {
QuasarAppUtils::Params::log("Failed to set player object. The input object is not player.",
QuasarAppUtils::Error);

View File

@ -8,7 +8,8 @@
#ifndef CRAWL_IWORLD_H
#define CRAWL_IWORLD_H
#include "iplayer.h"
#include "gameresult.h"
#include "playableobject.h"
#include <QHash>
#include <QMap>
@ -26,7 +27,7 @@ class ClastersTest;
namespace CRAWL {
class IWorldItem;
class IPlayer;
class PlayableObject;
class GroundClaster;
class IControl;
class IAI;
@ -67,7 +68,7 @@ public:
* @note The Palyer object will be deleted when wold distroed.
* So do not delete your created player pbject yuorself.
*/
virtual IPlayer* initPlayer() const = 0;
virtual PlayableObject* initPlayer() const = 0;
/**
* @brief initWorldRules The implementation of this interface must be retun initialized list of the world rules.
@ -494,7 +495,7 @@ private:
WorldRule *_worldRules = nullptr;
WorldRule::const_iterator _currendWorldLevel;
IPlayer *_player = nullptr;
PlayableObject *_player = nullptr;
IControl *_userInterface = nullptr;
IAI *_backgroundAI = nullptr;
int _worldStatus = 0;

View File

@ -6,55 +6,35 @@
//#
#include "defaultcontrol.h"
#include "iplayer.h"
#include "playableobject.h"
namespace CRAWL {
IPlayer::IPlayer(const QString &name,
PlayableObject::PlayableObject(const QString &name,
const QString &viewTempalte,
QObject *ptr):
IWorldItem(name, viewTempalte, ptr) {
}
GameResult IPlayer::getCurrentStatus() const {
return {_currentPoints, static_cast<int>(position().distanceToPoint({0,0,0}))};
}
bool IPlayer::isDead() const {
return _fDead;
}
void IPlayer::reward(int value) {
_currentPoints += value;
}
void IPlayer::fine(int value) {
_currentPoints -= value;
}
void IPlayer::render(unsigned int tbfMsec) {
void PlayableObject::render(unsigned int tbfMsec) {
MovableObject::render(tbfMsec);
}
void IPlayer::setControl(const IControl *control) {
void PlayableObject::setControl(const IControl *control) {
if (auto oldControl = dynamic_cast<const DefaultControl*>(_currentControl)) {
disconnect(oldControl, &DefaultControl::userTap, this, &IPlayer::onTap);
disconnect(oldControl, &DefaultControl::userTap, this, &PlayableObject::onTap);
}
auto defaultControl = dynamic_cast<const DefaultControl*>(control);
_currentControl = defaultControl;
if (_currentControl) {
connect(defaultControl, &DefaultControl::userTap, this, &IPlayer::onTap);
connect(defaultControl, &DefaultControl::userTap, this, &PlayableObject::onTap);
}
}
void IPlayer::kill() {
_fDead = true;
}
}

View File

@ -5,10 +5,9 @@
//# of this license document, but changing it is not allowed.
//#
#ifndef IPLAYER_H
#define IPLAYER_H
#ifndef PLAYABLEOBJECT_H
#define PLAYABLEOBJECT_H
#include "gameresult.h"
#include "global.h"
#include "iworlditem.h"
#include "Extensions/movableobject.h"
@ -19,56 +18,46 @@ namespace CRAWL {
class IControl;
/**
* @brief The IPlayer class This is base class of the player functions.
* @brief The PlayableObject class support works withe the IControl child classes.
* **How to is works**? You need to override the PlayableObject::setControl method for adding your own cpntroll classes. By Default This class use The DefaultControl class.
*/
class CRAWL_EXPORT IPlayer: public IWorldItem, public MovableObject {
class CRAWL_EXPORT PlayableObject: public IWorldItem, public MovableObject {
Q_OBJECT
public:
IPlayer(const QString& name,
PlayableObject(const QString& name,
const QString& viewTempalte = DEFAULT_VIEW_TEMPLATE,
QObject *ptr = nullptr);
/**
* @brief getCurrentStatus This method return current game state of the player.
* @return current gameState.
*/
GameResult getCurrentStatus() const;
/**
* @brief isDead This method return true if your player are dead.
* @return true if a player are dead.
*/
bool isDead() const;
/**
* @brief setControl This method should be connect player object with control object.
* @param control This is control object.
* @note This method can invoked two or more times, for example connect with AI control object and player control object. So your implementation should be contains disconnect methods.
*
* ### Example of use
*
* @code{cpp}
void MyPlayableObject::setControl(const IControl *control) {
if (auto oldControl = dynamic_cast<const DefaultControl*>(_currentControl)) {
disconnect(oldControl, &DefaultControl::userTap, this, &PlayableObject::onTap);
// some disconnect methodots
}
auto defaultControl = dynamic_cast<const DefaultControl*>(control);
_currentControl = defaultControl;
if (_currentControl) {
connect(defaultControl, &DefaultControl::userTap, this, &PlayableObject::onTap);
// some connect methodots
}
}
* @endcode
*/
virtual void setControl(const IControl* control);
protected:
/**
* @brief kill This method kill your player.
* Invoke this method when you want to kell your player.
*/
void kill();
/**
* @brief reward This method add reward for player.
* @param value This is new value;
* @note This method increment current value.
*/
void reward(int value);
/**
* @brief fine This method remove reward for player.
* @param value This is fine amount;
* @note This method decriment current points value.
*/
void fine(int value);
void render(unsigned int tbfMsec) override;
protected slots:
@ -80,12 +69,10 @@ protected slots:
private:
bool _fDead = false;
int _currentPoints = 0;
const IControl * _currentControl = nullptr;
};
}
#endif // IPLAYER_H
#endif // PLAYABLEOBJECT_H

View File

@ -15,7 +15,7 @@ namespace CRAWL {
Snake::Snake(const QString &name, const QString &viewTempalte, QObject *ptr):
IPlayer (name, viewTempalte, ptr) {
PlayableObject (name, viewTempalte, ptr) {
_vectors = new QVector3D[2];
setAngularVelocity(100);
@ -39,7 +39,7 @@ Snake::~Snake( ){
}
void Snake::render(unsigned int tbfMsec) {
IPlayer::render(tbfMsec);
PlayableObject::render(tbfMsec);
}
void Snake::add(ClasterItem *object) {

View File

@ -8,7 +8,7 @@
#ifndef CRAWL_SNAKE_H
#define CRAWL_SNAKE_H
#include "iplayer.h"
#include "playableobject.h"
#include "Extensions/autogenerateclaster.h"
namespace CRAWL {
@ -18,7 +18,7 @@ class SnakeItem;
/**
* @brief The Snake class This class implement render mehod for snake object.
*/
class CRAWL_EXPORT Snake : public IPlayer, public AutoGenerateClaster
class CRAWL_EXPORT Snake : public PlayableObject, public AutoGenerateClaster
{
Q_OBJECT
public:

View File

@ -4,7 +4,3 @@ DefaultMenu 1.0 DefaultMenu.qml
GraphicItem 1.0 GraphicItem.qml
ParticleEffect 1.0 ParticleEffect.qml
Light 1.0 Light.qml
GraphicItem 1.0 GraphicItem.qml
GraphicItem 1.0 GraphicItem.qml
GraphicItem 1.0 GraphicItem.qml
GraphicItem 1.0 GraphicItem.qml

View File

@ -23,7 +23,7 @@ AbsLvlWorld::AbsLvlWorld() {
setCameraRotation(QQuaternion::fromEulerAngles({0,0,0}));
}
CRAWL::IPlayer *AbsLvlWorld::initPlayer() const {
CRAWL::PlayableObject *AbsLvlWorld::initPlayer() const {
return new AbsLvlSnake();
}

View File

@ -20,7 +20,7 @@ public:
AbsLvlWorld();
CRAWL::IPlayer *initPlayer() const override;
CRAWL::PlayableObject *initPlayer() const override;
CRAWL::WorldRule *initWorldRules() override;
QString initHdrBackGround() const override;
QString description() const override;

View File

@ -73,7 +73,7 @@ void World::initPlayerControl(CRAWL::IControl *control) {
return IWorld::initPlayerControl(control);
}
CRAWL::IPlayer *World::initPlayer() const {
CRAWL::PlayableObject *World::initPlayer() const {
return new TestSnake();
}

View File

@ -28,7 +28,7 @@ public:
int costToUnlock() const override;
CRAWL::IControl *initUserInterface() const override;
void initPlayerControl(CRAWL::IControl *control) override;
CRAWL::IPlayer *initPlayer() const override;
CRAWL::PlayableObject *initPlayer() const override;
CRAWL::IAI *initBackGroundAI() const override;
private slots:

View File

@ -108,7 +108,7 @@ void World::initPlayerControl(CRAWL::IControl *control) {
return IWorld::initPlayerControl(control);
}
CRAWL::IPlayer *World::initPlayer() const {
CRAWL::PlayableObject *World::initPlayer() const {
return new Snake();
}

View File

@ -27,7 +27,7 @@ public:
int costToUnlock() const override;
CRAWL::IControl *initUserInterface() const override;
void initPlayerControl(CRAWL::IControl *control) override;
CRAWL::IPlayer *initPlayer() const override;
CRAWL::PlayableObject *initPlayer() const override;
CRAWL::IAI *initBackGroundAI() const override;
private slots:

View File

@ -45,7 +45,7 @@ public:
// IWorld interface
public:
CRAWL::IPlayer *initPlayer() const {return nullptr;};
CRAWL::PlayableObject *initPlayer() const {return nullptr;};
CRAWL::WorldRule *initWorldRules() {return nullptr;};
QString initHdrBackGround() const {return "";};
QString description() const {return "";};