Changeset View
Changeset View
Standalone View
Standalone View
kexthighscore_item.h
Show All 30 Lines | |||||
31 | { | 31 | { | ||
32 | 32 | | |||
33 | //----------------------------------------------------------------------------- | 33 | //----------------------------------------------------------------------------- | ||
34 | /** | 34 | /** | ||
35 | * This class defines how to convert and how to display | 35 | * This class defines how to convert and how to display | ||
36 | * a highscore element (such as the score, the date, ...) or a player | 36 | * a highscore element (such as the score, the date, ...) or a player | ||
37 | * info (such as the player name, the best score, ...). | 37 | * info (such as the player name, the best score, ...). | ||
38 | */ | 38 | */ | ||
39 | class KDEGAMES_EXPORT Item | 39 | class Item | ||
40 | { | 40 | { | ||
41 | public: | 41 | public: | ||
42 | /** | 42 | /** | ||
43 | * Possible display format. | 43 | * Possible display format. | ||
44 | * <ul> | 44 | * <ul> | ||
45 | * <li> @p NoFormat : no formatting (default) </li> | 45 | * <li> @p NoFormat : no formatting (default) </li> | ||
46 | * <li> @p OneDecimal : with one decimal (only for Double) </li> | 46 | * <li> @p OneDecimal : with one decimal (only for Double) </li> | ||
47 | * <li> @p Percentage : with one decimal + % (only for Double) </li> | 47 | * <li> @p Percentage : with one decimal + % (only for Double) </li> | ||
▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Line(s) | |||||
163 | * Possible score type. | 163 | * Possible score type. | ||
164 | * @p Won the game has been won. | 164 | * @p Won the game has been won. | ||
165 | * @p Lost the game has been lost or has been aborted. | 165 | * @p Lost the game has been lost or has been aborted. | ||
166 | * @p Draw the game is a draw. | 166 | * @p Draw the game is a draw. | ||
167 | */ | 167 | */ | ||
168 | enum ScoreType { Won = 0, Lost = -1, Draw = -2 }; | 168 | enum ScoreType { Won = 0, Lost = -1, Draw = -2 }; | ||
169 | 169 | | |||
170 | class Score; | 170 | class Score; | ||
171 | KDEGAMES_EXPORT QDataStream &operator <<(QDataStream &stream, const Score &score); | 171 | QDataStream &operator <<(QDataStream &stream, const Score &score); | ||
172 | KDEGAMES_EXPORT QDataStream &operator >>(QDataStream &stream, Score &score); | 172 | QDataStream &operator >>(QDataStream &stream, Score &score); | ||
173 | 173 | | |||
174 | /** | 174 | /** | ||
175 | * This class contains data for a score. You should not inherit from | 175 | * This class contains data for a score. You should not inherit from | ||
176 | * this class but reimplement the methods in Highscores. | 176 | * this class but reimplement the methods in Highscores. | ||
177 | */ | 177 | */ | ||
178 | class KDEGAMES_EXPORT Score | 178 | class Score | ||
179 | { | 179 | { | ||
180 | public: | 180 | public: | ||
181 | Score(ScoreType type = Won); | 181 | Score(ScoreType type = Won); | ||
182 | 182 | | |||
183 | ~Score(); | 183 | ~Score(); | ||
184 | 184 | | |||
185 | /** | 185 | /** | ||
186 | * @return the game type. | 186 | * @return the game type. | ||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | 234 | private: | |||
235 | ScoreType _type; | 235 | ScoreType _type; | ||
236 | QMap<QString, QVariant> _data; | 236 | QMap<QString, QVariant> _data; | ||
237 | 237 | | |||
238 | class ScorePrivate; | 238 | class ScorePrivate; | ||
239 | ScorePrivate *d; | 239 | ScorePrivate *d; | ||
240 | 240 | | |||
241 | friend class MultiplayerScores; | 241 | friend class MultiplayerScores; | ||
242 | 242 | | |||
243 | friend KDEGAMES_EXPORT QDataStream &operator <<(QDataStream &stream, const Score &score); | 243 | friend QDataStream &operator <<(QDataStream &stream, const Score &score); | ||
244 | friend KDEGAMES_EXPORT QDataStream &operator >>(QDataStream &stream, Score &score); | 244 | friend QDataStream &operator >>(QDataStream &stream, Score &score); | ||
245 | }; | 245 | }; | ||
246 | 246 | | |||
247 | class MultiplayerScores; | 247 | class MultiplayerScores; | ||
248 | KDEGAMES_EXPORT QDataStream &operator <<(QDataStream &stream, const MultiplayerScores &score); | 248 | QDataStream &operator <<(QDataStream &stream, const MultiplayerScores &score); | ||
249 | KDEGAMES_EXPORT QDataStream &operator >>(QDataStream &stream, MultiplayerScores &score); | 249 | QDataStream &operator >>(QDataStream &stream, MultiplayerScores &score); | ||
250 | 250 | | |||
251 | /** | 251 | /** | ||
252 | * This class is used to store and show scores for multiplayer games. | 252 | * This class is used to store and show scores for multiplayer games. | ||
253 | * | 253 | * | ||
254 | * Example of use: | 254 | * Example of use: | ||
255 | * Initialize the class: | 255 | * Initialize the class: | ||
256 | * <pre> | 256 | * <pre> | ||
257 | * KExtHighscore::MultiScore ms(2); | 257 | * KExtHighscore::MultiScore ms(2); | ||
258 | * ms.setPlayerName(0, "player 1"); | 258 | * ms.setPlayerName(0, "player 1"); | ||
259 | * ms.setPlayerName(1, "player 2"); | 259 | * ms.setPlayerName(1, "player 2"); | ||
260 | * </pre> | 260 | * </pre> | ||
261 | * At the end of each game, add the score of each players: | 261 | * At the end of each game, add the score of each players: | ||
262 | * <pre> | 262 | * <pre> | ||
263 | * KExtHighscore::Score score(KExtHighscore::Won); | 263 | * KExtHighscore::Score score(KExtHighscore::Won); | ||
264 | * score.setScore(100); | 264 | * score.setScore(100); | ||
265 | * ms.addScore(0, score); | 265 | * ms.addScore(0, score); | ||
266 | * score.setType(KExtHighscore::Lost); | 266 | * score.setType(KExtHighscore::Lost); | ||
267 | * score.setScore(20); | 267 | * score.setScore(20); | ||
268 | * ms.addScore(1, score); | 268 | * ms.addScore(1, score); | ||
269 | * </pre> | 269 | * </pre> | ||
270 | */ | 270 | */ | ||
271 | class KDEGAMES_EXPORT MultiplayerScores | 271 | class MultiplayerScores | ||
272 | { | 272 | { | ||
273 | public: | 273 | public: | ||
274 | MultiplayerScores(); | 274 | MultiplayerScores(); | ||
275 | 275 | | |||
276 | ~MultiplayerScores(); | 276 | ~MultiplayerScores(); | ||
277 | 277 | | |||
278 | /** | 278 | /** | ||
279 | * Set the number of players and clear the scores. | 279 | * Set the number of players and clear the scores. | ||
Show All 22 Lines | |||||
302 | 302 | | |||
303 | private: | 303 | private: | ||
304 | QVector<uint> _nbGames; | 304 | QVector<uint> _nbGames; | ||
305 | QVector<Score> _scores; | 305 | QVector<Score> _scores; | ||
306 | 306 | | |||
307 | class MultiplayerScoresPrivate; | 307 | class MultiplayerScoresPrivate; | ||
308 | MultiplayerScoresPrivate *d; | 308 | MultiplayerScoresPrivate *d; | ||
309 | 309 | | |||
310 | friend KDEGAMES_EXPORT QDataStream &operator <<(QDataStream &stream, | 310 | friend QDataStream &operator <<(QDataStream &stream, | ||
311 | const MultiplayerScores &score); | 311 | const MultiplayerScores &score); | ||
312 | friend KDEGAMES_EXPORT QDataStream &operator >>(QDataStream &stream, | 312 | friend QDataStream &operator >>(QDataStream &stream, | ||
313 | MultiplayerScores &score); | 313 | MultiplayerScores &score); | ||
314 | }; | 314 | }; | ||
315 | 315 | | |||
316 | } // namespace | 316 | } // namespace | ||
317 | 317 | | |||
318 | #endif | 318 | #endif |