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
25 #include <QtCore/QObject>
26 #include <QtCore/QHash>
48 TeleportSafelyIfPossible
,
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
69 explicit Engine( Scene
* scene
, QObject
* parent
= 0 );
71 const Ruleset
* ruleset();
72 bool gameHasStarted();
75 void requestNewGame();
76 void requestAction( HeroAction action
);
77 void requestAction( int action
);
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
);
100 void newRound( bool incrementRound
= true, const QString
& layout
= QString() );
101 void doAction( HeroAction direction
);
103 bool moveHero( HeroAction direction
);
105 bool teleportHeroSafely();
106 bool sonicScrewdriver();
108 void pushJunkheap( Sprite
* junkheap
, HeroAction direction
);
109 void moveRobots( bool justFastbots
= false );
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
);
128 void animationDone();
130 private: // data members
134 QList
<Sprite
*> m_bots
;
135 QList
<Sprite
*> m_junkheaps
;
137 bool m_busyAnimating
;
138 bool m_processFastbots
;
140 bool m_newGameRequested
;
141 HeroAction m_repeatedAction
;
142 HeroAction m_queuedAction
;
150 qreal m_fastbotCount
;
151 qreal m_junkheapCount
;
153 QMultiHash
< QPoint
, Sprite
* > m_spriteMap
;