Commit 88953f85 authored by Dmitry Suzdalev's avatar Dmitry Suzdalev
Browse files

Started to implement "Game Over" screen - klines lacks one currently.

And some minor tweaks.

svn path=/trunk/KDE/kdegames/klines/; revision=675605
parent c867c376
......@@ -293,4 +293,24 @@ void KLinesAnimator::findPath( const FieldPos& from, const FieldPos& to )
qDeleteAll( closedList );
}
void KLinesAnimator::startGameOverAnimation()
{
blockSignals(true);
QList<BallItem*> balls;
QList<QGraphicsItem*> items = m_scene->items();
BallItem *ball=0;
foreach( QGraphicsItem* item, items )
{
ball = qgraphicsitem_cast<BallItem*>(item);
if(ball)
balls.append(ball);
}
animateRemove(balls);
}
void KLinesAnimator::stopGameOverAnimation()
{
blockSignals(false);
}
#include "animator.moc"
/*******************************************************************
*
* Copyright 2006 Dmitry Suzdalev <dimsuz@gmail.com>
* Copyright 2006-2007 Dmitry Suzdalev <dimsuz@gmail.com>
*
* This file is part of the KDE project "KLines"
*
......@@ -62,6 +62,14 @@ public:
* @return whether some animation is in progress
*/
bool isAnimating() const;
/**
* Starts game over animation on the scene, shows game over message
*/
void startGameOverAnimation();
/**
* Stops game over animation
*/
void stopGameOverAnimation();
signals:
void moveFinished();
void removeFinished();
......
......@@ -101,7 +101,7 @@ void KLinesMainWindow::gameOver(int score)
{
KScoreDialog d(KScoreDialog::Name | KScoreDialog::Score, this);
d.addScore(score, KScoreDialog::AskName);
d.exec();
// d.exec();
}
void KLinesMainWindow::viewHighScore()
......
/*******************************************************************
*
* Copyright 2006 Dmitry Suzdalev <dimsuz@gmail.com>
* Copyright 2006-2007 Dmitry Suzdalev <dimsuz@gmail.com>
*
* This file is part of the KDE project "KLines"
*
......@@ -58,6 +58,7 @@ void KLinesScene::startNewGame()
m_score = 0;
m_bonusScore = 0;
m_placeBalls = true;
m_gameOver = false;
m_itemsToDelete.clear();
m_nextColors.clear();
m_focusItem->setPos(0, 0);
......@@ -88,6 +89,7 @@ void KLinesScene::startNewGame()
emit stateChanged("not_undoable");
m_animator->stopGameOverAnimation();
nextThreeBalls();
}
......@@ -143,6 +145,9 @@ void KLinesScene::resizeScene(int width,int height)
void KLinesScene::endTurn()
{
if( m_gameOver )
return;
saveUndoInfo();
nextThreeBalls();
}
......@@ -274,9 +279,8 @@ void KLinesScene::removeAnimFinished()
{
if( m_itemsToDelete.isEmpty() && m_numFreeCells == 0 )
{
emit stateChanged("not_undoable");
//emit enableUndo(false);
emit gameOver(m_score);
// game over
gameOverHandler();
return;
}
......@@ -312,18 +316,16 @@ void KLinesScene::removeAnimFinished()
if(numBallsErased)
emit scoreChanged(m_score);
}
}
void KLinesScene::bornAnimFinished()
{
// note that if m_numFreeCells == 0, we still need to
// check for possible 5-in-a-row balls, i.e. call searchAndErase()
// So there's another gameOver()-check in removeAnimFinished()
// So there's another gameOver-check in removeAnimFinished()
if( m_numFreeCells < 0 )
{
kDebug() << "GAME OVER" << endl;
emit gameOver(m_score);
gameOverHandler();
return;
}
// There's a little trick here:
......@@ -340,11 +342,7 @@ void KLinesScene::bornAnimFinished()
// And because of that we check for gameOver in removeAnimFinished()
// rather than here - there's a chance that searchAndErase() will remove
// balls making some free cells to play in
if (!searchAndErase() && m_numFreeCells == 0)
{
kDebug() << "GAME OVER" << endl;
emit gameOver(m_score);
}
searchAndErase();
}
bool KLinesScene::searchAndErase()
......@@ -613,4 +611,16 @@ void KLinesScene::drawBackground(QPainter *p, const QRectF&)
p->drawPixmap( x, y, KLinesRenderer::self()->backgroundTilePixmap() );
}
void KLinesScene::gameOverHandler()
{
if( m_gameOver )
return; // don't emit twice
m_gameOver = true;
kDebug() << "GAME OVER" << endl;
emit stateChanged("not_undoable");
//emit enableUndo(false);
emit gameOver(m_score);
m_animator->startGameOverAnimation();
}
#include "scene.moc"
......@@ -157,6 +157,10 @@ private:
* Saves game state information to be used during undo
*/
void saveUndoInfo();
/** Does some actions upon game over. Called from various places where
* it is clear that game is now over. emits gameOver(int) signal
*/
void gameOverHandler();
virtual void drawBackground( QPainter*, const QRectF& );
virtual void mousePressEvent( QGraphicsSceneMouseEvent* );
......@@ -241,6 +245,7 @@ private:
* It is saved before every new turn
*/
UndoInfo m_undoInfo;
bool m_gameOver;
};
#endif
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