[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-07 8:30:02
Message-ID: 1157617802.534346.29940.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 581702 by dimsuz:

Updated some documentation pieces


 M  +1 -1      kreversigame.cpp  
 M  +20 -16    kreversigame.h  
 M  +2 -2      kreversiscene.cpp  
 M  +2 -0      mainwindow.cpp  


--- branches/work/kreversi_rewrite/kreversigame.cpp #581701:581702
@@ -38,7 +38,7 @@
     m_undoStack.push( m_changedChips );
 }
 
-void KReversiGame::nextTurn(bool demoMode)
+void KReversiGame::startNextTurn(bool demoMode)
 {
     if( !isGameOver() )
     {
--- branches/work/kreversi_rewrite/kreversigame.h #581701:581702
@@ -15,18 +15,11 @@
  *  Whenever the board state changes it emits corresponding signals.
  *  The idea is also to abstract from any graphic representation of the game process
  *
- * FIXME dimsuz: re-document this! :)
  *  KReversiGame is supposed to be driven by someone from outside.
  *  I.e. it receives commands and emits events when it's internal state changes
  *  due to this commands dispatching.
  *  The main commands are:
- *  makePlayerMove() and makeComputerMove()
- *  Also, after each turn is made a user of this class should check
- *  that isGameOver() returns false,
- *  and that next player can move 
- *  (by calling isAnyPlayerMovePossible() || isAnyComputerMovePossible()).
- *  If, for example isAnyPlayerMovePossible() returns false, than player needs to skip and 
- *  makeComputerMove() should be called.
+ *  startNextTurn() and  makePlayerMove()
  *
  *  See KReversiScene for example of working with KReversiGame
  */
@@ -37,14 +30,24 @@
     KReversiGame();
     ~KReversiGame();
     /**
-     *  Makes next player turn.
-     *  Checks if players can move and if they can then:
-     *  if it's time for computer to move or user is locked and can't move,
-     *  this function performs a computer move.
+     *  Starts next player turn.
+     *  If game isn't over yet, then this function do the following:
+     *  - if it is computer turn and computer can move, it'll make that move.
+     *  - if it is computer turn and computer can't move it'll emit "computerCantMove"
+     *  signal and exit
+     *  - if it is player turn and player can move then this function 
+     *  will do nothing - you can call makePlayerMove(row,col) to make player move (but see last item)
+     *  - if it is player turn and player can't move it'll make a computer move
+     *  - in demo mode this function will make computer play player moves,
+     *  so you don't need to call makePlayerMove.
+     *  
+     *  If it's still unclear how to use it please see KReversiScene for working example.
+     *  In short: it calls startNextTurn() at the end of each turn and makePlayerMove() 
+     *  in mouseReleaseEvent()
      *
      *  @param demoMode if true then computer will decide for player turn
      */
-    void nextTurn(bool demoMode);
+    void startNextTurn(bool demoMode);
     /**
      *  This will make the player move at row, col.
      *  If that is possible of course
@@ -59,6 +62,7 @@
     void makeComputerMove();
     /**
      *  Undoes all the computer moves and one player move
+     *  (so after calling this function it will be player turn)
      *  @return number of undone moves
      */
     int undo();
@@ -77,15 +81,15 @@
     /**
      *  @return whether the game is already over
      */
-    bool isGameOver() const;
+    bool isGameOver() const; // perhaps this doesn't need to be public
     /**
      *  @return whether any player move is at all possible
      */
-    bool isAnyPlayerMovePossible() const;
+    bool isAnyPlayerMovePossible() const;// perhaps this doesn't need to be public
     /**
      *  @return whether any computer move is at all possible
      */
-    bool isAnyComputerMovePossible() const;
+    bool isAnyComputerMovePossible() const;// perhaps this doesn't need to be public
     /**
      *  @return a color of the current player
      */
--- branches/work/kreversi_rewrite/kreversiscene.cpp #581701:581702
@@ -179,7 +179,7 @@
     // if we are currently waiting for user mouse input and not animating,
     // let's do the turn right now!
     if( !m_game->isComputersTurn() && !m_animTimer->isActive() )
-        m_game->nextTurn(m_demoMode);
+        m_game->startNextTurn(m_demoMode);
 }
 
 void KReversiScene::slotGameMoveFinished()
@@ -227,7 +227,7 @@
                 displayLastAndPossibleMoves();
 
                 // FIXME dimsuz: set m_demoMode=false on GAME OVER somewhere!
-                m_game->nextTurn(m_demoMode);
+                m_game->startNextTurn(m_demoMode);
             }
         }
     }
--- branches/work/kreversi_rewrite/mainwindow.cpp #581701:581702
@@ -253,6 +253,8 @@
     int blackScore = m_game->playerScore(Black);
     int whiteScore = m_game->playerScore(White);
     QString res =  blackScore > whiteScore ? i18n("You win!") : i18n("You have lost!");
+    if( blackScore == whiteScore )
+        res = i18n("Game is drawn!");
     res += i18n("\nYou: %1", blackScore);
     res += i18n("\nComputer: %1", whiteScore);
 
[prev in list] [next in list] [prev in thread] [next in thread] 

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