1 /**************************************************************************
5 Copyright (c) Arto Hyvättinen 2010
7 This file is part of Chess Clock software.
9 Chess Clock is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Chess Clock is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
20 **************************************************************************/
29 class TurnInformation;
32 /*! Clock of a individual player
34 @author Arto Hyvättinen
37 Base class of chess clock.
39 ChessClock has not GUI itself, but it is subclass of QWidget
40 avoiding polymorphism.
43 class ChessClock : public QWidget
47 ChessClock(bool white, QWidget *parent = 0);
51 NotRunning /*! Not turn */ = 0,
52 Running /*! Turn running */ = 1,
53 Paused /*! Turn paused */ = 2
56 bool isLoser() const { return loser_; }
57 int getTurn() const { return turn_; }
58 bool isWhite() const { return isWhite_; }
59 RunningStatus getStatus() const { return status_ ; }
63 virtual void startTurn();
67 Player has done his move.
68 @return Locked turn information */
69 virtual TurnInformation* endTurn();
72 virtual void pauseTurn();
74 /*! Continue paused game */
75 virtual void continueTurn();
77 /*! Set another chess clock for connecting
78 @param another Clock of opposite player */
79 void setAnother( ChessClock* another);
81 /*! Get total time available
83 Time does't contain delays.
85 @return Time available in msecs */
86 virtual int getTimeAvailable();
88 /*! Get total time played
89 @return Time played in msecs */
90 virtual int getTimePlayed() const;
98 /*! Refresh clock information */
99 virtual void repaintClock() = 0;
101 /*! Update clock information, check looser state and refresh */
102 virtual void updateClock();
105 ChessClock* another_; /*! Another player's clock */
107 bool loser_; /*! Is player losed because of timeout */
108 int turn_; /*! Current turn */
109 RunningStatus status_;
110 TurnInformation* currentTurn_;
112 int timePlayedBeforeTurn_; /*! Time played in this game BEFORE this turn msecs */
113 int timeAvailableBeforeTurn_; /*! Time available for play BEFORE this turn msecs !*/
115 bool isWhite_; /*! True if white player */
120 static const int UPDATEINTERVAL = 1000; /** Clock updating interval in msecs */
124 #endif // CHESSCLOCK_H