2018-09-11 20:10:37 +03:00
|
|
|
#ifndef CONTROLLER_H
|
|
|
|
#define CONTROLLER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
2018-10-30 21:23:41 +03:00
|
|
|
#include <QTimer>
|
|
|
|
#include <QTime>
|
2018-11-04 16:11:55 +03:00
|
|
|
#include "diff.h"
|
2018-09-11 20:10:37 +03:00
|
|
|
#include "snake.h"
|
2018-09-27 14:59:10 +03:00
|
|
|
#include "world.h"
|
2018-09-11 20:10:37 +03:00
|
|
|
|
|
|
|
class Controller : public QObject
|
|
|
|
{
|
2018-10-11 00:04:52 +03:00
|
|
|
Q_OBJECT
|
|
|
|
|
2018-09-11 20:10:37 +03:00
|
|
|
private:
|
2018-09-27 14:59:10 +03:00
|
|
|
World world;
|
2018-10-30 21:23:41 +03:00
|
|
|
QTimer *timer;
|
2018-11-04 16:11:55 +03:00
|
|
|
int lvl = 0;
|
|
|
|
QMap<int, GuiObject *> objectsContainer;
|
|
|
|
|
|
|
|
void generateDiff(const QMap<int, GuiObject *> &);
|
2018-09-27 14:59:10 +03:00
|
|
|
|
2018-09-11 20:10:37 +03:00
|
|
|
public:
|
|
|
|
Controller();
|
2018-10-30 21:23:41 +03:00
|
|
|
void startTimer();
|
|
|
|
void stopTimer();
|
|
|
|
|
2018-10-11 18:09:35 +03:00
|
|
|
public slots:
|
2018-11-16 02:08:35 +03:00
|
|
|
void buttonPress();
|
2018-11-04 15:02:03 +03:00
|
|
|
void update();
|
2018-11-04 16:11:55 +03:00
|
|
|
|
2018-11-25 03:24:41 +03:00
|
|
|
/**
|
|
|
|
* @brief nextLvl - switch to next lvl from array lvels
|
|
|
|
* @return true if all levels are passed
|
|
|
|
*/
|
|
|
|
bool nextLvl();
|
|
|
|
|
2018-11-04 16:11:55 +03:00
|
|
|
/**
|
|
|
|
* @brief newGame - start game from first lvl
|
|
|
|
*/
|
|
|
|
void newGame();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief getGameObject
|
|
|
|
* @param id - id of guiObject;
|
|
|
|
* @return guiObject if (id is not valid return nullptr)
|
|
|
|
*/
|
|
|
|
QObject* getGameObject(int id);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
/**
|
|
|
|
* @brief finished - imited when game over or victory
|
|
|
|
* @param victory - flag of vicrory, if it equals false then game over
|
|
|
|
* @param lvl - game over lvl
|
|
|
|
* @param distance - game over distance
|
|
|
|
*/
|
2018-11-25 03:24:41 +03:00
|
|
|
void finished(bool victory, int lvl, double distance);
|
2018-11-04 16:11:55 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief gameObjectsChanged
|
|
|
|
* @param dif
|
|
|
|
*/
|
|
|
|
void gameObjectsChanged(const Diff &dif);
|
2018-09-11 20:10:37 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CONTROLLER_H
|