• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

libkdegames/kgame

kgame.h

Go to the documentation of this file.
00001 /*
00002     This file is part of the KDE games library
00003     Copyright (C) 2001 Martin Heni (kde at heni-online.de)
00004     Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de)
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License version 2 as published by the Free Software Foundation.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #ifndef __KGAME_H_
00022 #define __KGAME_H_
00023 
00024 #include <QtCore/QDataStream>
00025 #include <QtCore/QString>
00026 #include <QtCore/QList>
00027 
00028 #include "kgamenetwork.h"
00029 #include <libkdegames_export.h>
00030 class KRandomSequence;
00031 
00032 class KPlayer;
00033 class KGamePropertyBase;
00034 class KGamePropertyHandler;
00035 class KGameSequence;
00036 
00037 class KGamePrivate;
00038 
00060 class KDEGAMES_EXPORT KGame : public KGameNetwork
00061 {
00062   Q_OBJECT
00063 
00064 public:
00065     typedef QList<KPlayer*> KGamePlayerList;
00066 
00088     enum GamePolicy
00089     {
00090         PolicyUndefined = 0,
00091         PolicyClean = 1,
00092         PolicyDirty = 2,
00093         PolicyLocal = 3
00094     };
00095 
00101     explicit KGame(int cookie=42,QObject* parent=0);
00102 
00106     virtual ~KGame();
00107 
00111     virtual void Debug();
00112 
00118     enum GameStatus
00119     {
00120         Init = 0,
00121         Run = 1,
00122         Pause = 2,
00123         End = 3,
00124         Abort = 4,
00125         SystemPause = 5,
00126         Intro = 6,
00127         UserStatus = 7
00128     };
00129 
00130     // Properties
00136     KGamePlayerList *playerList();
00137 
00141     const KGamePlayerList *playerList() const;
00142 
00147     KGamePlayerList *inactivePlayerList();
00148 
00152     const KGamePlayerList *inactivePlayerList() const;
00153 
00159     KRandomSequence *random() const;
00160 
00165     KGameSequence *gameSequence() const;
00166 
00171     bool isRunning() const;
00172 
00173     // Player handling
00179     KPlayer *findPlayer(quint32 id) const;
00180 
00190     void setGameSequence(KGameSequence* sequence);
00191 
00209     bool addPlayer(KPlayer* newplayer);
00210 
00217     //AB: TODO: make sendMessage to return if the message will be able to be
00218     //sent, eg if a socket is connected, etc. If sendMessage returns false
00219     //remove the player directly using systemRemovePlayer
00220     bool removePlayer(KPlayer * player) { return removePlayer(player, 0); }
00221 
00226     void playerDeleted(KPlayer * player);
00227 
00231     bool activatePlayer(KPlayer *player);
00232 
00236     bool inactivatePlayer(KPlayer *player);
00237 
00244     void setMaxPlayers(uint maxnumber);
00245 
00250     int maxPlayers() const;
00251 
00258     void setMinPlayers(uint minnumber);
00259 
00264     uint minPlayers() const;
00265 
00270     uint playerCount() const;
00271 
00276     virtual KPlayer * nextPlayer(KPlayer *last,bool exclusive=true);
00277 
00278     // Input events
00283     virtual bool sendPlayerInput(QDataStream &msg,KPlayer *player,quint32 sender=0);
00284 
00295     virtual bool systemPlayerInput(QDataStream &msg,KPlayer *player,quint32 sender=0);
00296 
00323     virtual KPlayer *createPlayer(int rtti,int io,bool isvirtual);
00324 
00325     // load/save
00338     virtual bool load(QDataStream &stream,bool reset=true);
00339 
00348     virtual bool load(const QString& filename,bool reset=true);
00349 
00359     virtual bool save(QDataStream &stream,bool saveplayers=true);
00360 
00369     virtual bool save(const QString& filename,bool saveplayers=true);
00370 
00378     virtual bool reset();
00379 
00380 
00381     // Game sequence
00387     int gameStatus() const;
00388 
00394     void setGameStatus(int status);
00395 
00399     bool addProperty(KGamePropertyBase* data);
00400 
00404     bool sendPlayerProperty(int msgid, QDataStream& s, quint32 playerId);
00405 
00410     KGamePropertyBase* findProperty(int id) const;
00411 
00418     void setPolicy(GamePolicy p,bool recursive=true);
00419 
00423     GamePolicy policy() const;
00424 
00436     bool sendGroupMessage(const QByteArray& msg, int msgid, quint32 sender, const QString& group);
00437     bool sendGroupMessage(const QDataStream &msg, int msgid, quint32 sender, const QString& group);
00438     bool sendGroupMessage(int msg, int msgid, quint32 sender, const QString& group);
00439     bool sendGroupMessage(const QString& msg, int msgid, quint32 sender, const QString& group);
00440 
00459     virtual void networkTransmission(QDataStream &stream, int msgid, quint32 receiver, quint32 sender, quint32 clientID);
00460 
00464     KGamePropertyHandler* dataHandler() const;
00465 
00466 protected Q_SLOTS:
00470     void sendProperty(int msgid, QDataStream& stream, bool* sent);
00471 
00475     void emitSignal(KGamePropertyBase *me);
00476 
00481     virtual void prepareNext();
00482 
00483 
00488     void slotClientConnected(quint32 clientId);
00489 
00497     void slotClientDisconnected(quint32 clientId,bool broken);
00498 
00504     void slotServerDisconnected();
00505 
00506 Q_SIGNALS:
00524     void signalReplacePlayerIO(KPlayer* player, bool* remove);
00525 
00540     void signalLoadPrePlayers(QDataStream &stream);
00541 
00549     void signalLoad(QDataStream &stream);
00550 
00564     void signalSavePrePlayers(QDataStream &stream);
00565     
00573     void signalSave(QDataStream &stream);
00574 
00586     void signalLoadError(QDataStream &stream,bool network,int cookie, bool &result);
00587 
00594     void signalNetworkData(int msgid,const QByteArray& buffer, quint32 receiver, quint32 sender);
00595 
00601     void signalMessageUpdate(int msgid,quint32 receiver,quint32 sender);
00602 
00613     void signalPlayerLeftGame(KPlayer *player);
00614 
00620     void signalPlayerJoinedGame(KPlayer *player);
00621 
00622 
00627     void signalPropertyChanged(KGamePropertyBase *property, KGame *me);
00628 
00637     void signalGameOver(int status, KPlayer *current, KGame *me);
00638 
00650     void signalClientJoinedGame(quint32 clientid,KGame *me);
00651 
00669     void signalClientLeftGame(int clientID,int oldgamestatus,KGame *me);
00670 
00671 
00672 protected:
00700     virtual bool playerInput(QDataStream &msg,KPlayer *player)=0;
00701 
00702 
00714     KPlayer *playerInputFinished(KPlayer *player);
00715 
00716 
00750     virtual void newPlayersJoin(KGamePlayerList *oldplayer,
00751                 KGamePlayerList *newplayer,
00752                 QList<int> &inactivate) {
00753         Q_UNUSED( oldplayer );
00754         Q_UNUSED( newplayer );
00755         Q_UNUSED( inactivate );
00756     }
00757 
00766     void savePlayers(QDataStream &stream,KGamePlayerList *list=0);
00767 
00778     void savePlayer(QDataStream& stream,KPlayer* player);
00779 
00788     KPlayer *loadPlayer(QDataStream& stream,bool isvirtual=false);
00789 
00790 
00794     bool systemInactivatePlayer(KPlayer *player);
00795 
00799     bool systemActivatePlayer(KPlayer *player);
00800 
00818     bool systemAddPlayer(KPlayer* newplayer);
00819 
00827     void systemRemovePlayer(KPlayer* player,bool deleteit);
00828 
00839     virtual void negotiateNetworkGame(quint32 clientID);
00840 
00845     void syncRandom();
00846 
00847     void deletePlayers();
00848     void deleteInactivePlayers();
00849 
00857     virtual int checkGameOver(KPlayer *player);
00858 
00872     virtual bool loadgame(QDataStream &stream, bool network, bool reset);
00873 
00883     virtual bool savegame(QDataStream &stream, bool network,bool saveplayers);
00884 
00885 private:
00886     //AB: this is to hide the "receiver" parameter from the user. It shouldn't be
00887     //used if possible (except for init).
00896     //void addPlayer(KPlayer* newplayer, quint32 receiver);
00897 
00903     bool removePlayer(KPlayer * player, quint32 receiver);
00904 
00908     void setupGame(quint32 sender);
00909 
00913     void setupGameContinue(QDataStream& msg, quint32 sender);
00914 
00922     bool systemRemove(KPlayer* player,bool deleteit);
00923 
00924 
00925 private:
00926     KGamePrivate* const d;
00927 };
00928 
00929 #endif

libkdegames/kgame

Skip menu "libkdegames/kgame"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • kblackbox
  • kgoldrunner
  • kmahjongg
  • ksquares
  • libkdegames
  •   highscore
  •   kgame
  •   kggzgames
  •   kggzmod
  •   kggznet
  • libkmahjongg
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal