File indexing completed on 2024-10-27 03:46:38

0001 /*
0002     This file is part of Killbots.
0003 
0004     SPDX-FileCopyrightText: 2007-2009 Parker Coates <coates@kde.org>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef KILLBOTS_COORDINATOR_H
0010 #define KILLBOTS_COORDINATOR_H
0011 
0012 #include "actions.h"
0013 #include "sprite.h"
0014 
0015 class KGamePopupItem;
0016 
0017 #include <QObject>
0018 #include <QTimeLine>
0019 
0020 namespace Killbots
0021 {
0022 class Scene;
0023 class Engine;
0024 class NumericDisplayItem;
0025 
0026 class Coordinator : public QObject
0027 {
0028     Q_OBJECT
0029 
0030 public: // functions
0031     explicit Coordinator(QObject *parent = nullptr);
0032     ~Coordinator() override;
0033 
0034     void setEngine(Engine *engine);
0035     void setScene(Scene *scene);
0036 
0037     void setAnimationSpeed(int speed);
0038 
0039     void beginNewAnimationStage();
0040     Sprite *createSprite(SpriteType type, QPoint position);
0041     void slideSprite(Sprite *sprite, QPoint position);
0042     void teleportSprite(Sprite *sprite, QPoint position);
0043     void destroySprite(Sprite *sprite);
0044 
0045 public Q_SLOTS:
0046     void requestNewGame();
0047     void requestAction(int action);
0048 
0049 private: // types
0050     struct AnimationStage;
0051 
0052 private: // functions
0053     void startNewGame();
0054     void doAction(HeroAction action);
0055     void startAnimation();
0056     void startAnimationStage();
0057     void animationDone();
0058 
0059     void showUnqueuedMessage(const QString &message, int timeOut = 3000);
0060     void showQueuedMessage(const QString &message);
0061 
0062 private Q_SLOTS:
0063     void nextAnimationStage();
0064     void animate(qreal value);
0065 
0066     void updateRound(int round);
0067     void updateScore(int score);
0068     void updateEnemyCount(int enemyCount);
0069     void updateEnergy(int energy);
0070 
0071     void showNewGameMessage();
0072     void showRoundCompleteMessage();
0073     void showBoardFullMessage();
0074     void showGameOverMessage();
0075 
0076 private: // data members
0077     Engine *m_engine;
0078     Scene *m_scene;
0079 
0080     NumericDisplayItem *m_roundDisplay;
0081     NumericDisplayItem *m_scoreDisplay;
0082     NumericDisplayItem *m_enemyCountDisplay;
0083     NumericDisplayItem *m_energyDisplay;
0084 
0085     KGamePopupItem *m_unqueuedPopup;
0086     KGamePopupItem *m_queuedPopup;
0087 
0088     QTimeLine m_timeLine;
0089 
0090     QList<AnimationStage> m_stages;
0091 
0092     bool m_busyAnimating;
0093     bool m_newGameRequested;
0094     HeroAction m_repeatedAction;
0095     HeroAction m_queuedAction;
0096 };
0097 }
0098 
0099 #endif