mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2024-12-25 21:59:30 +01:00
Stats: display end game points for a free game
This commit is contained in:
parent
b53295c782
commit
c700f39ac7
8 changed files with 49 additions and 17 deletions
|
@ -163,6 +163,13 @@ void History::addSoloPoints(int iPoints)
|
|||
}
|
||||
|
||||
|
||||
void History::addEndGamePoints(int iPoints)
|
||||
{
|
||||
ASSERT(m_history.size() > 1, "Too short history");
|
||||
m_history[m_history.size() - 2]->addEndGamePoints(iPoints);
|
||||
}
|
||||
|
||||
|
||||
wstring History::toString() const
|
||||
{
|
||||
wstring rs;
|
||||
|
|
|
@ -96,6 +96,8 @@ public:
|
|||
|
||||
void addSoloPoints(int iPoints);
|
||||
|
||||
void addEndGamePoints(int iPoints);
|
||||
|
||||
/// String handling
|
||||
wstring toString() const;
|
||||
|
||||
|
|
|
@ -127,9 +127,20 @@ int Player::getSoloPoints() const
|
|||
}
|
||||
|
||||
|
||||
int Player::getEndGamePoints() const
|
||||
{
|
||||
int total = 0;
|
||||
for (unsigned i = 0; i < m_history.getSize(); ++i)
|
||||
{
|
||||
total += m_history.getTurn(i).getEndGamePoints();
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
|
||||
int Player::getTotalScore() const
|
||||
{
|
||||
return getPoints() + getSoloPoints() + getPenaltyPoints();
|
||||
return m_score + getSoloPoints() + getPenaltyPoints() + getEndGamePoints();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -91,6 +91,9 @@ public:
|
|||
/// Return the total number of solo points received
|
||||
int getSoloPoints() const;
|
||||
|
||||
/// Return the total number of end game points
|
||||
int getEndGamePoints() const;
|
||||
|
||||
/// Return the total score of the player, including solos and penalties
|
||||
int getTotalScore() const;
|
||||
|
||||
|
@ -100,7 +103,7 @@ public:
|
|||
// Add (or remove, if iPoints is negative) points to the score
|
||||
// of the player
|
||||
void addPoints(int iPoints) { m_score += iPoints; }
|
||||
int getPoints() const { return m_score; }
|
||||
int getPoints() const { return getTotalScore(); }
|
||||
|
||||
wstring toString() const;
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ void PlayerEventCmd::doExecute()
|
|||
else if (m_eventType == SOLO)
|
||||
m_player.accessHistory().addSoloPoints(m_points);
|
||||
else if (m_eventType == END_GAME)
|
||||
m_player.addPoints(m_points);
|
||||
m_player.accessHistory().addEndGamePoints(m_points);
|
||||
else
|
||||
ASSERT(false, "Missing case");
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ void PlayerEventCmd::doUndo()
|
|||
else if (m_eventType == SOLO)
|
||||
m_player.accessHistory().addSoloPoints(- m_points);
|
||||
else if (m_eventType == END_GAME)
|
||||
m_player.addPoints(- m_points);
|
||||
m_player.accessHistory().addEndGamePoints(- m_points);
|
||||
else
|
||||
ASSERT(false, "Missing case");
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ INIT_LOGGER(game, Turn);
|
|||
// constructor completely
|
||||
Turn::Turn()
|
||||
: m_playerId(0), m_warningsNb(0),
|
||||
m_penaltyPoints(0), m_soloPoints(0)
|
||||
m_penaltyPoints(0), m_soloPoints(0), m_endGamePoints(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ Turn::Turn()
|
|||
Turn::Turn(unsigned int iPlayerId, const PlayedRack& iPldRack,
|
||||
const Move& iMove)
|
||||
: m_playerId(iPlayerId), m_pldrack(iPldRack), m_move(iMove),
|
||||
m_warningsNb(0), m_penaltyPoints(0), m_soloPoints(0)
|
||||
m_warningsNb(0), m_penaltyPoints(0), m_soloPoints(0), m_endGamePoints(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -48,18 +48,20 @@ public:
|
|||
void setPlayer(unsigned int iPlayerId) { m_playerId = iPlayerId; }
|
||||
void setPlayedRack(const PlayedRack& iPldRack) { m_pldrack = iPldRack; }
|
||||
void setMove(const Move& iMove) { m_move = iMove; }
|
||||
// Setters for warnings, penalties and solos
|
||||
// Setters for events (warnings, penalties, solos, end game primes)
|
||||
void addWarning(unsigned iNb = 1) { m_warningsNb += iNb; }
|
||||
void addPenaltyPoints(int iPoints) { m_penaltyPoints += iPoints; }
|
||||
void addSoloPoints(int iPoints) { m_soloPoints += iPoints; }
|
||||
void addEndGamePoints(int iPoints) { m_endGamePoints += iPoints; }
|
||||
|
||||
unsigned int getPlayer() const { return m_playerId; }
|
||||
const PlayedRack& getPlayedRack() const { return m_pldrack; }
|
||||
const Move& getMove() const { return m_move; }
|
||||
// Getters for warnings, penalties and solos
|
||||
// Getters for events (warnings, penalties, solos, end game primes)
|
||||
unsigned getWarningsNb() const { return m_warningsNb; }
|
||||
int getPenaltyPoints() const { return m_penaltyPoints; }
|
||||
int getSoloPoints() const { return m_soloPoints; }
|
||||
int getEndGamePoints() const { return m_endGamePoints; }
|
||||
|
||||
wstring toString() const;
|
||||
|
||||
|
@ -70,6 +72,7 @@ private:
|
|||
int m_warningsNb;
|
||||
int m_penaltyPoints;
|
||||
int m_soloPoints;
|
||||
int m_endGamePoints;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -90,11 +90,13 @@ void StatsWidget::refresh()
|
|||
unsigned histSize = m_game == NULL ? 0 : m_game->getHistory().getSize();
|
||||
unsigned nbPlayers = m_game == NULL ? 0 : m_game->getNbPlayers();
|
||||
|
||||
setModelSize(nbPlayers + 1, histSize + 9);
|
||||
setModelSize(nbPlayers + 1, histSize + 10);
|
||||
|
||||
// Some fields are displayed only in some cases
|
||||
const bool isArbit = m_game != NULL &&
|
||||
m_game->getParams().getMode() == GameParams::kARBITRATION;
|
||||
const bool isFreeGame = m_game != NULL &&
|
||||
m_game->getParams().getMode() == GameParams::kFREEGAME;
|
||||
const bool canHaveSolos = m_game != NULL &&
|
||||
m_game->getParams().getMode() == GameParams::kDUPLICATE &&
|
||||
Settings::Instance().getInt("duplicate.solo-players") <= (int)m_game->getNbPlayers();
|
||||
|
@ -107,8 +109,10 @@ void StatsWidget::refresh()
|
|||
for (unsigned i = 1; i <= histSize; ++i)
|
||||
setModelHeader(col++, QString("#%1").arg(i), false);
|
||||
|
||||
setSectionHidden(col, !isArbit && !canHaveSolos);
|
||||
setSectionHidden(col, !isArbit && !canHaveSolos && !isFreeGame);
|
||||
setModelHeader(col++, _q("Sub-total"), false);
|
||||
setSectionHidden(col, !isFreeGame);
|
||||
setModelHeader(col++, _q("End game points"), false);
|
||||
setSectionHidden(col, !isArbit && !canHaveSolos);
|
||||
setModelHeader(col++, _q("Solo points"), false);
|
||||
setSectionHidden(col, !isArbit);
|
||||
|
@ -145,7 +149,7 @@ void StatsWidget::refresh()
|
|||
}
|
||||
setModelText(getIndex(row, col++), score, true);
|
||||
// Skip the events columns
|
||||
col += 3;
|
||||
col += 4;
|
||||
setModelText(getIndex(row, col++), score, true);
|
||||
// Skip the diff column
|
||||
++col;
|
||||
|
@ -180,15 +184,15 @@ void StatsWidget::refresh()
|
|||
setModelText(getIndex(i + 1, col++), score, score >= gameTotal);
|
||||
|
||||
// Events columns
|
||||
for (int j = 0; j <= 2; ++j)
|
||||
for (int j = 0; j <= 3; ++j)
|
||||
{
|
||||
setModelEventData(getIndex(i + 1, col++), j, player);
|
||||
}
|
||||
|
||||
// Final score
|
||||
score += player.getSoloPoints() + player.getPenaltyPoints();
|
||||
score += player.getSoloPoints() + player.getPenaltyPoints() + player.getEndGamePoints();
|
||||
setModelText(getIndex(i + 1, col++), score, score >= gameTotal);
|
||||
//ASSERT(score == player.getTotalScore(), "Invalid score computation");
|
||||
ASSERT(score == player.getTotalScore(), "Invalid score computation");
|
||||
|
||||
// Diff with game total
|
||||
setModelText(getIndex(i + 1, col++), score - gameTotal);
|
||||
|
@ -302,11 +306,13 @@ void StatsWidget::setModelEventData(const QModelIndex &iIndex,
|
|||
int iEvent, const Player &iPlayer)
|
||||
{
|
||||
QVariant text;
|
||||
if (iEvent == 0 && iPlayer.getSoloPoints() != 0)
|
||||
if (iEvent == 0 && iPlayer.getEndGamePoints() != 0)
|
||||
text = iPlayer.getEndGamePoints();
|
||||
else if (iEvent == 1 && iPlayer.getSoloPoints() != 0)
|
||||
text = iPlayer.getSoloPoints();
|
||||
else if (iEvent == 1 && iPlayer.getPenaltyPoints() != 0)
|
||||
else if (iEvent == 2 && iPlayer.getPenaltyPoints() != 0)
|
||||
text = iPlayer.getPenaltyPoints();
|
||||
else if (iEvent == 2 && iPlayer.getWarningsNb() != 0)
|
||||
else if (iEvent == 3 && iPlayer.getWarningsNb() != 0)
|
||||
text = iPlayer.getWarningsNb();
|
||||
setModelText(iIndex, text);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue