KGameComputerIO Class Reference

KGameIO variant for real-time games. More...

#include <kgameio.h>

Inheritance diagram for KGameComputerIO:

Inheritance graph
[legend]
Collaboration diagram for KGameComputerIO:

Collaboration graph
[legend]
List of all members.

Public Slots

virtual void advance ()
 Works kind of similar to QCanvas::advance.

Signals

void signalReaction ()
 This signal is emitted when your computer player is meant to do something, or better is meant to be allowed to do something.

Public Member Functions

 KGameComputerIO ()
 Creates a LOCAL computer player.
 KGameComputerIO (KPlayer *player)
 ~KGameComputerIO ()
int rtti () const
 Run time idendification.
void setReactionPeriod (int advanceCalls)
 The number of advance calls until the player (or rather: the IO) does something (default: 1).
int reactionPeriod () const
void setAdvancePeriod (int ms)
 Start a QTimer which calls advance every ms milli seconds.
void stopAdvancePeriod ()
void pause (int calls=-1)
 Ignore calls number of advance calls.
void unpause ()
 Equivalent to pause(0).

Protected Member Functions

virtual void reaction ()
 Default implementation simply emits signalReaction.

Classes

class  KGameComputerIOPrivate

Detailed Description

KGameIO variant for real-time games.

The KGameComputerIO class. It is used to create a LOCAL computer player and communicate transparently with it. Question: Is this needed or is it overwritten anyway for a real game?

You most probably don't want to use this if you want to design a turn based game/player. You'll rather use KGameIO directly, i.e. subclass it yourself. You just need to use KGameIO::signalPrepareTurn and/or KGameIO::notifyTurn there.

This is rather meant to be of use in real time games.

Author:
<b_mann@gmx.de>

Definition at line 477 of file kgameio.h.


Constructor & Destructor Documentation

KGameComputerIO::KGameComputerIO  ) 
 

Creates a LOCAL computer player.

Definition at line 449 of file kgameio.cpp.

KGameComputerIO::KGameComputerIO KPlayer player  ) 
 

Definition at line 454 of file kgameio.cpp.

KGameComputerIO::~KGameComputerIO  ) 
 

Definition at line 464 of file kgameio.cpp.

References KGameComputerIO::KGameComputerIOPrivate::mAdvanceTimer.


Member Function Documentation

void KGameComputerIO::advance  )  [virtual, slot]
 

Works kind of similar to QCanvas::advance.

Increase the internal advance counter. If reactionPeriod is reached the counter is set back to 0 and signalReaction is emitted. This is when the player is meant to do something (move its units or so).

This is very useful if you use QCanvas as you can use this in your QCanvas::advance call. The advantage is that if you change the speed of the game (i.e. change QCanvas::setAdvancePeriod) the computer player gets slower as well.

If you don't use QCanvas you can use setAdvancePeriod to get the same result. Alternatively you can just use a QTimer.

Definition at line 515 of file kgameio.cpp.

References KGameComputerIO::KGameComputerIOPrivate::mAdvanceCounter, KGameComputerIO::KGameComputerIOPrivate::mPauseCounter, KGameComputerIO::KGameComputerIOPrivate::mReactionPeriod, and reaction().

Referenced by setAdvancePeriod().

void KGameComputerIO::pause int  calls = -1  ) 
 

Ignore calls number of advance calls.

if calls is -1 then all following advance calls are ignored until unpause is called.

This simply prevents the internal advance counter to be increased.

You may want to use this to emulate a "thinking" computer player. Note that this means if you increase the advance period (see setAdvancePeriod), i.e. if you change the speed of your game, your computer player thinks "faster".

Parameters:
calls Number of advance calls to be ignored

Definition at line 505 of file kgameio.cpp.

References KGameComputerIO::KGameComputerIOPrivate::mPauseCounter.

Referenced by unpause().

void KGameComputerIO::reaction  )  [protected, virtual]
 

Default implementation simply emits signalReaction.

Definition at line 534 of file kgameio.cpp.

References signalReaction().

Referenced by advance().

int KGameComputerIO::reactionPeriod  )  const
 

Definition at line 483 of file kgameio.cpp.

References KGameComputerIO::KGameComputerIOPrivate::mReactionPeriod.

int KGameComputerIO::rtti  )  const [virtual]
 

Run time idendification.

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

Returns:
rtti value

Implements KGameIO.

Definition at line 473 of file kgameio.cpp.

References KGameIO::ComputerIO.

void KGameComputerIO::setAdvancePeriod int  ms  ) 
 

Start a QTimer which calls advance every ms milli seconds.

Definition at line 488 of file kgameio.cpp.

References advance(), KGameComputerIO::KGameComputerIOPrivate::mAdvanceTimer, and stopAdvancePeriod().

Here is the call graph for this function:

void KGameComputerIO::setReactionPeriod int  advanceCalls  ) 
 

The number of advance calls until the player (or rather: the IO) does something (default: 1).

Definition at line 478 of file kgameio.cpp.

References KGameComputerIO::KGameComputerIOPrivate::mReactionPeriod.

void KGameComputerIO::signalReaction  )  [signal]
 

This signal is emitted when your computer player is meant to do something, or better is meant to be allowed to do something.

Referenced by reaction().

void KGameComputerIO::stopAdvancePeriod  ) 
 

Definition at line 496 of file kgameio.cpp.

References KGameComputerIO::KGameComputerIOPrivate::mAdvanceTimer.

Referenced by setAdvancePeriod().

void KGameComputerIO::unpause  ) 
 

Equivalent to pause(0).

Immediately continue to increase the internal advance counter.

Definition at line 510 of file kgameio.cpp.

References pause().

Here is the call graph for this function:


The documentation for this class was generated from the following files:
Generated on Wed Aug 23 18:05:05 2006 for libkdegames by  doxygen 1.4.6