Use player name in the KScoreDialog
[kdegames.git] / killbots / engine.h
blob14e65a8d22f227d8fc3d2fa1126bced517c28548
1 /*
2 * Copyright 2006-2009 Parker Coates <parker.coates@gmail.com>
4 * This file is part of Killbots.
6 * Killbots is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * Killbots is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Killbots. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef KILLBOTS_ENGINE_H
21 #define KILLBOTS_ENGINE_H
23 #include "ruleset.h"
25 #include <QtCore/QObject>
26 #include <QtCore/QHash>
27 class QPoint;
29 namespace Killbots
31 class Scene;
32 class Sprite;
34 enum HeroAction
36 Right = 0,
37 UpRight,
38 Up,
39 UpLeft,
40 Left,
41 DownLeft,
42 Down,
43 DownRight,
44 Hold,
46 Teleport,
47 TeleportSafely,
48 TeleportSafelyIfPossible,
49 WaitOutRound,
50 SonicScrewdriver,
51 NoAction,
53 RepeatRight = -( Right + 1 ),
54 RepeatUpRight = -( UpRight + 1 ),
55 RepeatUp = -( Up + 1 ),
56 RepeatUpLeft = -( UpLeft + 1 ),
57 RepeatLeft = -( Left + 1 ),
58 RepeatDownLeft = -( DownLeft + 1 ),
59 RepeatDown = -( Down + 1 ),
60 RepeatDownRight = -( DownRight + 1 ),
61 RepeatHold = -( Hold + 1 )
64 class Engine : public QObject
66 Q_OBJECT
68 public: // functions
69 explicit Engine( Scene * scene, QObject * parent = 0 );
70 virtual ~Engine();
71 const Ruleset * ruleset();
72 bool gameHasStarted();
74 public slots:
75 void requestNewGame();
76 void requestAction( HeroAction action );
77 void requestAction( int action );
79 signals:
80 void newGame( int rows, int columns, bool gameIncludesEnergy );
81 void gameOver( int score, int round );
83 void roundChanged( int round );
84 void scoreChanged( int score );
85 void enemyCountChanged( int enemyCount );
86 void energyChanged( int energy );
88 void showNewGameMessage();
89 void showRoundCompleteMessage();
90 void showBoardFullMessage();
91 void showGameOverMessage();
93 void teleportAllowed( bool allowed );
94 void teleportSafelyAllowed( bool allowed );
95 void sonicScrewdriverAllowed( bool allowed );
96 void waitOutRoundAllowed( bool allowed );
98 private: // functions
99 void newGame();
100 void newRound( bool incrementRound = true, const QString & layout = QString() );
101 void doAction( HeroAction direction );
103 bool moveHero( HeroAction direction );
104 bool teleportHero();
105 bool teleportHeroSafely();
106 bool sonicScrewdriver();
108 void pushJunkheap( Sprite * junkheap, HeroAction direction );
109 void moveRobots( bool justFastbots = false );
110 void assessDamage();
111 void cleanUpRound();
112 void resetBotCounts();
114 void refreshSpriteMap();
115 int spriteTypeAt( const QPoint & cell ) const;
116 QPoint randomEmptyCell() const;
117 bool cellIsValid( const QPoint & cell ) const;
118 bool moveIsValid( const QPoint & cell, HeroAction direction ) const;
119 bool moveIsSafe( const QPoint & cell, HeroAction direction ) const;
120 bool canPushJunkheap( const Sprite * junkheap, HeroAction direction ) const;
121 QPoint offsetFromDirection( int direction ) const;
122 void destroySprite( Sprite * sprite, bool calculatePoints = true );
123 bool destroyAllCollidingBots( const Sprite * sprite, bool calculatePoints = true );
124 void updateScore( int changeInScore );
125 void updateEnergy( int changeInEnergy );
127 private slots:
128 void animationDone();
130 private: // data members
131 Scene * m_scene;
133 Sprite * m_hero;
134 QList<Sprite *> m_bots;
135 QList<Sprite *> m_junkheaps;
137 bool m_busyAnimating;
138 bool m_processFastbots;
139 bool m_gameOver;
140 bool m_newGameRequested;
141 HeroAction m_repeatedAction;
142 HeroAction m_queuedAction;
144 Ruleset * m_rules;
145 int m_round;
146 int m_score;
147 int m_energy;
148 qreal m_maxEnergy;
149 qreal m_robotCount;
150 qreal m_fastbotCount;
151 qreal m_junkheapCount;
153 QMultiHash< QPoint, Sprite * > m_spriteMap;
157 #endif