File indexing completed on 2023-10-01 08:05:25
0001 /* 0002 This file is part of the KDE games lskat program 0003 SPDX-FileCopyrightText: 2006 Martin Heni <kde@heni-online.de> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef PLAYER_H 0009 #define PLAYER_H 0010 0011 // Qt includes 0012 #include <QObject> 0013 #include <QVector> 0014 0015 // KF includes 0016 #include <KConfig> 0017 0018 // Local includes 0019 #include "lskat_debug.h" 0020 #include "deck.h" 0021 0022 // Forward declaration 0023 class AbstractInput; 0024 0025 using namespace CardDeck; 0026 0027 /** 0028 * A player of the game. 0029 */ 0030 class Player : public QObject 0031 { 0032 Q_OBJECT 0033 0034 public: 0035 /** 0036 * Constructor for the player 0037 * @param id The player number 0038 * @param parent The parent object 0039 */ 0040 explicit Player(int id, QObject *parent = nullptr); 0041 0042 /** 0043 * Destructor 0044 */ 0045 ~Player() override; 0046 0047 /** 0048 * Retrieve the player number. 0049 * @return The id. 0050 */ 0051 int id() {return mId;} 0052 0053 /** 0054 * Retrieve card value at given logical position 0055 * @param playerNumber (0..max number of cards of player) 0056 * @return Card number 0057 */ 0058 int getCard(int playerNumber); 0059 0060 /** 0061 * Remove a card from the given position. Typically if the 0062 * card was played. 0063 * @param cardPosition (0..max number of cards of player) 0064 */ 0065 void deleteCard(int cardPosition); 0066 0067 /** 0068 * Add a card to the given position. Typically if the 0069 * card was played back. 0070 * @param cardPosition (0..max number of cards of player) 0071 * @param card The actual card 0072 */ 0073 void addCard(int cardPosition, int card); 0074 0075 /** 0076 * Set this player to start a turn 0077 */ 0078 void startTurn(); 0079 0080 /** 0081 * Set this player to stop a turn 0082 */ 0083 void stopTurn(); 0084 0085 /** 0086 * Deal a number of cards to this player 0087 * @param amount The amount of cards 0088 */ 0089 void deal(int amount); 0090 0091 /** 0092 * Increases the number of moves by one for this player. 0093 * @param amount Increase by this amount (default 1) 0094 */ 0095 void increaseMovesWon(int amount = 1); 0096 0097 /** 0098 * Retrieve the number of won moves for this player. 0099 * @return The amount of won moves for this player. 0100 */ 0101 int noOfMovesWon(); 0102 0103 /** 0104 * Adds a card which is one in a move to this player. 0105 * Also increase this players point by the points of the card. Note, this 0106 * method has to be called with both cards of a move! 0107 * @param card The card to store 0108 */ 0109 void addWonCard(int card); 0110 0111 /** 0112 * Retrieve a card won by this player. 0113 * @param no The number of the card. Can be 0..2*noOfMovesWon(). 0114 * @return The card. 0115 */ 0116 int getWonCard(int no); 0117 0118 /** 0119 * Retrieve the amount of points this player has. 0120 * @return The amount of points (0-120). 0121 */ 0122 int points(); 0123 0124 /** 0125 * Set the points of the player. 0126 * Emits the signal signalUpdatePoints(int) 0127 * @param points The points. 0128 */ 0129 void setPoints(int points); 0130 0131 /** 0132 * Retrieve the name of the player. 0133 * @return The player's name. 0134 */ 0135 QString name(); 0136 0137 /** 0138 * Set the name of the player. 0139 * Emits the signal signalUpdateName(int) 0140 * @param name The new name. 0141 */ 0142 void setName(const QString &name); 0143 0144 /** 0145 * Add a number of won games to the overall player statistic. 0146 * @param amount The amount of won games 0147 */ 0148 void addWonGame(int amount); 0149 0150 /** 0151 * Retrieve the number of won games. 0152 * @return The number of games won. 0153 */ 0154 int wonGames(); 0155 0156 /** 0157 * Add a number of games to the overall player statistic. 0158 * @param amount The amount of games 0159 */ 0160 void addGame(int amount); 0161 0162 /** 0163 * Retrieve the number of games. 0164 * @return The overall number of games. 0165 */ 0166 int games(); 0167 0168 /** 0169 * Add a score to the overall player statistic. 0170 * @param amount The score amount 0171 */ 0172 void addScore(int amount); 0173 0174 /** 0175 * Retrieve the overall score. 0176 * @return The score. 0177 */ 0178 int score(); 0179 0180 /** 0181 * Retrieve the input device of the player 0182 * @return The input device. 0183 */ 0184 AbstractInput *input(); 0185 0186 /** 0187 * Set the input for this player. 0188 * @param input The input device. 0189 */ 0190 void setInput(AbstractInput *input); 0191 0192 /** 0193 * Set the deck for drawing cards. 0194 * @param deck The deck 0195 */ 0196 void setDeck(Deck *deck); 0197 0198 /** 0199 * Refresh GUI by emitting a signal. 0200 */ 0201 void refresh(); 0202 0203 /** 0204 * Clear the all time statistics of this player. 0205 */ 0206 void clear(); 0207 0208 /** 0209 * Set the trump to the player 0210 * @param trump The trump suite 0211 */ 0212 void setTrump(Suite trump); 0213 0214 /** 0215 * Retrieve the trump. 0216 * @return The trump suite. 0217 */ 0218 Suite trump(); 0219 0220 /** 0221 * Saves the properties 0222 * @param config The config group object. 0223 */ 0224 void save(KConfigGroup &config); 0225 0226 /** 0227 * Read properties. 0228 * @param config The config group object. 0229 */ 0230 void load(KConfigGroup &config); 0231 0232 Q_SIGNALS: 0233 /** 0234 * Notify change of player data. 0235 * @param p This player 0236 */ 0237 void signalUpdate(Player *p); 0238 0239 private: 0240 // Players input device 0241 AbstractInput *mInput; 0242 // Card deck 0243 Deck *mDeck; 0244 // Our cards 0245 QVector<int> mCards; 0246 // Our won cards 0247 QList<int> mWonCards; 0248 // Our points 0249 int mPoints; 0250 // Our id 0251 int mId; 0252 // Number of moves won in the current game 0253 int mMovesWon; 0254 // The current trump 0255 Suite mTrump; 0256 0257 // These attributes need to be saved 0258 // Our name 0259 QString mName; 0260 // Overall games won for this player 0261 int mGamesWon; 0262 // Overall score for this player 0263 int mScore; 0264 // Overall number of games for this player 0265 int mNumberOfGames; 0266 }; 0267 0268 #endif