[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-06 20:37:29
Message-ID: 1157575049.264219.12877.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 581610 by dimsuz:
Moved KReversiScene::beginNextTurn() to KReversiGame::nextTurn() where it really belongs
Added computerCantMove() signal to KReversiGame
M +42 -0 kreversigame.cpp
M +12 -0 kreversigame.h
M +8 -53 kreversiscene.cpp
M +0 -8 kreversiscene.h
M +7 -1 mainwindow.cpp
M +1 -0 mainwindow.h
--- branches/work/kreversi_rewrite/kreversigame.cpp #581609:581610
@@ -38,6 +38,48 @@
m_undoStack.push( m_changedChips );
}
+void KReversiGame::nextTurn(bool demoMode)
+{
+ if( !isGameOver() )
+ {
+ if( isComputersTurn() )
+ {
+ if(isAnyComputerMovePossible())
+ {
+ makeComputerMove();
+ }
+ else if( demoMode )
+ {
+ makePlayerMove(-1, -1, true );
+ }
+ else // no comp move possible and not in demo mode
+ {
+ kDebug() << "Computer can't move!" << endl;
+ emit computerCantMove();
+ }
+ }
+ else
+ {
+ // if player cant move let the computer play again!
+ if( !isAnyPlayerMovePossible() )
+ {
+ // FIXME dimsuz: emit something like "playerCantMove()" for gui to catch this?
+ kDebug() << "Player can't move!" << endl;
+ makeComputerMove();
+ }
+ else if( demoMode ) // let the computer play instead of player
+ {
+ makePlayerMove( -1, -1, true );
+ }
+ }
+ }
+ else
+ {
+ kDebug() << "GAME OVER" << endl;
+ emit gameOver();
+ }
+}
+
void KReversiGame::makeComputerMove()
{
m_curPlayer = m_computerColor;
--- branches/work/kreversi_rewrite/kreversigame.h #581609:581610
@@ -15,6 +15,7 @@
* 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.
@@ -36,6 +37,15 @@
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.
+ *
+ * @param demoMode if true then computer will decide for player turn
+ */
+ void nextTurn(bool demoMode);
+ /**
* This will make the player move at row, col.
* If that is possible of course
* If demoMode is true, the computer will decide on what move to take.
@@ -117,8 +127,10 @@
*/
MoveList possibleMoves() const;
signals:
+ void gameOver();
void boardChanged();
void moveFinished();
+ void computerCantMove();
private:
enum Direction { Up, Down, Right, Left, UpLeft, UpRight, DownLeft, DownRight };
/**
--- branches/work/kreversi_rewrite/kreversiscene.cpp #581609:581610
@@ -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() )
- beginNextTurn(); // it will take m_demoMode into account
+ m_game->nextTurn(m_demoMode);
}
void KReversiScene::slotGameMoveFinished()
@@ -226,8 +226,8 @@
displayLastAndPossibleMoves();
- // some better name maybe?
- beginNextTurn();
+ // FIXME dimsuz: set m_demoMode=false on GAME OVER somewhere!
+ m_game->nextTurn(m_demoMode);
}
}
}
@@ -238,54 +238,6 @@
}
}
-void KReversiScene::beginNextTurn()
-{
- if( !m_game->isGameOver() )
- {
- if( m_game->isComputersTurn() )
- {
- if(m_game->isAnyComputerMovePossible())
- {
- m_game->makeComputerMove();
- }
- else
- {
- // FIXME dimsuz: display this in GUI
- kDebug() << "Computer can't move!" << endl;
- if( m_demoMode )
- m_game->makePlayerMove(-1, -1, true );
- }
-
- // else we'll just do nothing and wait for
- // player's mouse input
- }
- else
- {
- // if player cant move there's no sence in waiting for mouseInput.
- // Let the computer play again!
- if( !m_game->isAnyPlayerMovePossible() )
- {
- // FIXME dimsuz: display this in GUI
- kDebug() << "Player can't move!" << endl;
- m_game->makeComputerMove();
- }
- else // else if we're in the demo-mode let the computer play instead of player
- {
- // "true" means "let the computer find best row and col for move"
- if( m_demoMode )
- m_game->makePlayerMove( -1, -1, true );
- }
- }
- }
- else
- {
- kDebug() << "GAME OVER" << endl;
- m_demoMode = false;
- // is something else needed?
- emit gameOver();
- }
-}
-
void KReversiScene::displayLastAndPossibleMoves()
{
// ==== Show What Last Move Was ====
@@ -431,14 +383,17 @@
m_showingHint = false;
update(m_hintChip->sceneBoundingRect());
}
- else // scene is animating move now...
- kDebug() << "Don't you see I'm animating? Be patient, human child..." << endl;
}
}
void KReversiScene::mousePressEvent( QGraphicsSceneMouseEvent* ev )
{
stopHintAnimation();
+ if( m_animTimer->isActive() )
+ {
+ kDebug() << "Don't you see I'm animating? Be patient, human child..." << endl;
+ return;
+ }
if( !m_boardRect.contains(ev->scenePos()) )
return;
--- branches/work/kreversi_rewrite/kreversiscene.h #581609:581610
@@ -77,7 +77,6 @@
*/
void toggleDemoMode(bool toggle);
signals:
- void gameOver();
/**
* emitted when Scene finishes displaying last move
*/
@@ -90,13 +89,6 @@
virtual void drawBackground( QPainter *p, const QRectF& rect );
virtual void mousePressEvent( QGraphicsSceneMouseEvent* );
/**
- * 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 tells m_game to perform computer move.
- * Else it just sits and wait for user's mouse input (= his turn)
- */
- void beginNextTurn();
- /**
* Visually displays last move and possible moves
* (if the scene is set up to show them)
*/
--- branches/work/kreversi_rewrite/mainwindow.cpp #581609:581610
@@ -215,6 +215,8 @@
{
delete m_game;
m_game = new KReversiGame;
+ connect( m_game, SIGNAL(gameOver()), SLOT(slotGameOver()) );
+ connect( m_game, SIGNAL(computerCantMove()), SLOT(slotComputerCantMove()) );
if(m_hintAct)
m_hintAct->setEnabled( true );
@@ -230,7 +232,6 @@
{
// 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()) );
connect( m_scene, SIGNAL(moveFinished()), SLOT(slotMoveFinished()) );
}
else
@@ -276,6 +277,11 @@
statusBar()->changeItem( i18n("Computer: %1", m_game->playerScore(White) ), COMP_STATUSBAR_ID);
}
+void KReversiMainWindow::slotComputerCantMove()
+{
+ statusBar()->changeItem( i18n("Computer can not make move. Your turn."), 0 );
+}
+
void KReversiMainWindow::slotUndo()
{
if( !m_scene->isBusy() )
--- branches/work/kreversi_rewrite/mainwindow.h #581609:581610
@@ -28,6 +28,7 @@
void slotDemoMode(bool);
void slotUseColoredChips(bool);
void slotShowMovesHistory(bool);
+ void slotComputerCantMove();
private:
void setupActions();
void loadSettings();
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic