Commit 5bc0bb54 authored by Dmitry Suzdalev's avatar Dmitry Suzdalev

Initial highscores support (adapted from old sources)

svn path=/branches/work/kreversi_rewrite/; revision=581722
parent 958ad41d
......@@ -12,6 +12,7 @@ set(kreversi_SRCS
kreversiscene.cpp
kreversiview.cpp
Engine.cpp
highscores.cpp
mainwindow.cpp
main.cpp )
......@@ -21,7 +22,7 @@ kde4_add_kcfg_files(kreversi_SRCS preferences.kcfgc)
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} )
......
......@@ -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);
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);
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());
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;
}
return QString::null;
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;
}
// 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 @@ void ExtManager::convertLegacy(uint gameType)
submitLegacyScore(s);
}
}
*/
} // Namespace
......@@ -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();
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];
public:
ExtManager();
private:
virtual QString gameTypeLabel(uint gameTye, LabelType) const;
QStringList m_typeLabels;
};
}
......
......@@ -40,6 +40,8 @@ public:
* - 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()
......
......@@ -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>&amp;View</text>
......
......@@ -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 @@ static const char description[] = I18N_NOOP("KDE Reversi Board Game");
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);
KCmdLineArgs::init( argc, argv, &aboutData );
KApplication application;
if( application.isSessionRestored() )
{
RESTORE(KReversiMainWindow)
}
else
{
KReversiMainWindow *mainWin = new KReversiMainWindow;
mainWin->show();
}
return application.exec();
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 );
KApplication application;
if( application.isSessionRestored() )
{
RESTORE(KReversiMainWindow)
}
else
{
KReversiMainWindow *mainWin = new KReversiMainWindow;
mainWin->show();
}
KExtHighscore::ExtManager highscoresManager;
return application.exec();
}
......@@ -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 @@ KReversiMainWindow::KReversiMainWindow(QWidget* parent)
m_historyLabel->hide();
m_historyView->hide();
setupActions();
loadSettings();
......@@ -122,7 +125,7 @@ void KReversiMainWindow::setupActions()
// 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 @@ void KReversiMainWindow::setupActions()
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 @@ void KReversiMainWindow::slotGameOver()
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::slotUndo()
}
}
void KReversiMainWindow::slotHighscores()
{
KExtHighscore::show(this);
}
#include "mainwindow.moc"
......@@ -29,6 +29,7 @@ public slots:
void slotUseColoredChips(bool);
void slotShowMovesHistory(bool);
void slotComputerCantMove();
void slotHighscores();
private:
void setupActions();
void loadSettings();
......
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