File indexing completed on 2024-09-08 03:47:08
0001 /* 0002 This file is part of the KDE games lskat 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 LSKAT_ABSTRACTENGINE_H 0009 #define LSKAT_ABSTRACTENGINE_H 0010 0011 // Qt includes 0012 #include <QHash> 0013 #include <QWidget> 0014 0015 // KF includes 0016 #include "lskat_debug.h" 0017 0018 // Local includes 0019 #include "deck.h" 0020 0021 // Forward declaration 0022 class Player; 0023 0024 using namespace CardDeck; 0025 0026 /** 0027 * The document/data object for the game. 0028 */ 0029 class AbstractEngine : public QObject 0030 { 0031 Q_OBJECT 0032 0033 public: 0034 /** 0035 * Constructor for the game engine. 0036 * @param parent The parent window 0037 */ 0038 explicit AbstractEngine(QWidget *parent); 0039 0040 /** 0041 * Stati of the game 0042 */ 0043 enum GameStatus {Running, Stopped}; 0044 0045 /** 0046 * Start a new game. 0047 * @param trump The trump suite. 0048 * @param startPlayer The start player 0049 */ 0050 virtual void startGame(Suite trump, int startPlayer) = 0; 0051 0052 /** 0053 * Stop a game. 0054 */ 0055 virtual void stopGame() = 0; 0056 0057 /** 0058 * Is the game still running? 0059 * @return True if the game is running. 0060 */ 0061 virtual bool isGameRunning() {return mGameStatus == Running;} 0062 0063 /** 0064 * Add a player to the game 0065 * @param no Player number 0066 * @param player Player to add 0067 */ 0068 virtual void addPlayer(int no, Player *player); 0069 0070 /** 0071 * Retrieve the player of the given number. 0072 * @param no The player number. 0073 * @return The player. 0074 */ 0075 virtual Player *player(int no); 0076 0077 /** 0078 * Retrieve the current player id 0079 * @return The current player. 0080 */ 0081 virtual int currentPlayer() {return mCurrentPlayer;} 0082 0083 public Q_SLOTS: 0084 /** 0085 * Player input available 0086 * @param inputId The input device id 0087 * @param playerNumber The player number [0-1] 0088 * @param cardNumber The card number [0-7] 0089 */ 0090 virtual void playerInput(int inputId, int playerNumber, int cardNumber) = 0; 0091 0092 Q_SIGNALS: 0093 /** 0094 * The game over signal. 0095 * @param winner The game winner (0,1,-1:drawn, -2:abort) 0096 */ 0097 void signalGameOver(int winner); 0098 0099 /** 0100 * A players turn is about to start. 0101 * @param player The new player 0102 */ 0103 void signalNextPlayer(Player *player); 0104 0105 protected: 0106 /** Current game status */ 0107 GameStatus mGameStatus; 0108 /** Whose turn is it */ 0109 int mCurrentPlayer; 0110 0111 /** Player in the game */ 0112 QHash<int, Player *> mPlayers; 0113 }; 0114 0115 #endif // LSKAT_ABSTRACTENGINE_H