libkdegames Library API Documentation

kgamesequence.cpp

00001 /* 00002 This file is part of the KDE games library 00003 Copyright (C) 2003 Andreas Beckermann (b_mann@gmx.de) 00004 Copyright (C) 2003 Martin Heni (martin@heni-online.de) 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License version 2 as published by the Free Software Foundation. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00018 Boston, MA 02111-1307, USA. 00019 */ 00020 /* 00021 $Id: kgamesequence.cpp,v 1.1 2003/03/01 01:21:05 andreas Exp $ 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 // remove when this has been checked 00072 minId = 0x7fff; // we just need a very large number...properly MAX_UINT or so would be ok... 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 // Find the first player for a cycle 00081 if (player->id() < minId) 00082 { 00083 minId=player->id(); 00084 minplayer=player; 00085 } 00086 if (player==last) 00087 { 00088 continue; 00089 } 00090 // Find the next player which is bigger than the current one 00091 if (player->id() > lastId && player->id() < nextId) 00092 { 00093 nextId=player->id(); 00094 nextplayer=player; 00095 } 00096 } 00097 00098 // Cycle to the beginning 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 // Per default we do not do anything 00119 int KGameSequence::checkGameOver(KPlayer*) 00120 { 00121 return 0; 00122 } 00123 /* 00124 * vim: et sw=2 00125 */
KDE Logo
This file is part of the documentation for libkdegames Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Aug 26 00:21:41 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003