File indexing completed on 2024-03-24 04:07:36
0001 /* 0002 SPDX-FileCopyrightText: 2006 Matthew Williams <matt@milliams.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KSQUARESPLAYER_H 0008 #define KSQUARESPLAYER_H 0009 0010 #include <QColor> 0011 0012 /** 0013 * @short Player class for KSquares 0014 * 0015 * Class containing All the information about a player. 0016 * 0017 * @author Matt Williams <matt@milliams.com> 0018 */ 0019 0020 class KSquaresPlayer 0021 { 0022 public: 0023 /** 0024 * Creates a player 0025 * 0026 * @param newName The displayable name of the player 0027 * @param newColor the colour used to fill the player's boxes 0028 * @param isPlayerHuman is the player human (or AI) 0029 */ 0030 explicit KSquaresPlayer(const QString &newName, const QColor &newColor, bool isPlayerHuman = true) 0031 { 0032 setName(newName); //defaults to human player 0033 playerColour = newColor; 0034 human = isPlayerHuman; 0035 playerScore = 0; 0036 } 0037 0038 ///Create a null player 0039 KSquaresPlayer() = 0040 default; // Needed to do QList<KSquaresPlayer>::operator[int i] since 0041 // it has to allocate memory i think 0042 0043 /** 0044 * Sets the players name 0045 * 0046 * @param newName The displayable name of the player 0047 */ 0048 void setName(const QString &newName) 0049 { 0050 playerName = newName; 0051 } 0052 0053 /** 0054 * Sets the players name 0055 * 0056 * @return The displayable name of the player 0057 */ 0058 QString name() const 0059 { 0060 return playerName; 0061 } 0062 0063 /** 0064 * Sets the players score 0065 * 0066 * @param newScore The players new score 0067 */ 0068 void setScore(int newScore) 0069 { 0070 playerScore = newScore; 0071 } 0072 /** 0073 * @return The players current score 0074 */ 0075 int score() const 0076 { 0077 return playerScore; 0078 } 0079 ///Increase the players score by 1 0080 void incScore() 0081 { 0082 playerScore++; 0083 } 0084 0085 /** 0086 * @return Is the player human 0087 */ 0088 bool isHuman() const 0089 { 0090 return human; 0091 } 0092 0093 /** 0094 * @return the player's chosen display colour 0095 */ 0096 QColor colour() const 0097 { 0098 return playerColour; 0099 } 0100 0101 /** 0102 * @return the player's signature (1 or 2 letters) 0103 */ 0104 QString sig() const 0105 { 0106 return displaySig; 0107 } 0108 0109 /** 0110 * Used in sort algorithm. Compares the player's score (not their height or age or anything :D) 0111 * @param player the player to compare wth this one 0112 * @return true if player is bigger than this 0113 */ 0114 bool operator<(const KSquaresPlayer &player) const 0115 { 0116 return score() < player.score(); 0117 } 0118 bool operator>(const KSquaresPlayer &player) const 0119 { 0120 return score() > player.score(); 0121 } 0122 0123 protected: 0124 /// Is the player a human 0125 bool human; 0126 /// Player's current score 0127 int playerScore; 0128 /// The player's displayable name 0129 QString playerName; 0130 ///Player's display colour 0131 QColor playerColour; 0132 ///Letter (or two) to display on the board 0133 QString displaySig; 0134 }; 0135 0136 #endif // KSQUARESPLAYER_H