Commit 72d3b82f authored by Dmitry Suzdalev's avatar Dmitry Suzdalev
Browse files

Now black&white chips may be used instead of colored ones.

You can even change this on the fly! ;)

Few crash fixes also.

You know what? It's getting near the end.
(Just joking - there's no end in software development ;) )

I'm in the mood of writing an overview of what to be done:

- Add number of chips statistics to status bar
- Add the moves history widget.
- Nice messagebox with stats at the end of the game
- HighScores

svn path=/branches/work/kreversi_rewrite/; revision=581275
parent 53e859b8
......@@ -32,5 +32,9 @@
<label>Background image name</label>
<default>Light_Wood</default>
</entry>
<entry name="UseColoredChips" type="Bool">
<label>Whether to use colored chips instead of black and white ones.</label>
<default>true</default>
</entry>
</group>
</kcfg>
......@@ -14,8 +14,8 @@
const int CHIP_SIZE = 36;
KReversiScene::KReversiScene( KReversiGame* game , const QPixmap& chipsPixmap )
: m_hintChip(0), m_lastMoveChip(0), m_timerDelay(25), m_showingHint(false), m_demoMode(false),
m_showLastMove(false), m_showPossibleMoves(false)
: m_game(0), m_frameSet(0), m_hintChip(0), m_lastMoveChip(0), m_timerDelay(25),
m_showingHint(false), m_demoMode(false), m_showLastMove(false), m_showPossibleMoves(false)
{
setBackgroundBrush( Qt::lightGray );
......@@ -27,13 +27,37 @@ KReversiScene::KReversiScene( KReversiGame* game , const QPixmap& chipsPixmap )
setSceneRect( 0, 0, m_boardRect.width()+2*fontHeight, m_boardRect.height()+2*fontHeight);
m_frameSet = new KReversiChipFrameSet( chipsPixmap, CHIP_SIZE );
setChipsPixmap(chipsPixmap);
m_animTimer = new QTimer(this);
connect(m_animTimer, SIGNAL(timeout()), SLOT(slotAnimationStep()));
setGame(game);
}
KReversiScene::~KReversiScene()
{
delete m_frameSet;
}
void KReversiScene::setChipsPixmap( const QPixmap& chipsPixmap )
{
delete m_frameSet;
m_frameSet = new KReversiChipFrameSet( chipsPixmap, CHIP_SIZE );
if(m_game)
{
QList<QGraphicsItem*> allItems = items( m_boardRect );
KReversiChip *chip = 0;
foreach( QGraphicsItem* item, allItems )
{
// FIXME dimsuz: use qgraphicsitem_cast?
chip = dynamic_cast<KReversiChip*>(item);
if( chip )
chip->setColor( chip->color() ); // this will reread pixmap
}
}
}
void KReversiScene::setGame( KReversiGame* game )
{
m_game = game;
......@@ -48,6 +72,14 @@ void KReversiScene::setGame( KReversiGame* game )
delete chip;
}
m_possibleMovesItems.clear();
m_animTimer->stop();
m_hintChip = 0; // it was deleted above if it was shown
m_showingHint = false;
m_lastMoveChip = 0;
m_demoMode = false;
updateBoard();
}
......
......@@ -30,8 +30,11 @@ public:
* @param chipsPixmap the pixmap with animation frames
*/
KReversiScene( KReversiGame* game, const QPixmap& chipsPixmap );
~KReversiScene();
void setGame( KReversiGame* game );
void setBackgroundPixmap( const QPixmap& pix );
void setChipsPixmap( const QPixmap& chipsPixmap );
/**
* This function will tell you if the scene is currently performing
* some kind of "better-don't-interrupt-me" operation.
......
......@@ -15,6 +15,7 @@
<Action name="choose_bkgnd" />
<Action name="anim_speed" />
<Action name="skill" />
<Action name="use_colored_chips" />
</Menu>
</MenuBar>
......
......@@ -84,6 +84,9 @@ void KReversiMainWindow::setupActions()
m_skillAct->setItems(acts);
connect(m_skillAct, SIGNAL(triggered(int)), SLOT(slotSkillChanged(int)) );
m_coloredChipsAct = new KToggleAction( i18n("Use colored chips"), actionCollection(), "use_colored_chips" );
connect( m_coloredChipsAct, SIGNAL(triggered(bool)), SLOT(slotUseColoredChips(bool)) );
addAction(newGameAct);
addAction(quitAct);
addAction(m_undoAct);
......@@ -102,6 +105,9 @@ void KReversiMainWindow::loadSettings()
m_animSpeedAct->setCurrentItem( Preferences::animationSpeed() );
slotAnimSpeedChanged( Preferences::animationSpeed() );
m_coloredChipsAct->setChecked( Preferences::useColoredChips() );
slotUseColoredChips( Preferences::useColoredChips() );
}
void KReversiMainWindow::slotBackgroundChanged( const QString& text )
......@@ -137,6 +143,14 @@ void KReversiMainWindow::slotAnimSpeedChanged(int speed)
Preferences::writeConfig();
}
void KReversiMainWindow::slotUseColoredChips(bool toggled)
{
QString chipsPngPath = m_coloredChipsAct->isChecked() ? "pics/chips.png" : "pics/chips_mono.png";
m_scene->setChipsPixmap( KStandardDirs::locate("appdata", chipsPngPath) );
Preferences::setUseColoredChips(toggled);
Preferences::writeConfig();
}
void KReversiMainWindow::slotDemoMode(bool toggled)
{
kDebug() << k_funcinfo << endl;
......
......@@ -8,6 +8,7 @@ class KReversiGame;
class KReversiView;
class KAction;
class KSelectAction;
class KToggleAction;
class KReversiMainWindow : public KMainWindow
{
......@@ -23,6 +24,7 @@ public slots:
void slotMoveFinished();
void slotGameOver();
void slotDemoMode(bool);
void slotUseColoredChips(bool);
private:
void setupActions();
void loadSettings();
......@@ -37,5 +39,6 @@ private:
KSelectAction* m_animSpeedAct;
KSelectAction* m_bkgndAct;
KSelectAction* m_skillAct;
KToggleAction* m_coloredChipsAct;
};
#endif
......@@ -4,4 +4,4 @@ File=kreversi.kcfg
ClassName=Preferences
Singleton=true
CustomAdditions=false
Mutators=Skill,BackgroundImageName,AnimationSpeed
Mutators=Skill,BackgroundImageName,AnimationSpeed,UseColoredChips
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment