Commit fc38c705 authored by Denis Kuplyakov's avatar Denis Kuplyakov

Now Highscores are stored.

Implemented highscores. Also added some missing i18n.
parent 54369da3
......@@ -67,4 +67,9 @@ void KReversiComputerPlayer::setSkill(int skill)
m_lowestSkill = qMin(m_lowestSkill, skill);
}
int KReversiComputerPlayer::lowestSkill()
{
return m_lowestSkill;
}
......@@ -48,6 +48,11 @@ public:
*/
void setSkill(int skill);
/**
* @return lowest skill that has been set
*/
int lowestSkill();
signals:
public slots:
......
......@@ -123,7 +123,7 @@ void KReversiMainWindow::setupActionsInit()
{
// Common actions
KStandardGameAction::gameNew(this, SLOT(slotNewGame()), actionCollection());
// KStandardGameAction::highscores(this, SLOT(slotHighscores()), actionCollection());
KStandardGameAction::highscores(this, SLOT(slotHighscores()), actionCollection());
KStandardGameAction::quit(this, SLOT(close()), actionCollection());
// Undo
......@@ -246,9 +246,6 @@ void KReversiMainWindow::slotNewGame()
// m_demoAct->setIcon(KIcon(QLatin1String("media-playback-start")));
// }
// if (m_undoAct)
// m_undoAct->setEnabled(false);
m_startDialog->exec();
}
......@@ -260,58 +257,57 @@ void KReversiMainWindow::slotGameOver()
int blackScore = m_game->playerScore(Black);
int whiteScore = m_game->playerScore(White);
// KExtHighscore::setGameType(m_lowestSkill);
// KExtHighscore::Score score;
// score.setScore(blackScore);
bool storeScore = false;
KExtHighscore::Score score;
QString res;
if (m_nowPlayingInfo.type[Black] == GameStartInformation::Human
&& m_nowPlayingInfo.type[White] == GameStartInformation::AI) { // we are playing black
storeScore = true;
KExtHighscore::setGameType(((KReversiComputerPlayer *)m_player[White])->lowestSkill());
score.setScore(blackScore);
if (blackScore == whiteScore) {
res = i18n("Game is drawn!");
//score.setType(KExtHighscore::Draw);
score.setType(KExtHighscore::Draw);
} else if (blackScore > whiteScore) {
res = i18n("You win!");
//score.setType(KExtHighscore::Won);
score.setType(KExtHighscore::Won);
} else {
res = i18n("You have lost!");
//score.setType(KExtHighscore::Lost);
score.setType(KExtHighscore::Lost);
}
} else if (m_nowPlayingInfo.type[White] == GameStartInformation::Human
&& m_nowPlayingInfo.type[Black] == GameStartInformation::AI) { // we are playing white
if (blackScore == whiteScore) {
storeScore = true;
KExtHighscore::setGameType(((KReversiComputerPlayer *)m_player[Black])->lowestSkill());
score.setScore(whiteScore);
if (blackScore == whiteScore) {
res = i18n("Game is drawn!");
//score.setType(KExtHighscore::Draw);
} else if (blackScore < whiteScore) {
score.setType(KExtHighscore::Draw);
} else if (blackScore < whiteScore) {
res = i18n("You win!");
//score.setType(KExtHighscore::Won);
} else {
score.setType(KExtHighscore::Won);
} else {
res = i18n("You have lost!");
//score.setType(KExtHighscore::Lost);
}
score.setType(KExtHighscore::Lost);
}
} else if (m_nowPlayingInfo.type[Black] == GameStartInformation::Human
&& m_nowPlayingInfo.type[White] == GameStartInformation::Human) { // friends match
if (blackScore == whiteScore) {
if (blackScore == whiteScore) {
res = i18n("Game is drawn!");
//score.setType(KExtHighscore::Draw);
} else if (blackScore > whiteScore) {
} else if (blackScore > whiteScore) {
res = i18n("%1 has won!", m_nowPlayingInfo.name[Black]);
//score.setType(KExtHighscore::Won);
} else {
} else {
res = i18n("%1 has won!", m_nowPlayingInfo.name[White]);
//score.setType(KExtHighscore::Lost);
}
}
} else { // using Black White names in other cases
if (blackScore == whiteScore) {
res = i18n("Game is drawn!");
//score.setType(KExtHighscore::Draw);
} else if (blackScore > whiteScore) {
res = i18n("Black has won!");
//score.setType(KExtHighscore::Won);
} else {
res = i18n("White has won!");
//score.setType(KExtHighscore::Lost);
}
}
......@@ -324,11 +320,10 @@ void KReversiMainWindow::slotGameOver()
res += i18n("\n%1: %2", m_nowPlayingInfo.name[White], whiteScore);
}
KMessageBox::information(this, res, i18n("Game over"));
// // FIXME dimsuz: don't submit if in demo mode!
// KExtHighscore::submitScore(score, this);
if (storeScore)
KExtHighscore::submitScore(score, this);
}
void KReversiMainWindow::slotMoveFinished()
......@@ -368,7 +363,7 @@ void KReversiMainWindow::slotUndo()
void KReversiMainWindow::slotHighscores()
{
// KExtHighscore::show(this);
KExtHighscore::show(this);
}
void KReversiMainWindow::slotDialogReady()
......
......@@ -18,10 +18,10 @@ StartGameDialog::StartGameDialog(QWidget *parent, KgThemeProvider *provider) :
setFixedSize(width(), height());
setButtons(Ok | Close);
setButtonText(Ok, "Start game");
setButtonToolTip(Ok, "Let's start playing!");
setButtonText(Close, "Quit");
setButtonToolTip(Close, "Quit KReversi");
setButtonText(Ok, i18n("Start game"));
setButtonToolTip(Ok, i18n("Let's start playing!"));
setButtonText(Close, i18n("Quit"));
setButtonToolTip(Close, i18n("Quit KReversi"));
m_contents = new QWidget(this);
setMainWidget(m_contents);
......@@ -118,7 +118,7 @@ void StartGameDialog::slotUpdateBlack(int clickedId)
if (clickedId == GameStartInformation::Human)
ui->blackName->setText(m_user.loginName());
else
ui->blackName->setText("Computer");
ui->blackName->setText(i18n("Computer"));
}
void StartGameDialog::slotUpdateWhite(int clickedId)
......@@ -128,5 +128,5 @@ void StartGameDialog::slotUpdateWhite(int clickedId)
if (clickedId == GameStartInformation::Human)
ui->whiteName->setText(m_user.loginName());
else
ui->whiteName->setText("Computer");
ui->whiteName->setText(i18n("Computer"));
}
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