Commit 1bd1eb33 authored by Dmitry Suzdalev's avatar Dmitry Suzdalev
Browse files

Added documentation and fixed game behavior

svn path=/trunk/KDE/kdegames/klines/; revision=616467
parent a52cb8c3
......@@ -29,14 +29,38 @@
class KLinesScene;
class BallItem;
/**
* Drives KLines animations
*/
class KLinesAnimator : public QObject
{
Q_OBJECT
public:
KLinesAnimator( KLinesScene *scene );
explicit KLinesAnimator( KLinesScene *scene );
/**
* Starts animation of ball movement.
* When animation finishes moveFinished() signal is emitted
* @param from starting field position
* @param to target field position
*/
void animateMove( const FieldPos& from, const FieldPos& to );
/**
* Starts animation of ball deletion from field.
* Note that it doesn't do actual deletion - it just runs
* animation of deletion.
* When animation finishes removeFinished() signal is emitted
* @param list list of balls to 'remove'
*/
void animateRemove( const QList<BallItem*>& list );
/**
* Starts animation of ball movement.
* When animation finishes bornFinished() signal is emitted
* @param list list of balls to be 'born'
*/
void animateBorn( const QList<BallItem*>& list );
/**
* @returns whether some animation is in progress
*/
bool isAnimating() const;
signals:
void moveFinished();
......@@ -51,15 +75,37 @@ private:
* Implements A* pathfinding algorithm.
*/
void findPath(const FieldPos& from, const FieldPos& to);
/**
* Timeline used to control movement animation
*/
QTimeLine m_moveTimeLine;
/**
* Timeline used to control deletion animation
*/
QTimeLine m_removeTimeLine;
/**
* Timeline used to control birth animation
*/
QTimeLine m_bornTimeLine;
/**
* Scene on which animations are played
*/
KLinesScene* m_scene;
/**
* Ball object used while animating movement
*/
BallItem* m_movingBall;
/**
* findPath() algorithm stores found path in this variable
*/
QList<FieldPos> m_foundPath;
/**
* Balls for which 'remove' animation is played
*/
QList<BallItem*> m_removedBalls;
/**
* Balls for which 'born' animation is played
*/
QList<BallItem*> m_bornBalls;
};
......
......@@ -30,13 +30,21 @@
class KLinesRenderer;
/**
* QGraphicsItem for Ball
*/
class BallItem : public QObject, public QGraphicsPixmapItem
{
Q_OBJECT
public:
BallItem( QGraphicsScene* parent, const KLinesRenderer* r );
/**
* Sets ball's color
*/
void setColor( BallColor c );
/**
* @return color of the ball
*/
BallColor color() const { return m_color; }
/**
* Starts "Selected" animation
......
......@@ -156,15 +156,16 @@ void KLinesScene::moveAnimFinished()
void KLinesScene::removeAnimFinished()
{
qDeleteAll( m_itemsToDelete );
m_itemsToDelete.clear();
if(m_placeBallsAfterErase)
if(m_itemsToDelete.isEmpty() && m_placeBallsAfterErase)
{
// slot bornAnimFinished() will be called
// when born animation finishes
nextThreeBalls();
}
else
{
qDeleteAll( m_itemsToDelete );
m_itemsToDelete.clear();
// it is needed after qDeleteAll()
// as an optimisation we may update only rects
// in which items from m_itemsToDelete were before
......@@ -272,7 +273,7 @@ void KLinesScene::searchAndErase()
// up-right diagonal
for(int x=0; x<FIELD_SIZE-4; ++x)
for(int y=5; y<FIELD_SIZE; ++y)
for(int y=4; y<FIELD_SIZE; ++y)
{
if(m_field[x][y] == 0)
continue;
......
......@@ -35,13 +35,19 @@ class KLinesRenderer;
class KLinesAnimator;
class BallItem;
/**
* Displays and drives the game
*/
class KLinesScene : public QGraphicsScene
{
Q_OBJECT
public:
KLinesScene( QObject *parent );
explicit KLinesScene( QObject *parent );
~KLinesScene();
/**
* Resizes scene
*/
void resizeScene( int width, int height );
/**
* Brings in next three balls to scene
......@@ -96,11 +102,19 @@ private:
* or 0 if there's no ball in that cell
*/
BallItem* m_field[FIELD_SIZE][FIELD_SIZE];
/**
* Renderer used to get all the game graphics
*/
const KLinesRenderer* m_renderer;
/**
* Used to start game animations
* This object knows how to do some ball animations
*/
KLinesAnimator* m_animator;
/**
* We need random numbers in this game
*/
KRandomSequence m_randomSeq;
/**
* Position of selected ball (-1,-1) if none
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment