File indexing completed on 2024-10-06 03:45:28

0001 /*
0002     This file is part of the KDE games kwin4 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 SCORE_H
0009 #define SCORE_H
0010 
0011 // Qt
0012 #include <QObject>
0013 
0014 class ScoreSprite;
0015 
0016 /**
0017  * The score object is a compatibility object to transfer the score between
0018  * the various players and status information entities and the score widget.
0019  */
0020 class Score : public QObject
0021 {
0022     Q_OBJECT
0023 
0024 public:
0025     /**
0026      * Construct a score object.
0027      * @param parent The parent object
0028      */
0029     explicit Score(QObject *parent = nullptr);
0030 
0031     /**
0032      * Set and update the level of the AI.
0033      * @param level  The new level
0034      * @param no     The player number [0,1]
0035      */
0036     void setLevel(int level, int no)
0037     {
0038         mLevel[no] = level;
0039         update();
0040     }
0041 
0042     /**
0043      * Set and update the player name.
0044      * @param name   The new name
0045      * @param no     The player number [0,1]
0046      */
0047     void setPlayerName(const QString &name, int no)
0048     {
0049         mName[no] = name;
0050         update();
0051     }
0052 
0053     /**
0054      * Set and update whose turn it is (which player goes next).
0055      * @param no     The player number [0,1]
0056      */
0057     void setTurn(int no)
0058     {
0059         mTurn = no;
0060         update();
0061     }
0062 
0063     /**
0064      * Set and update the amount of wins of a player.
0065      * @param amount The new amount
0066      * @param no     The player number [0,1]
0067      */
0068     void setWins(int amount, int no)
0069     {
0070         mWin[no] = amount;
0071         update();
0072     }
0073 
0074     /**
0075      * Set and update the amount of losses of a player.
0076      * @param amount The new amount
0077      * @param no     The player number [0,1]
0078      */
0079     void setLosses(int amount, int no)
0080     {
0081         mLoss[no] = amount;
0082         update();
0083     }
0084 
0085     /**
0086      * Set and update the amount of draws of a player.
0087      * @param amount The new amount
0088      * @param no     The player number [0,1]
0089      */
0090     void setRemis(int amount, int no)
0091     {
0092         mRemis[no] = amount;
0093         update();
0094     }
0095 
0096     /**
0097      * Set and update the amount of aborted games of a player.
0098      * @param amount The new amount
0099      * @param no     The player number [0,1]
0100      */
0101     void setBreaks(int amount, int no)
0102     {
0103         mBrk[no] = amount;
0104         update();
0105     }
0106 
0107     /**
0108      * Set and update the input device of a player.
0109      * @param type   The new input device (KGameIO) [1,2,4,8], 8 is AI
0110      * @param no     The player number [0,1]
0111      */
0112     void setPlayedBy(int type, int no)
0113     {
0114         mInputDevice[no] = type;
0115         update();
0116     }
0117 
0118     /**
0119      * Connect the score to a display sprite. This sprite will
0120      * be used for the update of the data.
0121      * @param s The display sprite
0122      */
0123     void setDisplay(ScoreSprite *s);
0124 
0125 protected:
0126     /**
0127      * Push all data into the display sprite.
0128      */
0129     void update();
0130 
0131 private:
0132     // The display sprite
0133     ScoreSprite *mDisplay;
0134 
0135     // The name of the players
0136     QString mName[2];
0137 
0138     // The level of the AI(s)
0139     int mLevel[2];
0140 
0141     // Whose turn is it
0142     int mTurn;
0143 
0144     // The amount of wins
0145     int mWin[2];
0146 
0147     // The amount of draws
0148     int mRemis[2];
0149 
0150     // The amount of losses
0151     int mLoss[2];
0152 
0153     // The amount of aborted games
0154     int mBrk[2];
0155 
0156     // The input device
0157     int mInputDevice[2];
0158 };
0159 
0160 #endif