File indexing completed on 2024-09-15 03:43:54
0001 /* 0002 This file is part of the KDE games kwin4 program 0003 SPDX-FileCopyrightText: 1995-2007 Martin Heni <kde@heni-online.de> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef KWIN4_PLAYER_H 0009 #define KWIN4_PLAYER_H 0010 0011 // own 0012 #include "score.h" 0013 // KF 0014 #include <KConfigGroup> 0015 // KDEGames 0016 #define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API 0017 #include <libkdegamesprivate/kgame/kgameproperty.h> 0018 #include <libkdegamesprivate/kgame/kplayer.h> 0019 0020 /** 0021 * A player for the KWin4 game. A player holds all important player data, 0022 * in particular the long time status and score information. Additionally, 0023 * via the KGame framework it supports various methods of input like mouse, 0024 * keyboard, AI or even network. 0025 */ 0026 class KWin4Player : public KPlayer 0027 { 0028 Q_OBJECT 0029 0030 public: 0031 /** 0032 * Construct a player object,. 0033 */ 0034 KWin4Player(); 0035 ~KWin4Player() override; 0036 0037 /** 0038 * Runtime identification for the player type (KGame). Only one player 0039 * _type_ for kwin4. 0040 * @return The player type = 1. 0041 */ 0042 int rtti() const override 0043 { 0044 return 1; 0045 } 0046 0047 /** 0048 * Assign the score object which allows to display player properties in 0049 * the GUI. 0050 * @param s The score object 0051 */ 0052 void setStatus(Score *s) 0053 { 0054 mStatus = s; 0055 } 0056 0057 /** 0058 * Retrieve the score object from the player. 0059 * @return The score object. 0060 */ 0061 Score *status() 0062 { 0063 return mStatus; 0064 } 0065 0066 /** 0067 * Read the player data (status, score) from the configuration file. 0068 * @param config The configuration group 0069 */ 0070 void readConfig(KConfigGroup &config); 0071 0072 /** 0073 * Write the player data (status, score) to the configuration file. 0074 * @param config The configuration group 0075 */ 0076 void writeConfig(KConfigGroup &config); 0077 0078 /** 0079 * Increase the number of wins for this player. 0080 */ 0081 void incWin(); 0082 0083 /** 0084 * Increase the number of draws for this player. 0085 */ 0086 void incRemis(); 0087 0088 /** 0089 * Increase the number of losses for this player. 0090 */ 0091 void incLost(); 0092 0093 /** 0094 * Increase the number of aborted games for this player. 0095 */ 0096 void incBrk(); 0097 0098 /** 0099 * Retrieve the number of wins. 0100 */ 0101 int win() 0102 { 0103 return mAllWin.value(); 0104 } 0105 0106 /** 0107 * Retrieve the number of losses. 0108 */ 0109 int lost() 0110 { 0111 return mAllLost.value(); 0112 } 0113 0114 /** 0115 * Retrieve the number of aborted games. 0116 */ 0117 int brk() 0118 { 0119 return mAllBrk.value(); 0120 } 0121 0122 /** 0123 * Retrieve the number of drawn games. 0124 */ 0125 int remis() 0126 { 0127 return mAllRemis.value(); 0128 } 0129 0130 /** 0131 * Clear the score of the player. 0132 * @param all True: Clear also long time score. False: Clear only session score. 0133 */ 0134 void resetStats(bool all = true); 0135 0136 protected Q_SLOTS: 0137 /** 0138 * KGame method which is called when any KGamePropery changes for this 0139 * player. 0140 * @param prop The property 0141 * @param player This player 0142 */ 0143 void slotPlayerPropertyChanged(KGamePropertyBase *prop, KPlayer *player); 0144 0145 private: 0146 // One session wins 0147 KGamePropertyInt mWin; 0148 0149 // One session draws 0150 KGamePropertyInt mRemis; 0151 0152 // One session losses 0153 KGamePropertyInt mLost; 0154 0155 // One session aborted games 0156 KGamePropertyInt mBrk; 0157 0158 // All time wins 0159 KGamePropertyInt mAllWin; 0160 0161 // All time draws 0162 KGamePropertyInt mAllRemis; 0163 0164 // All time losses 0165 KGamePropertyInt mAllLost; 0166 0167 // All time aborted games 0168 KGamePropertyInt mAllBrk; 0169 0170 // Status object: Connects player to GUI widget 0171 Score *mStatus; 0172 }; 0173 0174 #endif // KWIN4_PLAYER_H