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

libkdegames/libkdegamesprivate/kgame

Public Types | Signals | Public Member Functions | List of all members
KGameIO Class Referenceabstract

#include <KGame/KGameIO>

Inheritance diagram for KGameIO:
Inheritance graph
[legend]

Public Types

enum  IOMode {
  GenericIO =1, KeyIO =2, MouseIO =4, ProcessIO =8,
  ComputerIO =16
}
 

Signals

void signalPrepareTurn (QDataStream &stream, bool turn, KGameIO *io, bool *send)
 

Public Member Functions

 KGameIO ()
 
 KGameIO (KPlayer *)
 
virtual ~KGameIO ()
 
void Debug ()
 
KGame * game () const
 
virtual void initIO (KPlayer *p)
 
virtual void notifyTurn (bool b)
 
KPlayer * player () const
 
virtual int rtti () const =0
 
bool sendInput (QDataStream &stream, bool transmit=true, quint32 sender=0)
 
void setPlayer (KPlayer *p)
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
 QObject (QObject *parent, const char *name)
 
virtual  ~QObject ()
 
bool blockSignals (bool block)
 
QObject * child (const char *objName, const char *inheritsClass, bool recursiveSearch) const
 
const QObjectList & children () const
 
const char * className () const
 
bool connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const QObject *receiver, const char *method)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method)
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QByteArray > dynamicPropertyNames () const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
T findChild (const QString &name) const
 
QList< T > findChildren (const QRegExp &regExp) const
 
QList< T > findChildren (const QString &name) const
 
bool inherits (const char *className) const
 
void insertChild (QObject *object)
 
void installEventFilter (QObject *filterObj)
 
bool isA (const char *className) const
 
bool isWidgetType () const
 
void killTimer (int id)
 
virtual const QMetaObject * metaObject () const
 
void moveToThread (QThread *targetThread)
 
const char * name () const
 
const char * name (const char *defaultName) const
 
QString objectName () const
 
QObject * parent () const
 
QVariant property (const char *name) const
 
void removeChild (QObject *object)
 
void removeEventFilter (QObject *obj)
 
void setName (const char *name)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval)
 
QThread * thread () const
 

Additional Inherited Members

- Static Public Member Functions inherited from QObject
bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
- Protected Member Functions inherited from QObject
bool checkConnectArgs (const char *signal, const QObject *object, const char *method)
 
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const char *signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const char *signal)
 
int receivers (const char *signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 
- Static Protected Member Functions inherited from QObject
QByteArray normalizeSignalSlot (const char *signalSlot)
 
- Properties inherited from QObject
 objectName
 

Detailed Description

Base class for IO devices for games.

This is the master class for creating IO game devices. You cannot use it directly. Either take one of the classes derived from it or you have to create your own IO class derived from it (more probably).

The idea behind this class is to provide a common interface for input devices into your game. By programming a KGameIO device you need not distinguish the actual IO in the game anymore. All work is done by the IO's. This allows very easy reuse in other games as well. A further advantage of using the IO's is that you can exchange the control of a player at runtime. E.g. you switch a player to be controlled by the computer or vice versa.

To achieve this you have to make all of your player inputs through a KGameIO. You will usually call KGameIO::sendInput to do so.

Author
Martin Heni <kde at heni-online.de>

Definition at line 65 of file kgameio.h.

Member Enumeration Documentation

enum KGameIO::IOMode

Identifies the KGameIO via the rtti function.

Enumerator
GenericIO 
KeyIO 
MouseIO 
ProcessIO 
ComputerIO 

Definition at line 85 of file kgameio.h.

Constructor & Destructor Documentation

KGameIO::KGameIO ( )

Constructs a KGameIO object.

Definition at line 54 of file kgameio.cpp.

KGameIO::KGameIO ( KPlayer *  player)

Definition at line 60 of file kgameio.cpp.

KGameIO::~KGameIO ( )
virtual

Definition at line 70 of file kgameio.cpp.

Member Function Documentation

void KGameIO::Debug ( )

Gives debug output of the game status.

Definition at line 134 of file kgameio.cpp.

KGame * KGameIO::game ( ) const

Equivalent to player()->game()

Returns
the KGame object of this player

Definition at line 116 of file kgameio.cpp.

void KGameIO::initIO ( KPlayer *  p)
virtual

Init this device by setting the player and e.g.

sending an init message to the device. This initialisation message is very useful for computer players as you can transmit the game status to them and only update this status in the setTurn commands.

Called by KPlayer::addGameIO only!

Reimplemented in KGameProcessIO.

Definition at line 91 of file kgameio.cpp.

void KGameIO::notifyTurn ( bool  b)
virtual

Notifies the IO device that the player's setTurn had been called Called by KPlayer.

This emits signalPrepareTurn and sends the turn if the send parameter is set to true.

Parameters
bturn is true/false

Reimplemented in KGameProcessIO.

Definition at line 96 of file kgameio.cpp.

KPlayer * KGameIO::player ( ) const

This function returns the player who owns this IO.

Returns
the player this IO device is plugged into

Definition at line 81 of file kgameio.cpp.

virtual int KGameIO::rtti ( ) const
pure virtual

Run time idendification.

Predefined values are from IOMode You MUST overwrite this in derived classes!

Returns
rtti value

Implemented in KGameComputerIO, KGameProcessIO, KGameMouseIO, and KGameKeyIO.

bool KGameIO::sendInput ( QDataStream &  stream,
bool  transmit = true,
quint32  sender = 0 
)

Send an input message using KPlayer::forwardInput.

Definition at line 125 of file kgameio.cpp.

void KGameIO::setPlayer ( KPlayer *  p)

Sets the player to which this IO belongs to.

This is done automatically when adding a device to a player

Parameters
pthe player

Definition at line 86 of file kgameio.cpp.

void KGameIO::signalPrepareTurn ( QDataStream &  stream,
bool  turn,
KGameIO *  io,
bool *  send 
)
signal

Signal generated when KPlayer::myTurn changes.

This can either be when you get the turn status or when you lose it.

The datastream has to be filled with a move. If you set (or leave) the send parameter to FALSE then nothing happens: the datastream will be ignored. If you set it to TRUE sendInput is used to send the move.

Often you want to ignore this signal (leave send=FALSE) and send the message later. This is usually the case for a human player as he probably doesn't react immediately. But you can still use this e.g. to notify the player about the turn change.

Example:

void GameWindow::slotPrepareTurn(QDataStream &stream,bool b,KGameIO *input,bool * )
{
KPlayer *player=input->player();
if (!player->myTurn()) return ;
if (!b) return ; // only do something on setTurn(true)
stream << 1 << 2 << 3; // Some data for the process
}
Parameters
iothe KGameIO object itself
streamthe stream into which the move will be written
turnthe argument of setTurn
sendset this to true to send the generated move using sendInput

The documentation for this class was generated from the following files:
  • kgameio.h
  • kgameio.cpp
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