File indexing completed on 2024-06-16 03:57:56

0001 /*
0002     This file is part of the KDE games library
0003     SPDX-FileCopyrightText: 2003 Andreas Beckermann <b_mann@gmx.de>
0004     SPDX-FileCopyrightText: 2003 Martin Heni <kde at heni-online.de>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-only
0007 */
0008 
0009 #ifndef __KGAMESEQUENCE_H_
0010 #define __KGAMESEQUENCE_H_
0011 
0012 // own
0013 #include "kdegamesprivate_export.h"
0014 // Qt
0015 #include <QObject>
0016 // Std
0017 #include <memory>
0018 
0019 class KPlayer;
0020 class KGame;
0021 
0022 /**
0023  * \class KGameSequence kgamesequence.h <KGame/KGameSequence>
0024  *
0025  * This class takes care of round or move management as well of the gameover
0026  * condition. It is especially used for round based games. For these games @ref
0027  * nextPlayer and @ref checkGameOver are the most important methods.
0028  *
0029  * You can subclass KGameSequence and use @ref KGame::setGameSequence to use
0030  * your own rules. Note that @ref KGame will take ownership and therefore will
0031  * delete the object on destruction.
0032  * @short Round/move management class
0033  * @author Andreas Beckermann <b_mann@gmx.de>
0034  */
0035 class KDEGAMESPRIVATE_EXPORT KGameSequence : public QObject
0036 {
0037     Q_OBJECT
0038 
0039 public:
0040     KGameSequence();
0041     ~KGameSequence() override;
0042 
0043     /**
0044      * Select the next player in a turn based game. In an asynchronous game this
0045      * function has no meaning. Overwrite this function for your own game sequence.
0046      * Per default it selects the next player in the playerList
0047      */
0048     virtual KPlayer *nextPlayer(KPlayer *last, bool exclusive = true);
0049 
0050     virtual void setCurrentPlayer(KPlayer *p);
0051 
0052     /**
0053      * @return The @ref KGame object this sequence is for, or NULL if none.
0054      */
0055     KGame *game() const;
0056 
0057     KPlayer *currentPlayer() const;
0058 
0059     /**
0060      * Set the @ref KGame object for this sequence. This is called
0061      * automatically by @ref KGame::setGameSequence and you should not call
0062      * it.
0063      */
0064     void setGame(KGame *game);
0065 
0066     /**
0067      * Check whether the game is over. The default implementation always
0068      * returns 0.
0069      *
0070      * @param player the player who made the last move
0071      * @return anything else but 0 is considered as game over
0072      */
0073     virtual int checkGameOver(KPlayer *player);
0074 
0075 private:
0076     std::unique_ptr<class KGameSequencePrivate> const d;
0077 
0078     Q_DISABLE_COPY(KGameSequence)
0079 };
0080 
0081 #endif