libkdegames/kgame
kgamesequence.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "kgamesequence.h"
00022 #include "kgamesequence.moc"
00023
00024 #include "kplayer.h"
00025 #include "kgame.h"
00026
00027 #include <kdebug.h>
00028
00029 class KGameSequence::KGameSequencePrivate
00030 {
00031 public:
00032 KGameSequencePrivate()
00033 : mGame(0), mCurrentPlayer(0)
00034 {
00035 }
00036
00037 KGame* mGame;
00038 KPlayer* mCurrentPlayer;
00039 };
00040
00041 KGameSequence::KGameSequence()
00042 : QObject(), d(new KGameSequencePrivate)
00043 {
00044 }
00045
00046 KGameSequence::~KGameSequence()
00047 {
00048 delete d;
00049 }
00050
00051 void KGameSequence::setGame(KGame* game)
00052 {
00053 d->mGame = game;
00054 }
00055
00056 KGame* KGameSequence::game() const
00057 {
00058 return d->mGame;
00059 }
00060
00061 KPlayer* KGameSequence::currentPlayer() const
00062 {
00063 return d->mCurrentPlayer;
00064 }
00065
00066 void KGameSequence::setCurrentPlayer(KPlayer* player)
00067 {
00068 d->mCurrentPlayer = player;
00069 }
00070
00071 KPlayer *KGameSequence::nextPlayer(KPlayer *last,bool exclusive)
00072 {
00073 kDebug(11001) << "=================== NEXT PLAYER ==========================";
00074 if (!game())
00075 {
00076 kError() << "NULL game object";
00077 return 0;
00078 }
00079 unsigned int minId,nextId,lastId;
00080 KPlayer *nextplayer, *minplayer;
00081 if (last)
00082 {
00083 lastId = last->id();
00084 }
00085 else
00086 {
00087 lastId = 0;
00088 }
00089
00090 kDebug(11001) << "nextPlayer: lastId="<<lastId;
00091
00092
00093 minId = 0x7fff;
00094 nextId = minId;
00095 nextplayer = 0;
00096 minplayer = 0;
00097
00098 QList<KPlayer*>::iterator it = game()->playerList()->begin();
00099 for (;it != game()->playerList()->end(); it++ )
00100 {
00101 KPlayer* player = *it;
00102
00103 if (player->id() < minId)
00104 {
00105 minId=player->id();
00106 minplayer=player;
00107 }
00108 if (player==last)
00109 {
00110 continue;
00111 }
00112
00113 if (player->id() > lastId && player->id() < nextId)
00114 {
00115 nextId=player->id();
00116 nextplayer=player;
00117 }
00118 }
00119
00120
00121 if (!nextplayer)
00122 {
00123 nextplayer=minplayer;
00124 }
00125
00126 kDebug(11001) << " ##### lastId=" << lastId << "exclusive="
00127 << exclusive << " minId=" << minId << "nextid=" << nextId
00128 << "count=" << game()->playerList()->count();
00129 if (nextplayer)
00130 {
00131 nextplayer->setTurn(true,exclusive);
00132 }
00133 else
00134 {
00135 return 0;
00136 }
00137 return nextplayer;
00138 }
00139
00140
00141 int KGameSequence::checkGameOver(KPlayer*)
00142 {
00143 return 0;
00144 }
00145
00146
00147