mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-05-08 23:49:42 +00:00
added init world methods
This commit is contained in:
parent
79564ebfa6
commit
56a0061c28
6
src/Core/SnakeProject/iground.cpp
Normal file
6
src/Core/SnakeProject/iground.cpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "iground.h"
|
||||||
|
|
||||||
|
IGround::IGround()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
11
src/Core/SnakeProject/iground.h
Normal file
11
src/Core/SnakeProject/iground.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#ifndef IGROUND_H
|
||||||
|
#define IGROUND_H
|
||||||
|
|
||||||
|
|
||||||
|
class IGround
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
IGround();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // IGROUND_H
|
@ -57,6 +57,11 @@ void IWorld::deinit() {
|
|||||||
delete _worldRules;
|
delete _worldRules;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IWorld::generateGround() {
|
||||||
|
int count = 10;
|
||||||
|
TO-DU
|
||||||
|
}
|
||||||
|
|
||||||
void IWorld::addItem(const QString& group, IWorldItem* obj) {
|
void IWorld::addItem(const QString& group, IWorldItem* obj) {
|
||||||
_items.insert(obj->guiId(), WorldObjectWraper{obj, group});
|
_items.insert(obj->guiId(), WorldObjectWraper{obj, group});
|
||||||
_itemsGroup.insert(group, obj->guiId());
|
_itemsGroup.insert(group, obj->guiId());
|
||||||
@ -78,7 +83,7 @@ bool IWorld::removeItem(int id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool IWorld::removeAnyItemFromGroup(const QString &group) {
|
bool IWorld::removeAnyItemFromGroup(const QString &group) {
|
||||||
auto anyObject =_itemsGroup.value(group);
|
auto anyObject = _itemsGroup.value(group);
|
||||||
return removeItem(anyObject);
|
return removeItem(anyObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +95,7 @@ void IWorld::worldChanged(const WorldObjects &objects) {
|
|||||||
|
|
||||||
for (auto it = objects.begin(); it != objects.end(); ++it) {
|
for (auto it = objects.begin(); it != objects.end(); ++it) {
|
||||||
|
|
||||||
int count = it.value() -_itemsGroup.count(it.key());
|
int count = it.value() - _itemsGroup.count(it.key());
|
||||||
|
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
for ( int i = 0; i < count; ++i ) {
|
for ( int i = 0; i < count; ++i ) {
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
class IWorldItem;
|
class IWorldItem;
|
||||||
class IPlayer;
|
class IPlayer;
|
||||||
|
class Diff;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief WorldObjects This is map list of the avalable objects and its count on a lvl-long point.
|
* @brief WorldObjects This is map list of the avalable objects and its count on a lvl-long point.
|
||||||
@ -41,6 +42,14 @@ public:
|
|||||||
IWorld();
|
IWorld();
|
||||||
virtual ~IWorld();
|
virtual ~IWorld();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief generateGroundTile This method should be generate a new tile of the world.
|
||||||
|
* @return raw pointer to tile of the world ground.
|
||||||
|
* @note The tile count sets automaticly.
|
||||||
|
* @note All generated objects will be distroed automaticaly.
|
||||||
|
*/
|
||||||
|
virtual IWorldItem* generateGroundTile() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief initPlayer The implementation of This interface must be return playerObject.
|
* @brief initPlayer The implementation of This interface must be return playerObject.
|
||||||
* @return raw pointer to the player object.
|
* @return raw pointer to the player object.
|
||||||
@ -103,10 +112,23 @@ public:
|
|||||||
*/
|
*/
|
||||||
const IWorldItem * getItem(int id) const;
|
const IWorldItem * getItem(int id) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief hdrMap This method return path to hdr map of world.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
const QString &hdrMap() const;
|
const QString &hdrMap() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void sigGameFinished(GameResult);
|
/**
|
||||||
|
* @brief sigGameFinished This signal emit when game are finished
|
||||||
|
* @brief result This is player statistics after finished level,
|
||||||
|
*/
|
||||||
|
void sigGameFinished(GameResult result);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief sigOBjctsListChanged This signal emited when lvel status are changed.
|
||||||
|
*/
|
||||||
|
void sigOBjctsListChanged(Diff);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
@ -121,6 +143,7 @@ private:
|
|||||||
bool init();
|
bool init();
|
||||||
void deinit();
|
void deinit();
|
||||||
|
|
||||||
|
void generateGround();
|
||||||
void worldChanged(const WorldObjects& objects);
|
void worldChanged(const WorldObjects& objects);
|
||||||
void clearItems();
|
void clearItems();
|
||||||
void addItem(const QString &group, IWorldItem *obj);
|
void addItem(const QString &group, IWorldItem *obj);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <QQmlComponent>
|
#include <QQmlComponent>
|
||||||
#include <guiobject.h>
|
#include <guiobject.h>
|
||||||
#include "SnakeProject/iworld.h"
|
#include "SnakeProject/iworld.h"
|
||||||
|
#include "diff.h"
|
||||||
|
|
||||||
Engine::Engine() {
|
Engine::Engine() {
|
||||||
|
|
||||||
@ -59,10 +60,6 @@ bool Engine::remove(int id) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Diff Engine::generateDiff() {
|
|
||||||
TO-DO
|
|
||||||
}
|
|
||||||
|
|
||||||
void Engine::setQmlEngine(QQmlEngine *newEngine) {
|
void Engine::setQmlEngine(QQmlEngine *newEngine) {
|
||||||
if (_engine == newEngine)
|
if (_engine == newEngine)
|
||||||
return;
|
return;
|
||||||
@ -74,9 +71,17 @@ void Engine::setWorld(IWorld *world) {
|
|||||||
if (_currentWorld == world)
|
if (_currentWorld == world)
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
|
if (_currentWorld) {
|
||||||
|
disconnect(_currentWorld, &IWorld::sigOBjctsListChanged,
|
||||||
|
this, &Engine::handleGameObjectsChanged);
|
||||||
|
}
|
||||||
|
|
||||||
_currentWorld = world;
|
_currentWorld = world;
|
||||||
|
|
||||||
handleGameObjectsChanged();
|
connect(_currentWorld, &IWorld::sigOBjctsListChanged,
|
||||||
|
this, &Engine::handleGameObjectsChanged,
|
||||||
|
Qt::QueuedConnection);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Engine::hdr() const {
|
QString Engine::hdr() const {
|
||||||
|
@ -49,10 +49,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
void setScane(QObject *newScane);
|
void setScane(QObject *newScane);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief currentWorld return pointer to current world object.
|
||||||
|
* @return raw pointer to current world object.
|
||||||
|
*/
|
||||||
IWorld *currentWorld() const;
|
IWorld *currentWorld() const;
|
||||||
void setCurrentWorld(IWorld *newCurrentWorld);
|
|
||||||
|
|
||||||
public slots:
|
private slots:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief handleGameObjectsChanged This slot invoked when games objects changed.
|
* @brief handleGameObjectsChanged This slot invoked when games objects changed.
|
||||||
@ -67,7 +70,6 @@ signals:
|
|||||||
private:
|
private:
|
||||||
bool add(GuiObject* obj);
|
bool add(GuiObject* obj);
|
||||||
bool remove(int id);
|
bool remove(int id);
|
||||||
Diff generateDiff();
|
|
||||||
|
|
||||||
QObject *_scane = nullptr;
|
QObject *_scane = nullptr;
|
||||||
QQmlEngine *_engine = nullptr;
|
QQmlEngine *_engine = nullptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user