[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-08-20 18:10:29
Message-ID: 1156097429.134270.27052.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 575067 by dimsuz:
Implemented "Demo Mode" - computer makes turns instead of player
M +8 -4 kreversigame.cpp
M +3 -1 kreversigame.h
M +23 -2 kreversiscene.cpp
M +17 -1 kreversiscene.h
M +3 -1 kreversiui.rc
M +5 -0 mainwindow.cpp
--- branches/work/kreversi_rewrite/kreversigame.cpp #575066:575067
@@ -18,12 +18,16 @@
delete m_engine;
}
-void KReversiGame::makePlayerMove( int row, int col )
+void KReversiGame::makePlayerMove( int row, int col, bool demoMode )
{
m_curPlayer = m_playerColor;
- KReversiMove move( m_playerColor, row, col );
- // this can help you to see computer vs computer battle :)
- //KReversiMove move = m_engine->computeMove( *this, true );
+ KReversiMove move;
+
+ if( !demoMode )
+ move = KReversiMove( m_playerColor, row, col );
+ else
+ move = m_engine->computeMove( *this, true );
+
if( !isMovePossible(move) )
{
kDebug() << "No move possible" << endl;
--- branches/work/kreversi_rewrite/kreversigame.h #575066:575067
@@ -76,8 +76,10 @@
/**
* 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.
+ * row and col values do not matter in that case.
*/
- void makePlayerMove(int row, int col);
+ void makePlayerMove(int row, int col, bool demoMode);
/**
* This function will make computer decide where he
* wants to put his chip... and he'll put it there!
--- branches/work/kreversi_rewrite/kreversiscene.cpp #575066:575067
@@ -14,7 +14,7 @@
const int CHIP_SIZE = 36;
KReversiScene::KReversiScene( KReversiGame* game , const QPixmap& chipsPixmap )
- : m_showingHint(false), m_hintChip(0)
+ : m_showingHint(false), m_hintChip(0), m_demoMode(false)
{
setBackgroundBrush( Qt::lightGray );
@@ -84,6 +84,15 @@
}
}
+void KReversiScene::toggleDemoMode( bool toggle )
+{
+ m_demoMode = toggle;
+ // 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
+}
+
void KReversiScene::slotMoveFinished()
{
m_changedChips = m_game->changedChips();
@@ -135,6 +144,12 @@
{
if( m_game->isComputersTurn() )
{
+ // FIXME dimsuz: somehow fix undo in this case!
+ // it seems that after undoing of two consequent computer
+ // moves, the player can't move anymore, because m_curPlayer in m_game is \
set to wrong player + // check if this is true and fix
+ // The same situation may also apply for two consequent player moves + \
undo + // check it too
if(m_game->isAnyComputerMovePossible())
m_game->makeComputerMove();
// else we'll just do nothing and wait for
@@ -150,6 +165,12 @@
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
@@ -257,7 +278,7 @@
kDebug() << "Cell (" << row << "," << col << ") clicked." << endl;
- m_game->makePlayerMove( row, col );
+ m_game->makePlayerMove( row, col, false );
}
#include "kreversiscene.moc"
--- branches/work/kreversi_rewrite/kreversiscene.h #575066:575067
@@ -40,6 +40,10 @@
* during, for example animation of computer move)
*/
bool isBusy() const;
+ /**
+ * @return whether the scene is in demo-mode
+ */
+ bool demoModeToggled() const { return m_demoMode; }
public slots:
void updateBoard();
void slotMoveFinished();
@@ -48,6 +52,14 @@
* Shows hint for player
*/
void slotHint();
+ /**
+ * Sets Demo Mode.
+ * In this mode KReversiScene would not wait for user
+ * clicks to produce his turn. It will let computer
+ * play for user
+ * @see m_demoMode
+ */
+ void toggleDemoMode(bool toggle);
signals:
void gameOver();
private:
@@ -58,7 +70,7 @@
virtual void drawBackground( QPainter *p, const QRectF& rect );
virtual void mousePressEvent( QGraphicsSceneMouseEvent* );
/**
- * Checks if players can move and if they can:
+ * 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)
@@ -106,5 +118,9 @@
* Used to animate corresponding chips.
*/
MoveList m_changedChips;
+ /**
+ * Specifies whether computer should play human moves
+ */
+ bool m_demoMode;
};
#endif
--- branches/work/kreversi_rewrite/kreversiui.rc #575066:575067
@@ -5,6 +5,7 @@
<Menu name="game"><text>&Game</text>
<Action name="new_game" />
<Action name="hint" />
+ <Action name="demo" />
<Action name="quit" />
</Menu>
<Menu name="edit"><text>&Edit</text>
@@ -17,7 +18,8 @@
<ToolBar name="mainToolBar"><text>Main Toolbar</text>
<Action name="new_game" />
+ <Action name="undo" />
<Action name="hint" />
- <Action name="undo" />
+ <Action name="demo" />
</ToolBar>
</kpartgui>
--- branches/work/kreversi_rewrite/mainwindow.cpp #575066:575067
@@ -4,6 +4,7 @@
#include "kreversiview.h"
#include <kaction.h>
+#include <ktoggleaction.h>
#include <kapplication.h>
#include <kdebug.h>
#include <kicon.h>
@@ -38,6 +39,10 @@
m_hintAct->setShortcut( Qt::Key_H );
connect( m_hintAct, SIGNAL(triggered(bool)), m_scene, SLOT(slotHint()) );
+ KAction *demoAct = new KToggleAction( KIcon("1rightarrow"), i18n("Demo"), \
actionCollection(), "demo" ); + // FIXME dimsuz: disable undo action in demo mode
+ connect(demoAct, SIGNAL(triggered(bool)), m_scene, SLOT(toggleDemoMode(bool)) );
+
KSelectAction *bkgndAct = new KSelectAction(i18n("Choose background"), \
actionCollection(), "choose_bkgnd");
connect(bkgndAct, SIGNAL(triggered(const QString&)), \
SLOT(slotBackgroundChanged(const QString&)));
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic