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

libkdegames/kgame

kgamesequence.cpp

Go to the documentation of this file.
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 (kde at 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., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
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  // remove when this has been checked
00093  minId = 0x7fff;  // we just need a very large number...properly MAX_UINT or so would be ok...
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    // Find the first player for a cycle
00103    if (player->id() < minId)
00104    {
00105      minId=player->id();
00106      minplayer=player;
00107    }
00108    if (player==last)
00109    {
00110      continue;
00111    }
00112    // Find the next player which is bigger than the current one
00113    if (player->id() > lastId && player->id() < nextId)
00114    {
00115      nextId=player->id();
00116      nextplayer=player;
00117    }
00118  }
00119 
00120  // Cycle to the beginning
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 // Per default we do not do anything
00141 int KGameSequence::checkGameOver(KPlayer*)
00142 {
00143  return 0;
00144 }
00145 /*
00146  * vim: et sw=2
00147  */

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