예제 #1
0
void KBattleshipWindow::slotHighscore()
{
	KScoreDialog *scoreDialog = new KScoreDialog(KScoreDialog::Name | KScoreDialog::Score | KScoreDialog::Custom1 | KScoreDialog::Custom2 | KScoreDialog::Custom3, this);
	scoreDialog->addField(KScoreDialog::Custom1, i18n("Shots"), "shots");
	scoreDialog->addField(KScoreDialog::Custom2, i18n("Hits"), "hits");
	scoreDialog->addField(KScoreDialog::Custom3, i18n("Water"), "water");
	scoreDialog->show();
}
예제 #2
0
void Kolf::showHighScores()
{
	KScoreDialog *scoreDialog = new KScoreDialog(KScoreDialog::Name | KScoreDialog::Custom1 | KScoreDialog::Score, this);
	scoreDialog->addField(KScoreDialog::Custom1, i18n("Par"), "Par");

	CourseInfo courseInfo;
	game->courseInfo(courseInfo, game->curFilename());

	scoreDialog->setConfigGroup(courseInfo.untranslatedName + QString(" Highscores"));
	scoreDialog->setComment(i18n("High Scores for %1").arg(courseInfo.name));
	scoreDialog->show();
}
예제 #3
0
void KBattleshipWindow::slotUpdateHighscore()
{
	// Balancing factors
	// a = shot-balance
	// b = water-balance
	double a = 3;
	double b = 0.5;
	double score = (a * m_stat->hit() - b * m_stat->water()) / (m_stat->shot() + m_stat->water()) * 1000;
	if(score == 0) score = 1;
	
	KScoreDialog *scoreDialog = new KScoreDialog(KScoreDialog::Name | KScoreDialog::Score | KScoreDialog::Custom1 | KScoreDialog::Custom2 | KScoreDialog::Custom3, this);
	scoreDialog->addField(KScoreDialog::Custom1, i18n("Shots"), "shots");
	scoreDialog->addField(KScoreDialog::Custom2, i18n("Hits"), "hits");
	scoreDialog->addField(KScoreDialog::Custom3, i18n("Water"), "water");

	KScoreDialog::FieldInfo info;
	info[KScoreDialog::Name] = m_ownNickname;
	info[KScoreDialog::Custom1] = QString::number(m_stat->shot());
	info[KScoreDialog::Custom2] = QString::number(m_stat->hit());
	info[KScoreDialog::Custom3] = QString::number(m_stat->water());

	scoreDialog->addScore((int)score, info, false, false);
}
예제 #4
0
void PlayField::gameOver(Sea::Player winner)
{
    if (winner == Sea::Player(0)) {
        const Stats* stats = m_menu->player(0)->stats();
       
        if (stats && qobject_cast<const AIEntity*>(m_menu->player(1))) {
            KScoreDialog* highscoredialog = new KScoreDialog(
                    KScoreDialog::Name | KScoreDialog::Score | 
                    KScoreDialog::Custom1 | 
                    KScoreDialog::Custom2 | 
                    KScoreDialog::Custom3, 
                    this);
            highscoredialog->initFromDifficulty(Kg::difficulty());
            highscoredialog->addField(KScoreDialog::Custom1, i18n("Shots"), "shots");
            highscoredialog->addField(KScoreDialog::Custom2, i18n("Hits"), "hits");
            highscoredialog->addField(KScoreDialog::Custom3, i18n("Misses"), "water");
        
            KScoreDialog::FieldInfo info;
            info[KScoreDialog::Name] = m_menu->player(0)->nick();
            info[KScoreDialog::Score].setNum(stats->score());
            info[KScoreDialog::Custom1] = QString::number(stats->shots());
            info[KScoreDialog::Custom2] = QString::number(stats->hits());
            info[KScoreDialog::Custom3] = QString::number(stats->misses());
        
            int temp = highscoredialog->addScore(info, KScoreDialog::AskName);
            qDebug() << "temp =" << temp;
            //if (highscoredialog->addScore(info, KScoreDialog::AskName)) {
            if (temp != 0) {
                highscoredialog->exec();
                return;
            }
        }
        
        m_status_bar->showMessage(i18n("You win!"));
        if (m_show_endofgame_message) {
            KMessageBox::information(this, i18n("You win. Excellent!"));
        }
    }
    else {
        m_status_bar->showMessage(i18n("You lose."));
        if (m_show_endofgame_message) {
            KMessageBox::information(this, i18n("You lose. Better luck next time!"));
        }
    }
    
    // When we have finished, show again the welcome screen
    emit gameFinished();
}
예제 #5
0
void PlayField::highscores()
{
    KScoreDialog* highscoredialog = new KScoreDialog(
            KScoreDialog::Name | KScoreDialog::Score | 
            KScoreDialog::Custom1 | 
            KScoreDialog::Custom2 | 
            KScoreDialog::Custom3, 
            this);
    highscoredialog->initFromDifficulty(Kg::difficulty());
    highscoredialog->addField(KScoreDialog::Custom1, i18n("Shots"), "shots");
    highscoredialog->addField(KScoreDialog::Custom2, i18n("Hits"), "hits");
    highscoredialog->addField(KScoreDialog::Custom3, i18n("Misses"), "water");
    
    highscoredialog->exec();
}
예제 #6
0
void Kolf::gameOver()
{
	int curPar = 0;
	int lowScore = INT_MAX; // let's hope it doesn't stay this way!
	int curScore = 1;

	// names of people who had the lowest score
	QStringList names;

	HighScoreList highScores;
	int scoreBoardIndex = 1;

	while (curScore != 0)
	{
		QString curName;

		// name taken as a reference and filled out
		curScore = scoreboard->total(scoreBoardIndex, curName);

		scoreBoardIndex++;

		if (curName == i18n("Par"))
		{
			curPar = curScore;
			continue;
		}

		if (curScore == 0)
			continue;

		// attempt to add everybody to the highscore list
		// (ignored if we aren't competing down below)
		highScores.append(HighScore(curName, curScore));

		if (curScore < lowScore)
		{
			names.clear();
			lowScore = curScore;
			names.append(curName);
		}
		else if (curScore == lowScore)
			names.append(curName);
	}

	// only announce a winner if more than two entries
	// (player and par) are on the scoreboard + one to go past end
	// + 1 for koodoo
	if (scoreBoardIndex > 4)
	{
		if (names.count() > 1)
		{
			QString winners = names.join(i18n(" and "));
			KMessageBox::information(this, i18n("%1 tied").arg(winners));
		}
		else
			KMessageBox::information(this, i18n("%1 won!").arg(names.first()));
	}

	if (competition)
	{
		// deal with highscores
		// KScoreDialog makes it very easy :-))

		KScoreDialog *scoreDialog = new KScoreDialog(KScoreDialog::Name | KScoreDialog::Custom1 | KScoreDialog::Score, this);
		scoreDialog->addField(KScoreDialog::Custom1, i18n("Par"), "Par");

		CourseInfo courseInfo;
		game->courseInfo(courseInfo, game->curFilename());

		scoreDialog->setConfigGroup(courseInfo.untranslatedName + QString(" Highscores"));

		for (HighScoreList::Iterator it = highScores.begin(); it != highScores.end(); ++it)
		{
			KScoreDialog::FieldInfo info;
			info[KScoreDialog::Name] = (*it).name;
			info[KScoreDialog::Custom1] = QString::number(curPar);

			scoreDialog->addScore((*it).score, info, false, true);
		}

		scoreDialog->setComment(i18n("High Scores for %1").arg(courseInfo.name));
		scoreDialog->show();
	}

	QTimer::singleShot(700, this, SLOT(closeGame()));
}