• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

libkdegames/libkdegamesprivate/kgame

  • sources
  • kde-4.14
  • kdegames
  • libkdegames
  • libkdegamesprivate
  • kgame
kgame.h
Go to the documentation of this file.
1 /*
2  This file is part of the KDE games library
3  Copyright (C) 2001 Martin Heni (kde at heni-online.de)
4  Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de)
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #ifndef __KGAME_H_
22 #define __KGAME_H_
23 
24 #include <QtCore/QDataStream>
25 #include <QtCore/QString>
26 #include <QtCore/QList>
27 
28 #include "kgamenetwork.h"
29 #include "../libkdegamesprivate_export.h"
30 class KRandomSequence;
31 
32 class KPlayer;
33 class KGamePropertyBase;
34 class KGamePropertyHandler;
35 class KGameSequence;
36 
37 class KGamePrivate;
38 
60 class KDEGAMESPRIVATE_EXPORT KGame : public KGameNetwork
61 {
62  Q_OBJECT
63 
64 public:
65  typedef QList<KPlayer*> KGamePlayerList;
66 
88  enum GamePolicy
89  {
90  PolicyUndefined = 0,
91  PolicyClean = 1,
92  PolicyDirty = 2,
93  PolicyLocal = 3
94  };
95 
101  explicit KGame(int cookie=42,QObject* parent=0);
102 
106  virtual ~KGame();
107 
111  virtual void Debug();
112 
118  enum GameStatus
119  {
120  Init = 0,
121  Run = 1,
122  Pause = 2,
123  End = 3,
124  Abort = 4,
125  SystemPause = 5,
126  Intro = 6,
127  UserStatus = 7
128  };
129 
130  // Properties
136  KGamePlayerList *playerList();
137 
141  const KGamePlayerList *playerList() const;
142 
147  KGamePlayerList *inactivePlayerList();
148 
152  const KGamePlayerList *inactivePlayerList() const;
153 
159  KRandomSequence *random() const;
160 
165  KGameSequence *gameSequence() const;
166 
171  bool isRunning() const;
172 
173  // Player handling
179  KPlayer *findPlayer(quint32 id) const;
180 
190  void setGameSequence(KGameSequence* sequence);
191 
209  bool addPlayer(KPlayer* newplayer);
210 
217  //AB: TODO: make sendMessage to return if the message will be able to be
218  //sent, eg if a socket is connected, etc. If sendMessage returns false
219  //remove the player directly using systemRemovePlayer
220  bool removePlayer(KPlayer * player) { return removePlayer(player, 0); }
221 
226  void playerDeleted(KPlayer * player);
227 
231  bool activatePlayer(KPlayer *player);
232 
236  bool inactivatePlayer(KPlayer *player);
237 
244  void setMaxPlayers(uint maxnumber);
245 
250  int maxPlayers() const;
251 
258  void setMinPlayers(uint minnumber);
259 
264  uint minPlayers() const;
265 
270  uint playerCount() const;
271 
276  virtual KPlayer * nextPlayer(KPlayer *last,bool exclusive=true);
277 
278  // Input events
283  virtual bool sendPlayerInput(QDataStream &msg,KPlayer *player,quint32 sender=0);
284 
295  virtual bool systemPlayerInput(QDataStream &msg,KPlayer *player,quint32 sender=0);
296 
323  virtual KPlayer *createPlayer(int rtti,int io,bool isvirtual);
324 
325  // load/save
338  virtual bool load(QDataStream &stream,bool reset=true);
339 
348  virtual bool load(const QString& filename,bool reset=true);
349 
359  virtual bool save(QDataStream &stream,bool saveplayers=true);
360 
369  virtual bool save(const QString& filename,bool saveplayers=true);
370 
378  virtual bool reset();
379 
380 
381  // Game sequence
387  int gameStatus() const;
388 
394  void setGameStatus(int status);
395 
399  bool addProperty(KGamePropertyBase* data);
400 
404  bool sendPlayerProperty(int msgid, QDataStream& s, quint32 playerId);
405 
410  KGamePropertyBase* findProperty(int id) const;
411 
418  void setPolicy(GamePolicy p,bool recursive=true);
419 
423  GamePolicy policy() const;
424 
436  bool sendGroupMessage(const QByteArray& msg, int msgid, quint32 sender, const QString& group);
437  bool sendGroupMessage(const QDataStream &msg, int msgid, quint32 sender, const QString& group);
438  bool sendGroupMessage(int msg, int msgid, quint32 sender, const QString& group);
439  bool sendGroupMessage(const QString& msg, int msgid, quint32 sender, const QString& group);
440 
459  virtual void networkTransmission(QDataStream &stream, int msgid, quint32 receiver, quint32 sender, quint32 clientID);
460 
464  KGamePropertyHandler* dataHandler() const;
465 
466 protected Q_SLOTS:
470  void sendProperty(int msgid, QDataStream& stream, bool* sent);
471 
475  void emitSignal(KGamePropertyBase *me);
476 
481  virtual void prepareNext();
482 
483 
488  void slotClientConnected(quint32 clientId);
489 
497  void slotClientDisconnected(quint32 clientId,bool broken);
498 
504  void slotServerDisconnected();
505 
506 Q_SIGNALS:
524  void signalReplacePlayerIO(KPlayer* player, bool* remove);
525 
540  void signalLoadPrePlayers(QDataStream &stream);
541 
549  void signalLoad(QDataStream &stream);
550 
564  void signalSavePrePlayers(QDataStream &stream);
565 
573  void signalSave(QDataStream &stream);
574 
586  void signalLoadError(QDataStream &stream,bool network,int cookie, bool &result);
587 
594  void signalNetworkData(int msgid,const QByteArray& buffer, quint32 receiver, quint32 sender);
595 
601  void signalMessageUpdate(int msgid,quint32 receiver,quint32 sender);
602 
613  void signalPlayerLeftGame(KPlayer *player);
614 
620  void signalPlayerJoinedGame(KPlayer *player);
621 
622 
627  void signalPropertyChanged(KGamePropertyBase *property, KGame *me);
628 
637  void signalGameOver(int status, KPlayer *current, KGame *me);
638 
650  void signalClientJoinedGame(quint32 clientid,KGame *me);
651 
669  void signalClientLeftGame(int clientID,int oldgamestatus,KGame *me);
670 
671 
672 protected:
700  virtual bool playerInput(QDataStream &msg,KPlayer *player)=0;
701 
702 
714  KPlayer *playerInputFinished(KPlayer *player);
715 
716 
750  virtual void newPlayersJoin(KGamePlayerList *oldplayer,
751  KGamePlayerList *newplayer,
752  QList<int> &inactivate) {
753  Q_UNUSED( oldplayer );
754  Q_UNUSED( newplayer );
755  Q_UNUSED( inactivate );
756  }
757 
766  void savePlayers(QDataStream &stream,KGamePlayerList *list=0);
767 
778  void savePlayer(QDataStream& stream,KPlayer* player);
779 
788  KPlayer *loadPlayer(QDataStream& stream,bool isvirtual=false);
789 
790 
794  bool systemInactivatePlayer(KPlayer *player);
795 
799  bool systemActivatePlayer(KPlayer *player);
800 
818  bool systemAddPlayer(KPlayer* newplayer);
819 
827  void systemRemovePlayer(KPlayer* player,bool deleteit);
828 
839  virtual void negotiateNetworkGame(quint32 clientID);
840 
845  void syncRandom();
846 
847  void deletePlayers();
848  void deleteInactivePlayers();
849 
857  virtual int checkGameOver(KPlayer *player);
858 
872  virtual bool loadgame(QDataStream &stream, bool network, bool reset);
873 
883  virtual bool savegame(QDataStream &stream, bool network,bool saveplayers);
884 
885 private:
886  //AB: this is to hide the "receiver" parameter from the user. It shouldn't be
887  //used if possible (except for init).
896  //void addPlayer(KPlayer* newplayer, quint32 receiver);
897 
903  bool removePlayer(KPlayer * player, quint32 receiver);
904 
908  void setupGame(quint32 sender);
909 
913  void setupGameContinue(QDataStream& msg, quint32 sender);
914 
922  bool systemRemove(KPlayer* player,bool deleteit);
923 
924 
925 private:
926  KGamePrivate* const d;
927 };
928 
929 #endif
KGameSequence
This class takes care of round or move management as well of the gameover condition.
Definition: kgamesequence.h:44
KGame::GameStatus
GameStatus
Game status - Use this to Control the game flow.
Definition: kgame.h:118
KGame::removePlayer
bool removePlayer(KPlayer *player)
Sends a message over the network, msgid=IdRemovePlayer.
Definition: kgame.h:220
QByteArray
QDataStream
KGamePropertyHandler
A collection class for KGameProperty objects.
Definition: kgamepropertyhandler.h:73
KGame::newPlayersJoin
virtual void newPlayersJoin(KGamePlayerList *oldplayer, KGamePlayerList *newplayer, QList< int > &inactivate)
This virtual function can be overwritten for your own player management.
Definition: kgame.h:750
kgamenetwork.h
KGame::GamePolicy
GamePolicy
The policy of the property.
Definition: kgame.h:88
QObject
QString
QList< KPlayer * >
KGame::KGamePlayerList
QList< KPlayer * > KGamePlayerList
Definition: kgame.h:65
KPlayer
Base class for a game player.
Definition: kplayer.h:69
KGamePropertyBase
Base class of KGameProperty.
Definition: kgameproperty.h:45
KGameNetwork::networkTransmission
virtual void networkTransmission(QDataStream &, int, quint32, quint32, quint32 clientID)=0
Called by ReceiveNetworkTransmission().
KGameNetwork
The KGameNetwork class is the KGame class with network support.
Definition: kgamenetwork.h:46
KGame
The main KDE game object.
Definition: kgame.h:60
KGameNetwork::Debug
virtual void Debug()
Gives debug output of the game status.
Definition: kgamenetwork.cpp:517
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:54 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdegames/libkdegamesprivate/kgame

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

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal