Commit 47b8883f authored by Dmitry Suzdalev's avatar Dmitry Suzdalev

- KReversi: add "--demo" option which will start kreversi in demo mode.

  As someone stated somewhere this could be useful during presentations.
  Demo is looped - i.e, after game is lost, new game is started.
- KAtomic: minor fix - added KCmdLastOption which I missed yesterday

svn path=/trunk/KDE/kdegames/kreversi/; revision=654531
parent e1782ee0
......@@ -284,7 +284,7 @@ void KReversiScene::slotGameMoveFinished()
void KReversiScene::slotAnimationStep()
{
if(m_changedChips.count() == 0)
if(m_changedChips.count() == 0 && !m_showingHint)
{
// FIXME: GGZ only - doesn't yet report flipped chips
m_animTimer->stop();
......
......@@ -24,9 +24,9 @@
#include <kapplication.h>
#include <klocale.h>
#include <kcmdlineargs.h>
#include <kaboutdata.h>
#include <klocale.h>
#include "highscores.h"
#include "mainwindow.h"
......@@ -34,11 +34,17 @@
static const char description[] = I18N_NOOP("KDE Reversi Board Game");
static const KCmdLineOptions options[] =
{
{"demo", I18N_NOOP( "Start with demo game playing" ), 0 },
KCmdLineLastOption
};
int main(int argc, char **argv)
{
KAboutData aboutData( "kreversi", I18N_NOOP("KReversi"),
KREVERSI_VERSION, description, KAboutData::License_GPL,
"(c) 1997-2000, Mario Weilguni\n(c) 2004-2006, Inge Wallin\n(c) 2006, Dmitry Suzdalev");
KREVERSI_VERSION, description, KAboutData::License_GPL,
"(c) 1997-2000, Mario Weilguni\n(c) 2004-2006, Inge Wallin\n(c) 2006, Dmitry Suzdalev");
aboutData.addAuthor("Mario Weilguni",I18N_NOOP("Original author"), "mweilguni@sime.com");
aboutData.addAuthor("Inge Wallin",I18N_NOOP("Original author"), "inge@lysator.liu.se");
aboutData.addAuthor("Dmitry Suzdalev", I18N_NOOP("Game rewrite for KDE4. Current maintainer."), "dimsuz@gmail.com");
......@@ -47,6 +53,7 @@ int main(int argc, char **argv)
aboutData.addCredit("Mauricio Piacentini", I18N_NOOP("Vector chips and background for KDE4."), 0);
KCmdLineArgs::init( argc, argv, &aboutData );
KCmdLineArgs::addCmdLineOptions( options );
KApplication application;
if( application.isSessionRestored() )
......@@ -55,7 +62,8 @@ int main(int argc, char **argv)
}
else
{
KReversiMainWindow *mainWin = new KReversiMainWindow;
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
KReversiMainWindow *mainWin = new KReversiMainWindow( 0, args->isSet( "demo" ) );
mainWin->show();
}
......
......@@ -67,10 +67,11 @@ static QString moveToString( const KReversiPos& move )
return moveString;
}
KReversiMainWindow::KReversiMainWindow(QWidget* parent)
KReversiMainWindow::KReversiMainWindow(QWidget* parent, bool startDemo )
: KMainWindow(parent), m_scene(0), m_game(0),
m_historyLabel(0), m_historyView(0), m_undoAct(0),
m_hintAct(0), m_demoAct(0)
m_historyLabel(0), m_historyView(0),
m_firstShow( true ), m_startInDemoMode( startDemo ),
m_undoAct(0), m_hintAct(0), m_demoAct(0)
{
statusBar()->insertItem( i18n("Your turn."), 0 );
statusBar()->insertItem( i18n("You: %1", 2), PLAYER_STATUSBAR_ID );
......@@ -121,6 +122,7 @@ void KReversiMainWindow::setupActions()
m_demoAct->setIcon( KIcon("media-playback-start") );
m_demoAct->setText( i18n("Demo") );
m_demoAct->setShortcut( Qt::Key_D );
m_demoAct->setCheckable( true );
connect(m_demoAct, SIGNAL(triggered(bool)), SLOT(slotToggleDemoMode()) );
m_seatsAct = actionCollection()->addAction( "game_seats" );
......@@ -233,11 +235,13 @@ void KReversiMainWindow::slotToggleDemoMode()
{
toggled = false;
m_demoAct->setIcon( KIcon("media-playback-start") );
m_demoAct->setChecked( false );
}
else
{
toggled = true;
m_demoAct->setIcon( KIcon("media-playback-pause") );
m_demoAct->setChecked( true );
}
m_scene->toggleDemoMode(toggled);
......@@ -257,7 +261,10 @@ void KReversiMainWindow::slotNewGame()
if(m_hintAct)
m_hintAct->setEnabled( true );
if(m_demoAct)
{
m_demoAct->setChecked( false );
m_demoAct->setIcon( KIcon("media-playback-start") );
}
if(m_undoAct)
m_undoAct->setEnabled( false );
......@@ -283,9 +290,17 @@ void KReversiMainWindow::slotNewGame()
void KReversiMainWindow::slotGameOver()
{
m_hintAct->setEnabled(false);
m_demoAct->setChecked(false);
m_undoAct->setEnabled(true);
if ( m_scene->isInDemoMode() )
{
// let's loop! :-)
slotToggleDemoMode();// turn off
slotNewGame();
slotToggleDemoMode();// turn on
return;
}
statusBar()->changeItem( i18n("GAME OVER."), 0 );
int blackScore = m_game->playerScore(Black);
......@@ -381,4 +396,14 @@ void KReversiMainWindow::slotSeats()
// FIXME (josef): player might want to use it alongside game window
}
void KReversiMainWindow::showEvent( QShowEvent* )
{
if ( m_firstShow && m_startInDemoMode )
{
kDebug() << "starting demo..." <<endl;
slotToggleDemoMode();
}
m_firstShow = false;
}
#include "mainwindow.moc"
......@@ -38,7 +38,7 @@ class KReversiMainWindow : public KMainWindow
{
Q_OBJECT
public:
explicit KReversiMainWindow(QWidget* parent=0);
explicit KReversiMainWindow(QWidget* parent=0, bool startDemo=false );
public slots:
void slotNewGame();
void slotSkillChanged(int);
......@@ -53,6 +53,7 @@ public slots:
void slotHighscores();
void slotSeats();
private:
virtual void showEvent( QShowEvent* );
void setupActions();
void loadSettings();
......@@ -62,6 +63,9 @@ private:
QLabel *m_historyLabel;
QListWidget *m_historyView;
bool m_firstShow;
bool m_startInDemoMode;
QAction* m_undoAct;
QAction* m_hintAct;
QAction* m_demoAct;
......
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