File indexing completed on 2024-12-08 03:47:25
0001 /* 0002 SPDX-FileCopyrightText: 2013 Denis Kuplyakov <dener.kup@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KREVERSI_PLAYER_H 0008 #define KREVERSI_PLAYER_H 0009 0010 #include "kreversigame.h" 0011 #include <QString> 0012 0013 class KReversiGame; 0014 0015 /** 0016 * Indicates current state of the player 0017 */ 0018 enum KReversiPlayerState { 0019 /** Player is waiting for his move or smth else */ 0020 WAITING, 0021 /** Player is thinking about his move */ 0022 THINKING, 0023 /** Player state is unknown */ 0024 UNKNOWN 0025 }; 0026 /** 0027 * Represents abstract player. It is interface. 0028 */ 0029 class KReversiPlayer: public QObject 0030 { 0031 Q_OBJECT 0032 public: 0033 /** 0034 * Construct player with specified @p color and @p name. 0035 * @param hintAllowed determines whether hints are allowed for player 0036 * @param undoAllowed determines whether undos are allowed for player 0037 */ 0038 explicit KReversiPlayer(ChipColor color, const QString &name, 0039 bool hintAllowed, bool undoAllowed); 0040 0041 /** 0042 * Used to get player color 0043 * @return color of player 0044 */ 0045 ChipColor getColor() const; 0046 0047 /** 0048 * Used to get player's name 0049 * @return player's name 0050 */ 0051 QString getName() const; 0052 0053 /** 0054 * @return is hint allowed for player or not 0055 */ 0056 bool isHintAllowed() const; 0057 0058 /** 0059 * KReversiGame triggers it to to increase used hints count 0060 */ 0061 void hintUsed(); 0062 0063 /** 0064 * @return how many times player has used hints 0065 */ 0066 int getHintsCount(); 0067 0068 /** 0069 * @return is undo allowed for player 0070 */ 0071 bool isUndoAllowed() const; 0072 0073 /** 0074 * KReversiGame triggers it to to increase used undos count 0075 */ 0076 void undoUsed(); 0077 0078 /** 0079 * @return how many times player has used undo 0080 */ 0081 int getUndoCount(); 0082 0083 public Q_SLOTS: 0084 /** 0085 * Triggered by KReversiGame before game starts 0086 * Implementation should assign @p game to m_game 0087 */ 0088 virtual void prepare(KReversiGame* game) = 0; 0089 0090 /** 0091 * It triggered from KReversiGame. 0092 * Means that player should start think about his move. 0093 */ 0094 virtual void takeTurn() = 0; 0095 0096 /** 0097 * It triggered from KReversiGame. 0098 * Means that player can't do move and skips it. 0099 */ 0100 virtual void skipTurn() = 0; 0101 0102 /** 0103 * Triggered by KReversiGame to notify player that game is over. 0104 */ 0105 virtual void gameOver() = 0; 0106 0107 Q_SIGNALS: 0108 /** 0109 * Player emit it when want to notify about his move 0110 */ 0111 void makeMove(KReversiMove); 0112 0113 /** 0114 * Player emit it after he has prepared after getting prepare command 0115 */ 0116 void ready(); 0117 0118 protected: 0119 /** 0120 * Game which player is playing 0121 */ 0122 KReversiGame *m_game; 0123 0124 /** 0125 * Is player thinking or waiting 0126 */ 0127 KReversiPlayerState m_state; 0128 0129 /** 0130 * Player's chip color 0131 */ 0132 ChipColor m_color; 0133 0134 /** 0135 * Player's name to be shown at UI 0136 */ 0137 QString m_name; 0138 0139 /** 0140 * Are hints enabled for player 0141 */ 0142 bool m_hintAllowed; 0143 0144 /** 0145 * How many times player has used hint 0146 */ 0147 int m_hintCount; 0148 0149 /** 0150 * Can player request undo or not 0151 */ 0152 bool m_undoAllowed; 0153 0154 /** 0155 * How many times player has used undo 0156 */ 0157 int m_undoCount; 0158 }; 0159 0160 #endif // KREVERSIPLAYER_H