1 /*
2     This file is part of the KDE games kwin4 program
3     SPDX-FileCopyrightText: 2006 Martin Heni <kde@heni-online.de>
4 
5     SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #ifndef SCORE_H
9 #define SCORE_H
10 
11 // Qt
12 #include <QObject>
13 
14 class ScoreSprite;
15 
16 
17 /**
18  * The score object is a compatibility object to transfer the score between
19  * the various players and status information entities and the score widget.
20  */
21 class Score : public QObject
22 {
23     Q_OBJECT
24 
25 public:
26     /** Construct a score object.
27       * @param parent The parent object
28       */
29     explicit Score(QObject* parent = nullptr);
30 
31     /** Set and update the level of the AI.
32       * @param level  The new level
33       * @param no     The player number [0,1]
34       */
setLevel(int level,int no)35     void setLevel(int level, int no) {mLevel[no] = level; update();}
36 
37     /** Set and update the player name.
38       * @param name   The new name
39       * @param no     The player number [0,1]
40       */
setPlayerName(const QString & name,int no)41     void setPlayerName(const QString &name,int no) {mName[no] = name;update();}
42 
43     /** Set and update whose turn it is (which player goes next).
44       * @param no     The player number [0,1]
45       */
setTurn(int no)46     void setTurn(int no) {mTurn = no;update();}
47 
48     /** Set and update the amount of wins of a player.
49       * @param amount The new amount
50       * @param no     The player number [0,1]
51       */
setWins(int amount,int no)52     void setWins(int amount, int no) {mWin[no] = amount; update();}
53 
54     /** Set and update the amount of losses of a player.
55       * @param amount The new amount
56       * @param no     The player number [0,1]
57       */
setLosses(int amount,int no)58     void setLosses(int amount, int no) {mLoss[no] = amount; update();}
59 
60     /** Set and update the amount of draws of a player.
61       * @param amount The new amount
62       * @param no     The player number [0,1]
63       */
setRemis(int amount,int no)64     void setRemis(int amount, int no) {mRemis[no] = amount; update();}
65 
66     /** Set and update the amount of aborted games of a player.
67       * @param amount The new amount
68       * @param no     The player number [0,1]
69       */
setBreaks(int amount,int no)70     void setBreaks(int amount, int no) {mBrk[no] = amount; update();}
71 
72     /** Set and update the input device of a player.
73       * @param type   The new input device (KGameIO) [1,2,4,8], 8 is AI
74       * @param no     The player number [0,1]
75       */
setPlayedBy(int type,int no)76     void setPlayedBy(int type, int no) {mInputDevice[no] = type; update();}
77 
78     /** Connect the score to a display sprite. This sprite will
79       * be used for the update of the data.
80       * @param s The display sprite
81       */
82     void setDisplay(ScoreSprite* s);
83 
84 protected:
85     /** Push all data into the display sprite.
86       */
87     void update();
88 
89 private:
90     // The display sprite
91     ScoreSprite* mDisplay;
92 
93     // The name of the players
94     QString mName[2];
95 
96     // The level of the AI(s)
97     int mLevel[2];
98 
99     // Whose turn is it
100     int mTurn;
101 
102     // The amount of wins
103     int mWin[2];
104 
105     // The amount of draws
106     int mRemis[2];
107 
108     // The amount of losses
109     int mLoss[2];
110 
111     // The amount of aborted games
112     int mBrk[2];
113 
114     // The input device
115     int mInputDevice[2];
116 };
117 
118 #endif
119 
120