Commit 121619d4 authored by Dmitry Suzdalev's avatar Dmitry Suzdalev

Also disable hint action after game is over

svn path=/branches/work/kreversi_rewrite/; revision=574336
parent a09bf4f4
......@@ -154,8 +154,9 @@ void KReversiScene::beginNextTurn()
}
else
{
// FIXME dimsuz: IMPLEMENT
kDebug() << "GAME OVER" << endl;
// is something else needed?
emit gameOver();
}
}
......
......@@ -48,6 +48,8 @@ public slots:
* Shows hint for player
*/
void slotHint();
signals:
void gameOver();
private:
/**
* Draws a background with 8x8 cell matrix.
......
......@@ -15,7 +15,7 @@
#include <QGraphicsView>
KReversiMainWindow::KReversiMainWindow(QWidget* parent)
: KMainWindow(parent), m_scene(0), m_game(0)
: KMainWindow(parent), m_scene(0), m_game(0), m_undoAct(0), m_hintAct(0)
{
slotNewGame();
// m_scene is created in slotNewGame();
......@@ -34,9 +34,9 @@ void KReversiMainWindow::setupActions()
KAction *quitAct = KStdAction::quit(this, SLOT(close()), actionCollection(), "quit");
m_undoAct = KStdAction::undo( this, SLOT(slotUndo()), actionCollection(), "undo" );
m_undoAct->setEnabled( false ); // nothing to undo at the start of the game
KAction *hintAct = new KAction( KIcon("wizard"), i18n("Hint"), actionCollection(), "hint" );
hintAct->setShortcut( Qt::Key_H );
connect( hintAct, SIGNAL(triggered(bool)), m_scene, SLOT(slotHint()) );
m_hintAct = new KAction( KIcon("wizard"), i18n("Hint"), actionCollection(), "hint" );
m_hintAct->setShortcut( Qt::Key_H );
connect( m_hintAct, SIGNAL(triggered(bool)), m_scene, SLOT(slotHint()) );
KSelectAction *bkgndAct = new KSelectAction(i18n("Choose background"), actionCollection(), "choose_bkgnd");
connect(bkgndAct, SIGNAL(triggered(const QString&)), SLOT(slotBackgroundChanged(const QString&)));
......@@ -61,7 +61,7 @@ void KReversiMainWindow::setupActions()
addAction(newGameAct);
addAction(quitAct);
addAction(m_undoAct);
addAction(hintAct);
addAction(m_hintAct);
}
void KReversiMainWindow::slotBackgroundChanged( const QString& text )
......@@ -85,10 +85,14 @@ void KReversiMainWindow::slotNewGame()
m_game = new KReversiGame;
connect( m_game, SIGNAL(moveFinished()), SLOT(slotMoveFinished()) );
if(m_hintAct)
m_hintAct->setEnabled( true );
if(m_scene == 0) // if called first time
{
// FIXME dimsuz: if chips.png not found give error end exit
m_scene = new KReversiScene(m_game, KStandardDirs::locate("appdata", "pics/chips.png"));
connect( m_scene, SIGNAL(gameOver()), SLOT(slotGameOver()) );
}
else
{
......@@ -96,6 +100,11 @@ void KReversiMainWindow::slotNewGame()
}
}
void KReversiMainWindow::slotGameOver()
{
m_hintAct->setEnabled(false);
}
void KReversiMainWindow::slotMoveFinished()
{
m_undoAct->setEnabled( m_game->canUndo() );
......@@ -108,6 +117,9 @@ void KReversiMainWindow::slotUndo()
// scene will automatically notice that it needs to update
m_game->undo();
m_undoAct->setEnabled( m_game->canUndo() );
// if the user hits undo after game is over
// let's give him a chance to ask for a hint ;)
m_hintAct->setEnabled( true );
}
}
......
......@@ -18,6 +18,7 @@ public slots:
void slotBackgroundChanged(const QString& text);
void slotUndo();
void slotMoveFinished();
void slotGameOver();
private:
void setupActions();
......@@ -26,5 +27,6 @@ private:
KReversiGame *m_game;
KAction* m_undoAct;
KAction* m_hintAct;
};
#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