[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 10:10:14
Message-ID: 1157623814.637796.8154.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 581722 by dimsuz:
Initial highscores support (adapted from old sources)
M +2 -1 CMakeLists.txt
M +28 -31 highscores.cpp
M +6 -14 highscores.h
M +2 -0 kreversigame.h
M +1 -0 kreversiui.rc
M +23 -20 main.cpp
M +34 -2 mainwindow.cpp
M +1 -0 mainwindow.h
--- branches/work/kreversi_rewrite/CMakeLists.txt #581721:581722
@@ -12,6 +12,7 @@
kreversiscene.cpp
kreversiview.cpp
Engine.cpp
+ highscores.cpp
mainwindow.cpp
main.cpp )
@@ -21,7 +22,7 @@
kde4_add_executable(kreversi ${kreversi_SRCS})
-target_link_libraries(kreversi ${KDE4_KDEUI_LIBS})
+target_link_libraries(kreversi ${KDE4_KDEUI_LIBS} kdegames)
install(TARGETS kreversi DESTINATION ${BIN_INSTALL_DIR} )
--- branches/work/kreversi_rewrite/highscores.cpp #581721:581722
@@ -22,7 +22,6 @@
#include <klocale.h>
#include <kconfig.h>
#include <kapplication.h>
-//Added by qt3to4:
#include <QVector>
#include <QDateTime>
#include <kglobal.h>
@@ -31,53 +30,50 @@
namespace KExtHighscore
{
-const ExtManager::Data ExtManager::DATA[SuperEngine::NbStrengths] = {
- { I18N_NOOP("1 (Beginner)"), "beginner" },
- { I18N_NOOP("2"), 0 },
- { I18N_NOOP("3"), 0 },
- { I18N_NOOP("4 (Average)"), "average" },
- { I18N_NOOP("5"), 0 },
- { I18N_NOOP("6"), 0 },
- { I18N_NOOP("7 (Expert)"), "expert" }
-};
-
-
ExtManager::ExtManager()
- : Manager(SuperEngine::NbStrengths)
+ : Manager(7)
{
- setShowStatistics(true);
- setShowDrawGamesStatistic(true);
+ setShowStatistics(true);
+ setShowDrawGamesStatistic(true);
- const uint RANGE[6] = { 0, 32, 40, 48, 56, 64 };
- QVector<uint> s;
- s.resize(6);
- qCopy(RANGE, RANGE + 6, s.begin());
- //s.duplicate(RANGE, 6);
- setScoreHistogram(s, ScoreBound);
+ const uint RANGE[6] = { 0, 32, 40, 48, 56, 64 };
+ QVector<uint> s;
+ s.resize(6);
+ qCopy(RANGE, RANGE + 6, s.begin());
+ setScoreHistogram(s, ScoreBound);
+
+ // FIXME dimsuz: somehow rearrange the code to be sure that this and in \
mainwindow.cpp are + // always in sync
+ m_typeLabels << i18n("Very easy") << i18n("Easy") << i18n("Normal");
+ m_typeLabels << i18n("Hard") << i18n("Very Hard") << i18n("Unbeatable") << \
i18n("Champion"); }
QString ExtManager::gameTypeLabel(uint gameType, LabelType type) const
{
- const Data &data = DATA[gameType];
- switch (type) {
- case Icon: return data.icon;
- case Standard: return QString::number(gameType);
- case I18N: return i18n(data.label);
- case WW: break;
- }
+ switch (type) {
+ case Standard:
+ return QString::number(gameType);
+ case I18N:
+ return m_typeLabels.at(gameType);
+ case Icon:
+ // FIXME dimsuz: implement
+ break;
+ case WW:
+ break;
+ }
- return QString::null;
+ return QString::null;
}
+// FIXME dimsuz: is this still needed?
+/*
void ExtManager::convertLegacy(uint gameType)
{
// Since there is no information about the skill level
// in the legacy highscore list, consider they are
// for beginner skill ...
- qDebug("convert legacy %i", gameType);
-
if ( gameType!=0 )
return;
@@ -105,6 +101,7 @@
submitLegacyScore(s);
}
}
+ */
} // Namespace
--- branches/work/kreversi_rewrite/highscores.h #581721:581722
@@ -20,29 +20,21 @@
#ifndef HIGHSCORES_H
#define HIGHSCORES_H
-
#include <kexthighscore.h>
#include <kdemacros.h>
-#include "SuperEngine.h"
+#include <QStringList>
-
namespace KExtHighscore
{
class KDE_EXPORT ExtManager : public Manager
{
- public:
- ExtManager();
+public:
+ ExtManager();
- private:
- QString gameTypeLabel(uint gameTye, LabelType) const;
- void convertLegacy(uint gameType);
-
- struct Data {
- const char *label;
- const char *icon;
- };
- static const Data DATA[SuperEngine::NbStrengths];
+private:
+ virtual QString gameTypeLabel(uint gameTye, LabelType) const;
+ QStringList m_typeLabels;
};
}
--- branches/work/kreversi_rewrite/kreversigame.h #581721:581722
@@ -40,6 +40,8 @@
* - 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 game is over it'll emit gameOver()
*
* 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()
--- branches/work/kreversi_rewrite/kreversiui.rc #581721:581722
@@ -6,6 +6,7 @@
<Action name="new_game" />
<Action name="hint" />
<Action name="demo" />
+ <Action name="game_highscores" />
<Action name="quit" />
</Menu>
<Menu name="view"><text>&View</text>
--- branches/work/kreversi_rewrite/main.cpp #581721:581722
@@ -2,7 +2,7 @@
*
* Copyright 2006 Dmitry Suzdalev <dimsuz@gmail.com>
*
- * This file is part of the KDE project "KREVERSI"
+ * This file is part of the KDE project "KReversi"
*
* KREVERSI is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -28,6 +28,7 @@
#include <kaboutdata.h>
#include <klocale.h>
+#include "highscores.h"
#include "mainwindow.h"
#include "version.h"
@@ -35,27 +36,29 @@
int main(int argc, char **argv)
{
- KAboutData aboutData( "kreversi", I18N_NOOP("KReversi"),
- KREVERSI_VERSION, description, KAboutData::License_GPL,
- "(c) 1997-2000, Mario Weilguni\n(c) 2006, Dmitry Suzdalev");
- aboutData.addAuthor("Mario Weilguni",I18N_NOOP("Original author"), \
"mweilguni@sime.com");
- aboutData.addAuthor("Dmitry Suzdalev", I18N_NOOP("Game rewrite for KDE4. Current \
maintainer."), "dimsuz@gmail.com");
- aboutData.addCredit("Mats Luthman", I18N_NOOP("Game engine, ported from his JAVA \
applet."), 0);
- aboutData.addCredit("Arne Klaassen", I18N_NOOP("Raytraced chips."), 0);
+ KAboutData aboutData( "kreversi", I18N_NOOP("KReversi"),
+ KREVERSI_VERSION, description, KAboutData::License_GPL,
+ "(c) 1997-2000, Mario Weilguni\n(c) 2006, Dmitry Suzdalev");
+ aboutData.addAuthor("Mario Weilguni",I18N_NOOP("Original author"), \
"mweilguni@sime.com"); + aboutData.addAuthor("Dmitry Suzdalev", I18N_NOOP("Game \
rewrite for KDE4. Current maintainer."), "dimsuz@gmail.com"); + \
aboutData.addCredit("Mats Luthman", I18N_NOOP("Game engine, ported from his JAVA \
applet."), 0); + aboutData.addCredit("Arne Klaassen", I18N_NOOP("Raytraced \
chips."), 0);
- KCmdLineArgs::init( argc, argv, &aboutData );
+ KCmdLineArgs::init( argc, argv, &aboutData );
- KApplication application;
- if( application.isSessionRestored() )
- {
- RESTORE(KReversiMainWindow)
- }
- else
- {
- KReversiMainWindow *mainWin = new KReversiMainWindow;
- mainWin->show();
- }
+ KApplication application;
+ if( application.isSessionRestored() )
+ {
+ RESTORE(KReversiMainWindow)
+ }
+ else
+ {
+ KReversiMainWindow *mainWin = new KReversiMainWindow;
+ mainWin->show();
+ }
- return application.exec();
+ KExtHighscore::ExtManager highscoresManager;
+
+ return application.exec();
}
--- branches/work/kreversi_rewrite/mainwindow.cpp #581721:581722
@@ -8,12 +8,14 @@
#include <ktoggleaction.h>
#include <kapplication.h>
#include <kdebug.h>
+#include <kexthighscore.h>
#include <kicon.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kstandarddirs.h>
#include <kstatusbar.h>
#include <kstdaction.h>
+#include <kstdgameaction.h>
#include <kselectaction.h>
#include <QGraphicsView>
@@ -69,6 +71,7 @@
m_historyLabel->hide();
m_historyView->hide();
+
setupActions();
loadSettings();
@@ -122,7 +125,7 @@
// FIXME dimsuz: this utilises 5 skills. although 7 is possible
// also give them good names
acts << i18n("Very easy") << i18n("Easy") << i18n("Normal");
- acts << i18n("Hard") << i18n("Beatable") << i18n("Unbeatable");
+ acts << i18n("Hard") << i18n("Very Hard") << i18n("Unbeatable") << \
i18n("Champion"); m_skillAct->setItems(acts);
connect(m_skillAct, SIGNAL(triggered(int)), SLOT(slotSkillChanged(int)) );
@@ -133,6 +136,8 @@
KToggleAction *showMovesAct = new KToggleAction( i18n("Show moves history"), \
actionCollection(), "show_moves" );
connect( showMovesAct, SIGNAL(triggered(bool)), SLOT(slotShowMovesHistory(bool)) \
);
+ KStdGameAction::highscores(this, SLOT(slotHighScores()), actionCollection());
+
addAction(newGameAct);
addAction(quitAct);
addAction(m_undoAct);
@@ -252,13 +257,35 @@
int blackScore = m_game->playerScore(Black);
int whiteScore = m_game->playerScore(White);
- QString res = blackScore > whiteScore ? i18n("You win!") : i18n("You have \
lost!"); +
+ // FIXME dimsuz: use lowest skill that was during ONE game
+ KExtHighscore::setGameType( Preferences::skill()-1 );
+ KExtHighscore::Score score;
+ score.setScore(blackScore);
+
+ QString res;
if( blackScore == whiteScore )
+ {
res = i18n("Game is drawn!");
+ score.setType( KExtHighscore::Draw );
+ }
+ else if( blackScore > whiteScore )
+ {
+ res = i18n("You win!");
+ score.setType( KExtHighscore::Won );
+ }
+ else
+ {
+ res = i18n("You have lost!");
+ score.setType( KExtHighscore::Lost );
+ }
+
res += i18n("\nYou: %1", blackScore);
res += i18n("\nComputer: %1", whiteScore);
KMessageBox::information( this, res, i18n("Game over") );
+ // FIXME dimsuz: don't submit if in demo mode!
+ KExtHighscore::submitScore(score, this);
}
void KReversiMainWindow::slotMoveFinished()
@@ -305,4 +332,9 @@
}
}
+void KReversiMainWindow::slotHighscores()
+{
+ KExtHighscore::show(this);
+}
+
#include "mainwindow.moc"
--- branches/work/kreversi_rewrite/mainwindow.h #581721:581722
@@ -29,6 +29,7 @@
void slotUseColoredChips(bool);
void slotShowMovesHistory(bool);
void slotComputerCantMove();
+ void slotHighscores();
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