Commit 9505f5ae authored by Dmitry Suzdalev's avatar Dmitry Suzdalev
Browse files

Preparations for support for displaying next balls' colors

svn path=/trunk/KDE/kdegames/klines/; revision=616712
parent 641ce99f
......@@ -55,6 +55,14 @@ KLinesScene::KLinesScene( QObject* parent )
for(int x=0; x<FIELD_SIZE; ++x)
for(int y=0; y<FIELD_SIZE; ++y)
m_field[x][y] = 0;
// init m_nextColors
for(int i=0; i<3; i++)
{
// random color
BallColor c = static_cast<BallColor>(m_randomSeq.getLong(static_cast<int>(NumColors)));
m_nextColors.append(c);
}
nextThreeBalls();
}
......@@ -77,17 +85,26 @@ void KLinesScene::nextThreeBalls()
BallItem* newBall;
for(int i=0; i<3; i++)
{
newBall = placeRandomBall();
newBall = randomlyPlaceBall( m_nextColors.at(i) );
if( newBall )
newItems.append(newBall);
else
break; // the field is filled :).
}
for(int i=0; i<3; i++)
{
// random color
BallColor c = static_cast<BallColor>(m_randomSeq.getLong(static_cast<int>(NumColors)));
m_nextColors[i] = c;
}
emit nextColorsChanged();
m_animator->animateBorn( newItems );
}
BallItem* KLinesScene::placeRandomBall()
BallItem* KLinesScene::randomlyPlaceBall(BallColor c)
{
m_numFreeCells--;
if(m_numFreeCells < 0)
......@@ -105,9 +122,6 @@ BallItem* KLinesScene::placeRandomBall()
posy = m_randomSeq.getLong(FIELD_SIZE);
} while( m_field[posx][posy] != 0 );
// random color
BallColor c = static_cast<BallColor>(m_randomSeq.getLong(static_cast<int>(NumColors)));
BallItem* newBall = new BallItem( this, m_renderer );
newBall->setColor(c);
newBall->setPos( fieldToPix( FieldPos(posx,posy) ) );
......
......@@ -49,6 +49,10 @@ public:
* Resizes scene
*/
void resizeScene( int width, int height );
/**
* Returns colors of the 3 balls in the next turn
*/
QList<BallColor> nextColors() const { return m_nextColors; }
/**
* Brings in next three balls to scene
*/
......@@ -79,6 +83,7 @@ public:
return FieldPos(static_cast<int>(p.x()/32), static_cast<int>(p.y()/32)); }
signals:
void scoreChanged(int);
void nextColorsChanged();
void gameOver(int);
private slots:
void moveAnimFinished();
......@@ -86,10 +91,11 @@ private slots:
void bornAnimFinished();
private:
/**
* Creates a ball of random color and places it in random free cell
* Creates a ball and places it in random free cell
* @param c color of the ball
* @return ball placed
*/
BallItem* placeRandomBall();
BallItem* randomlyPlaceBall(BallColor c);
/**
* Searches for 5 or more balls in a row and deletes them from field
*/
......@@ -142,6 +148,10 @@ private:
* Items pending for removal after remove-anim finishes
*/
QList<BallItem*> m_itemsToDelete;
/**
* Colors of the next turn's balls
*/
QList<BallColor> m_nextColors;
};
class KLinesView : public QGraphicsView
......
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