Commit dcb78cc2 authored by Dmitry Suzdalev's avatar Dmitry Suzdalev

Implemented kaction & co for setting computer skill

svn path=/branches/work/kreversi_rewrite/; revision=580783
parent bd81e747
......@@ -61,7 +61,7 @@ public:
* Supposes that allFrames represents an animation sequence
* going from black to white.
* @param allFrames a pixmap containing whole animation sequence
* @param chipSize size of each frame's pixmap. Frames are squares.
* @param frameSize size of each frame's pixmap. Frames are squares.
*/
KReversiChipFrameSet( const QPixmap& allFrames, int frameSize );
/**
......
......@@ -435,6 +435,12 @@ bool KReversiGame::isAnyComputerMovePossible() const
return false;
}
void KReversiGame::setComputerSkill(int skill)
{
kDebug() << "setting skill to " << skill << endl;
m_engine->setStrength( skill );
}
KReversiMove KReversiGame::getHint() const
{
// FIXME dimsuz: don't use true, use m_competitive
......
......@@ -55,6 +55,10 @@ public:
* Sets the strength of game engine (1 to 7)
*/
void setEngineStrength(uint strength);
/**
* Sets the computer skill level. From 1 to 7
*/
void setComputerSkill(int skill);
/**
* @return strength of the game engine
*/
......
......@@ -13,6 +13,8 @@
</Menu>
<Menu name="settings"><text>&amp;Settings</text>
<Action name="choose_bkgnd" />
<Action name="anim_speed" />
<Action name="skill" />
</Menu>
</MenuBar>
......
......@@ -27,6 +27,8 @@ KReversiMainWindow::KReversiMainWindow(QWidget* parent)
m_view->show();
setupActions();
loadSettings();
setCentralWidget(m_view);
statusBar()->insertItem( i18n("Your turn."), 0 );
......@@ -47,8 +49,8 @@ void KReversiMainWindow::setupActions()
m_demoAct->setShortcut( Qt::Key_D );
connect(m_demoAct, SIGNAL(triggered(bool)), SLOT(slotDemoMode(bool)) );
KSelectAction *bkgndAct = new KSelectAction(i18n("Choose background"), actionCollection(), "choose_bkgnd");
connect(bkgndAct, SIGNAL(triggered(const QString&)), SLOT(slotBackgroundChanged(const QString&)));
m_bkgndAct = new KSelectAction(i18n("Choose background"), actionCollection(), "choose_bkgnd");
connect(m_bkgndAct, SIGNAL(triggered(const QString&)), SLOT(slotBackgroundChanged(const QString&)));
QStringList pixList = kapp->dirs()->findAllResources( "appdata", "pics/background/*.png", false, true );
// let's find a name of files w/o extensions
......@@ -58,19 +60,27 @@ void KReversiMainWindow::setupActions()
{
int idx1 = str.lastIndexOf('/');
int idx2 = str.lastIndexOf('.');
bkgndAct->addAction(str.mid(idx1+1,idx2-idx1-1));
m_bkgndAct->addAction(str.mid(idx1+1,idx2-idx1-1));
}
bkgndAct->setCurrentAction( Preferences::backgroundImageName() );
slotBackgroundChanged( Preferences::backgroundImageName() );
KToggleAction *showLast = new KToggleAction(KIcon("lastmoves"), i18n("Show last move"), actionCollection(), "show_last_move");
connect( showLast, SIGNAL(triggered(bool)), m_scene, SLOT(setShowLastMove(bool)) );
KToggleAction *showLegal = new KToggleAction(KIcon("legalmoves"), i18n("Show legal moves"), actionCollection(), "show_legal_moves" );
connect( showLegal, SIGNAL(triggered(bool)), m_scene, SLOT(setShowLegalMoves(bool)) );
KSelectAction *animSpeed = new KSelectAction(i18n("Animation speed"), actionCollection(), "anim_speed");
QStringList acts;
acts << "Slow" << "Normal" << "Fast";
animSpeed->setItems(acts);
m_skillAct = new KSelectAction(i18n("Computer skill"), actionCollection(), "skill" );
acts.clear();
// FIXME dimsuz: this utilises 5 skills. although 7 is possible
acts << "Very easy" << "Easy" << "Normal" << "Hard" << "Unbeatable";
m_skillAct->setItems(acts);
connect(m_skillAct, SIGNAL(triggered(int)), SLOT(slotSkillChanged(int)) );
addAction(newGameAct);
addAction(quitAct);
addAction(m_undoAct);
......@@ -78,6 +88,16 @@ void KReversiMainWindow::setupActions()
addAction(m_demoAct);
}
void KReversiMainWindow::loadSettings()
{
m_bkgndAct->setCurrentAction( Preferences::backgroundImageName() );
slotBackgroundChanged( Preferences::backgroundImageName() );
int skill = Preferences::skill();
m_skillAct->setCurrentItem( skill - 1 );
slotSkillChanged( skill - 1 );
}
void KReversiMainWindow::slotBackgroundChanged( const QString& text )
{
// FIXME dimsuz: I'm removing "&" from text here, because
......@@ -96,6 +116,14 @@ void KReversiMainWindow::slotBackgroundChanged( const QString& text )
Preferences::writeConfig();
}
void KReversiMainWindow::slotSkillChanged(int skill)
{
// m_game takes it from 1 to 7
m_game->setComputerSkill( skill+1 );
Preferences::setSkill( skill+1 );
Preferences::writeConfig();
}
void KReversiMainWindow::slotDemoMode(bool toggled)
{
kDebug() << k_funcinfo << endl;
......
......@@ -7,6 +7,7 @@ class KReversiScene;
class KReversiGame;
class KReversiView;
class KAction;
class KSelectAction;
class KReversiMainWindow : public KMainWindow
{
......@@ -16,12 +17,14 @@ public:
public slots:
void slotNewGame();
void slotBackgroundChanged(const QString& text);
void slotSkillChanged(int);
void slotUndo();
void slotMoveFinished();
void slotGameOver();
void slotDemoMode(bool);
private:
void setupActions();
void loadSettings();
KReversiScene *m_scene;
KReversiView *m_view;
......@@ -30,5 +33,7 @@ private:
KAction* m_undoAct;
KAction* m_hintAct;
KAction* m_demoAct;
KSelectAction* m_bkgndAct;
KSelectAction* m_skillAct;
};
#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