[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/work/kreversi_rewrite
From:       Dmitry Suzdalev <dimsuz () gmail ! com>
Date:       2006-09-04 13:34:42
Message-ID: 1157376882.070678.24256.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 580783 by dimsuz:

Implemented kaction & co for setting computer skill


 M  +1 -1      kreversichip.h  
 M  +6 -0      kreversigame.cpp  
 M  +4 -0      kreversigame.h  
 M  +2 -0      kreversiui.rc  
 M  +35 -7     mainwindow.cpp  
 M  +5 -0      mainwindow.h  


--- branches/work/kreversi_rewrite/kreversichip.h #580782:580783
@@ -61,7 +61,7 @@
      *  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 );
     /**
--- branches/work/kreversi_rewrite/kreversigame.cpp #580782:580783
@@ -435,6 +435,12 @@
     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
--- branches/work/kreversi_rewrite/kreversigame.h #580782:580783
@@ -56,6 +56,10 @@
      */
     void setEngineStrength(uint strength);
     /**
+     *  Sets the computer skill level. From 1 to 7
+     */
+    void setComputerSkill(int skill);
+    /**
      *  @return strength of the game engine
      */
     uint strength() const;
--- branches/work/kreversi_rewrite/kreversiui.rc #580782:580783
@@ -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>
 
--- branches/work/kreversi_rewrite/mainwindow.cpp #580782:580783
@@ -27,6 +27,8 @@
     m_view->show();
 
     setupActions();
+    loadSettings();
+
     setCentralWidget(m_view);
 
     statusBar()->insertItem( i18n("Your turn."), 0 );
@@ -47,8 +49,8 @@
     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 @@
     {
         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 @@
     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 @@
     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;
--- branches/work/kreversi_rewrite/mainwindow.h #580782:580783
@@ -7,6 +7,7 @@
 class KReversiGame;
 class KReversiView;
 class KAction;
+class KSelectAction;
 
 class KReversiMainWindow : public KMainWindow
 {
@@ -16,12 +17,14 @@
 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 @@
     KAction* m_undoAct;
     KAction* m_hintAct;
     KAction* m_demoAct;
+    KSelectAction* m_bkgndAct;
+    KSelectAction* m_skillAct;
 };
 #endif


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic