[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 10:36:55
Message-ID: 1157366215.251587.3215.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 580711 by dimsuz:
- Add ability to visually mark last made move
- Reanimate KConfigXt-based configuration. Fix some related FIXMEs
M +2 -0 CMakeLists.txt
M +5 -38 kreversi.kcfg
M +15 -0 kreversichip.cpp
M +5 -0 kreversichip.h
M +10 -5 kreversigame.cpp
M +20 -20 kreversigame.h
M +36 -10 kreversiscene.cpp
M +27 -10 kreversiscene.h
M +2 -0 kreversiui.rc
M +8 -3 mainwindow.cpp
A preferences.kcfgc
--- branches/work/kreversi_rewrite/CMakeLists.txt #580710:580711
@@ -17,6 +17,8 @@
kde4_automoc(${kreversi_SRCS})
+kde4_add_kcfg_files(kreversi_SRCS preferences.kcfgc)
+
kde4_add_executable(kreversi ${kreversi_SRCS})
target_link_libraries(kreversi ${KDE4_KDEUI_LIBS})
--- branches/work/kreversi_rewrite/kreversi.kcfg #580710:580711
@@ -3,37 +3,17 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
- <include>kstandarddirs.h</include>
- <include>kglobal.h</include>
<kcfgfile name="kreversirc"/>
<group name="Game">
<entry name="Grayscale" type="Bool">
<label>Whether to use a grayscale board instead of colored.</label>
<default>false</default>
</entry>
- <entry name="HumanColor" type="Int">
- <label>The human color.</label>
- <default>1</default>
- </entry>
- <entry name="ComputerColor" type="Int">
- <label>The computer color.</label>
- <default>0</default>
- </entry>
- <entry name="Animation" type="Bool">
- <label>Whether to use animations.</label>
- <default>true</default>
- </entry>
<entry name="AnimationSpeed" type="Int">
<label>The speed of the animations.</label>
- <default>4</default>
- <min>1</min>
- <max>10</max>
- </entry>
- <entry name="Zoom" type="Int">
- <label>The zoom factor of the board.</label>
- <default>100</default>
+ <default>25</default>
<min>10</min>
- <max>300</max>
+ <max>40</max>
</entry>
<entry name="CompetitiveGameChoice" type="Bool">
<label>Whether to play competitively in contrast to casually.</label>
@@ -45,22 +25,9 @@
<min>1</min>
<max>7</max>
</entry>
- <entry name="BackgroundImageChoice" type="Bool">
- <label>Whether to use a background image.</label>
- <default>true</default>
+ <entry name="backgroundImageName" type="String">
+ <label>Background image name</label>
+ <default>Light_Wood</default>
</entry>
- <entry name="BackgroundColor" type="Color">
- <label>The background color to use.</label>
- <default>#ffffff</default>
- </entry>
- <entry name="BackgroundImage" type="Path">
- <label>Image to use as background.</label>
- <code>#define PICDATA(x) KGlobal::dirs()->findResource("appdata", \
QString("pics/")+ x)</code>
- <default code="true">PICDATA("background/Light_Wood.png")</default>
- </entry>
- <entry name="MenubarVisible" type="Bool" key="menubar visible">
- <label>Whether the menubar is visible.</label>
- <default>true</default>
- </entry>
</group>
</kcfg>
--- branches/work/kreversi_rewrite/kreversichip.cpp #580710:580711
@@ -25,6 +25,21 @@
return finished;
}
+void KReversiChip::showLastMoveMarker(bool show)
+{
+ if(show)
+ {
+ QPixmap pix = pixmap();
+ QPainter p(&pix);
+ p.setBrush(Qt::black);
+ p.drawEllipse( 3*pix.width()/8, 3*pix.height()/8, pix.width()/4, \
pix.height()/4); + p.end();
+ setPixmap(pix);
+ }
+ else
+ setPixmap( m_frameSet->chipPixmap( m_color ) );
+}
+
// -------------------------------------------------------------------------------
KReversiChipFrameSet::KReversiChipFrameSet( const QPixmap& allFrames, int frameSize \
)
--- branches/work/kreversi_rewrite/kreversichip.h #580710:580711
@@ -20,6 +20,11 @@
* @return whether the animation sequence is finished
*/
bool nextFrame();
+ /**
+ * Toggles showing of little marker on top of the chip.
+ * It is used to indicate last-made move
+ */
+ void showLastMoveMarker(bool show);
private:
ChipColor m_color;
const KReversiChipFrameSet* m_frameSet;
--- branches/work/kreversi_rewrite/kreversigame.cpp #580710:580711
@@ -396,11 +396,6 @@
return false;
}
-const KReversiBoard& KReversiGame::board() const
-{
- return *m_board;
-}
-
bool KReversiGame::isGameOver() const
{
// trivial fast-check
@@ -446,6 +441,16 @@
return m_engine->computeMove( *this, true );
}
+KReversiMove KReversiGame::getLastMove() const
+{
+ // we'll take this move from changed list
+ if( m_changedChips.isEmpty() )
+ return KReversiMove(NoColor, -1, -1); // invalid one
+
+ // first item in this list is the actual move, rest is turned chips
+ return m_changedChips.first();
+}
+
int KReversiGame::playerScore( ChipColor player ) const
{
return m_board->playerScore( player );
--- branches/work/kreversi_rewrite/kreversigame.h #580710:580711
@@ -36,6 +36,22 @@
KReversiGame();
~KReversiGame();
/**
+ * 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, bool demoMode);
+ /**
+ * This function will make computer decide where he
+ * wants to put his chip... and he'll put it there!
+ */
+ void makeComputerMove();
+ /**
+ * Undoes all the computer moves and one player move
+ */
+ void undo();
+ /**
* Sets the strength of game engine (1 to 7)
*/
void setEngineStrength(uint strength);
@@ -56,10 +72,6 @@
*/
bool isAnyComputerMovePossible() const;
/**
- * @return the board so the callers can examine its current state
- */
- const KReversiBoard& board() const;
- /**
* @return a color of the current player
*/
ChipColor currentPlayer() const { return m_curPlayer; }
@@ -74,22 +86,6 @@
// NOTE: this is just a wrapper around KReversiBoard::playerScore
ChipColor chipColorAt( int row, int col ) const;
/**
- * 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, bool demoMode);
- /**
- * This function will make computer decide where he
- * wants to put his chip... and he'll put it there!
- */
- void makeComputerMove();
- /**
- * Undoes all the computer moves and one player move
- */
- void undo();
- /**
* @return if undo is possible
*/
bool canUndo() const { return !m_undoStack.isEmpty(); }
@@ -98,6 +94,10 @@
*/
KReversiMove getHint() const;
/**
+ * @return last move made
+ */
+ KReversiMove getLastMove() const;
+ /**
* Returns true, if it's computer's turn now
*/
bool isComputersTurn() const { return m_curPlayer == m_computerColor; }
--- branches/work/kreversi_rewrite/kreversiscene.cpp #580710:580711
@@ -14,7 +14,8 @@
const int CHIP_SIZE = 36;
KReversiScene::KReversiScene( KReversiGame* game , const QPixmap& chipsPixmap )
- : m_showingHint(false), m_hintChip(0), m_demoMode(false)
+ : m_hintChip(0), m_lastMoveChip(0), m_showingHint(false), m_demoMode(false),
+ m_showLastMove(false)
{
setBackgroundBrush( Qt::lightGray );
@@ -32,7 +33,7 @@
{
m_game = game;
connect( m_game, SIGNAL(boardChanged()), this, SLOT(updateBoard()) );
- connect( m_game, SIGNAL(moveFinished()), this, SLOT(slotMoveFinished()) );
+ connect( m_game, SIGNAL(moveFinished()), this, SLOT(slotGameMoveFinished()) );
// this will remove all items left from previous game
QList<QGraphicsItem*> allChips = items( m_boardRect );
@@ -45,6 +46,12 @@
updateBoard();
}
+void KReversiScene::setShowLastMove( bool show )
+{
+ m_showLastMove = show;
+ displayLastAndPossibleMoves();
+}
+
bool KReversiScene::isBusy() const
{
return m_animTimer->isActive();
@@ -82,6 +89,7 @@
delete itemAt( cellCenter(row, col) );
}
}
+ m_lastMoveChip = 0;
}
void KReversiScene::toggleDemoMode( bool toggle )
@@ -93,7 +101,7 @@
beginNextTurn(); // it will take m_demoMode into account
}
-void KReversiScene::slotMoveFinished()
+void KReversiScene::slotGameMoveFinished()
{
m_changedChips = m_game->changedChips();
// create an item that was placed by player
@@ -102,6 +110,8 @@
KReversiChip *newchip = new KReversiChip( move.color, m_frameSet, this );
newchip->setPos( cellTopLeft( move.row, move.col ) );
// start animation
+ if( m_lastMoveChip )
+ m_lastMoveChip->showLastMoveMarker( false );
m_animTimer->start(10);
}
@@ -111,7 +121,7 @@
{ // we're animating chips move
KReversiMove move = m_changedChips.at(0);
- KReversiChip *chip = static_cast<KReversiChip*>(itemAt( cellCenter(move.row, \
move.col) )); + KReversiChip *chip = dynamic_cast<KReversiChip*>(itemAt( \
cellCenter(move.row, move.col) ));
bool animFinished = chip->nextFrame();
if(animFinished)
@@ -126,6 +136,8 @@
m_animTimer->stop();
emit moveFinished();
+ displayLastAndPossibleMoves();
+
// some better name maybe?
beginNextTurn();
}
@@ -144,12 +156,6 @@
{
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();
@@ -192,6 +198,26 @@
}
}
+void KReversiScene::displayLastAndPossibleMoves()
+{
+ // ==== Show What Last Move Was ====
+ if( m_showLastMove )
+ {
+ KReversiMove lastPos = m_game->getLastMove();
+ m_lastMoveChip = dynamic_cast<KReversiChip*>(itemAt(cellCenter(lastPos.row, \
lastPos.col))); + if(m_lastMoveChip)
+ m_lastMoveChip->showLastMoveMarker(true);
+ }
+ else
+ {
+ if(m_lastMoveChip)
+ m_lastMoveChip->showLastMoveMarker(false);
+ }
+
+ // ==== Show Possible Moves ====
+ // TODO
+}
+
void KReversiScene::slotHint()
{
if( m_game->isComputersTurn() )
--- branches/work/kreversi_rewrite/kreversiscene.h #580710:580711
@@ -44,12 +44,16 @@
/**
* @return whether the scene is in demo-mode
*/
- bool demoModeToggled() const { return m_demoMode; }
+ bool isDemoModeToggled() const { return m_demoMode; }
public slots:
void updateBoard();
- void slotMoveFinished();
+ void slotGameMoveFinished();
void slotAnimationStep();
/**
+ * This will make scene visually mark the last made move
+ */
+ void setShowLastMove( bool show );
+ /**
* Shows hint for player
*/
void slotHint();
@@ -82,6 +86,11 @@
*/
void beginNextTurn();
/**
+ * Visually displays last move and possible moves
+ * (if the scene is set up to show them)
+ */
+ void displayLastAndPossibleMoves();
+ /**
* Returns the center point of cell (row,col)
*/
QPointF cellCenter( int row, int col ) const;
@@ -106,26 +115,34 @@
*/
KReversiChipFrameSet *m_frameSet;
/**
+ * This list will hold a changed chips
+ * after each turn. It is received from the game object.
+ * Used to animate corresponding chips.
+ */
+ MoveList m_changedChips;
+ /**
* Animation timer
*/
QTimer* m_animTimer;
/**
- * Holds true if the scene is showing hint to the player
- */
- bool m_showingHint;
- /**
* This is our "hint-chip" - used to show hints
*/
KReversiChip* m_hintChip;
/**
- * This list will hold a changed chips
- * after each turn. It is received from the game object.
- * Used to animate corresponding chips.
+ * This will hold a pointer to chip which has "last-move" mark
*/
- MoveList m_changedChips;
+ KReversiChip* m_lastMoveChip;
/**
+ * Holds true if the scene is showing hint to the player
+ */
+ bool m_showingHint;
+ /**
* Specifies whether computer should play human moves
*/
bool m_demoMode;
+ /**
+ * If true, then last made turn will be shown to the player
+ */
+ bool m_showLastMove;
};
#endif
--- branches/work/kreversi_rewrite/kreversiui.rc #580710:580711
@@ -21,5 +21,7 @@
<Action name="undo" />
<Action name="hint" />
<Action name="demo" />
+ <Separator />
+ <Action name="show_last_move" />
</ToolBar>
</kpartgui>
--- branches/work/kreversi_rewrite/mainwindow.cpp #580710:580711
@@ -2,6 +2,7 @@
#include "kreversigame.h"
#include "kreversiscene.h"
#include "kreversiview.h"
+#include "preferences.h"
#include <kaction.h>
#include <ktoggleaction.h>
@@ -61,10 +62,12 @@
}
- // FIXME dimsuz: this should come from KConfig!
- bkgndAct->setCurrentAction( "Hexagon" );
- slotBackgroundChanged("Hexagon");
+ 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)) ); +
addAction(newGameAct);
addAction(quitAct);
addAction(m_undoAct);
@@ -85,6 +88,8 @@
m_view->resetCachedContent();
m_scene->setBackgroundPixmap( pix );
}
+ Preferences::setBackgroundImageName( text );
+ Preferences::writeConfig();
}
void KReversiMainWindow::slotDemoMode(bool toggled)
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic