kgamesequence.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "kgamesequence.h"
00025 #include "kgamesequence.moc"
00026
00027 #include "kplayer.h"
00028 #include "kgame.h"
00029
00030 KGameSequence::KGameSequence() : QObject()
00031 {
00032 mGame = 0;
00033 mCurrentPlayer = 0;
00034 }
00035
00036 KGameSequence::~KGameSequence()
00037 {
00038 }
00039
00040 void KGameSequence::setGame(KGame* game)
00041 {
00042 mGame = game;
00043 }
00044
00045 void KGameSequence::setCurrentPlayer(KPlayer* player)
00046 {
00047 mCurrentPlayer = player;
00048 }
00049
00050 KPlayer *KGameSequence::nextPlayer(KPlayer *last,bool exclusive)
00051 {
00052 kdDebug(11001) << "=================== NEXT PLAYER =========================="<<endl;
00053 if (!game())
00054 {
00055 kdError() << k_funcinfo << "NULL game object" << endl;
00056 return 0;
00057 }
00058 unsigned int minId,nextId,lastId;
00059 KPlayer *nextplayer, *minplayer;
00060 if (last)
00061 {
00062 lastId = last->id();
00063 }
00064 else
00065 {
00066 lastId = 0;
00067 }
00068
00069 kdDebug(11001) << "nextPlayer: lastId="<<lastId<<endl;
00070
00071
00072 minId = 0x7fff;
00073 nextId = minId;
00074 nextplayer = 0;
00075 minplayer = 0;
00076
00077 KPlayer *player;
00078 for (player = game()->playerList()->first(); player != 0; player=game()->playerList()->next() )
00079 {
00080
00081 if (player->id() < minId)
00082 {
00083 minId=player->id();
00084 minplayer=player;
00085 }
00086 if (player==last)
00087 {
00088 continue;
00089 }
00090
00091 if (player->id() > lastId && player->id() < nextId)
00092 {
00093 nextId=player->id();
00094 nextplayer=player;
00095 }
00096 }
00097
00098
00099 if (!nextplayer)
00100 {
00101 nextplayer=minplayer;
00102 }
00103
00104 kdDebug(11001) << k_funcinfo << " ##### lastId=" << lastId << " exclusive="
00105 << exclusive << " minId=" << minId << " nextid=" << nextId
00106 << " count=" << game()->playerList()->count() << endl;
00107 if (nextplayer)
00108 {
00109 nextplayer->setTurn(true,exclusive);
00110 }
00111 else
00112 {
00113 return 0;
00114 }
00115 return nextplayer;
00116 }
00117
00118
00119 int KGameSequence::checkGameOver(KPlayer*)
00120 {
00121 return 0;
00122 }
00123
00124
00125
|