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

libkdegames/kgame

KGameIO Class Reference

#include <kgameio.h>

Inheritance diagram for KGameIO:

Inheritance graph
[legend]

List of all members.


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 63 of file kgameio.h.


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 ()
virtual int rtti () const =0
KPlayer * player () const
KGame * game () const
void setPlayer (KPlayer *p)
virtual void initIO (KPlayer *p)
virtual void notifyTurn (bool b)
bool sendInput (QDataStream &stream, bool transmit=true, quint32 sender=0)

Friends

class KGameIOPrivate

Member Enumeration Documentation

enum KGameIO::IOMode

Identifies the KGameIO via the rtti function.

Enumerator:
GenericIO 
KeyIO 
MouseIO 
ProcessIO 
ComputerIO 

Definition at line 83 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.

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 KGameKeyIO, KGameMouseIO, KGameProcessIO, and KGameComputerIO.

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.

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::setPlayer ( KPlayer *  p  ) 

Sets the player to which this IO belongs to.

This is done automatically when adding a device to a player

Parameters:
p the player

Definition at line 86 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:
b turn is true/false

Reimplemented in KGameProcessIO.

Definition at line 96 of file kgameio.cpp.

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::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:
io the KGameIO object itself
stream the stream into which the move will be written
turn the argument of setTurn
send set this to true to send the generated move using sendInput


Friends And Related Function Documentation

friend class KGameIOPrivate [friend]

Definition at line 177 of file kgameio.h.


The documentation for this class was generated from the following files:
  • kgameio.h
  • kgameio.cpp

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