• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

libkdegames/libkdegamesprivate/kgame

  • sources
  • kde-4.14
  • kdegames
  • libkdegames
  • libkdegamesprivate
  • kgame
kgamesequence.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the KDE games library
3  Copyright (C) 2003 Andreas Beckermann (b_mann@gmx.de)
4  Copyright (C) 2003 Martin Heni (kde at heni-online.de)
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "kgamesequence.h"
22 #include "kgamesequence.moc"
23 
24 #include "kplayer.h"
25 #include "kgame.h"
26 
27 #include <kdebug.h>
28 
29 class KGameSequence::KGameSequencePrivate
30 {
31  public:
32  KGameSequencePrivate()
33  : mGame(0), mCurrentPlayer(0)
34  {
35  }
36 
37  KGame* mGame;
38  KPlayer* mCurrentPlayer;
39 };
40 
41 KGameSequence::KGameSequence()
42  : QObject(), d(new KGameSequencePrivate)
43 {
44 }
45 
46 KGameSequence::~KGameSequence()
47 {
48  delete d;
49 }
50 
51 void KGameSequence::setGame(KGame* game)
52 {
53  d->mGame = game;
54 }
55 
56 KGame* KGameSequence::game() const
57 {
58  return d->mGame;
59 }
60 
61 KPlayer* KGameSequence::currentPlayer() const
62 {
63  return d->mCurrentPlayer;
64 }
65 
66 void KGameSequence::setCurrentPlayer(KPlayer* player)
67 {
68  d->mCurrentPlayer = player;
69 }
70 
71 KPlayer *KGameSequence::nextPlayer(KPlayer *last,bool exclusive)
72 {
73  kDebug(11001) << "=================== NEXT PLAYER ==========================";
74  if (!game())
75  {
76  kError() << "NULL game object";
77  return 0;
78  }
79  unsigned int minId,nextId,lastId;
80  KPlayer *nextplayer, *minplayer;
81  if (last)
82  {
83  lastId = last->id();
84  }
85  else
86  {
87  lastId = 0;
88  }
89 
90  kDebug(11001) << "nextPlayer: lastId="<<lastId;
91 
92  // remove when this has been checked
93  minId = 0x7fff; // we just need a very large number...properly MAX_UINT or so would be ok...
94  nextId = minId;
95  nextplayer = 0;
96  minplayer = 0;
97 
98  QList<KPlayer*>::iterator it = game()->playerList()->begin();
99  for (;it != game()->playerList()->end(); it++ )
100  {
101  KPlayer* player = *it;
102  // Find the first player for a cycle
103  if (player->id() < minId)
104  {
105  minId=player->id();
106  minplayer=player;
107  }
108  if (player==last)
109  {
110  continue;
111  }
112  // Find the next player which is bigger than the current one
113  if (player->id() > lastId && player->id() < nextId)
114  {
115  nextId=player->id();
116  nextplayer=player;
117  }
118  }
119 
120  // Cycle to the beginning
121  if (!nextplayer)
122  {
123  nextplayer=minplayer;
124  }
125 
126  kDebug(11001) << " ##### lastId=" << lastId << "exclusive="
127  << exclusive << " minId=" << minId << "nextid=" << nextId
128  << "count=" << game()->playerList()->count();
129  if (nextplayer)
130  {
131  nextplayer->setTurn(true,exclusive);
132  }
133  else
134  {
135  return 0;
136  }
137  return nextplayer;
138 }
139 
140 // Per default we do not do anything
141 int KGameSequence::checkGameOver(KPlayer*)
142 {
143  return 0;
144 }
145 /*
146  * vim: et sw=2
147  */
KGameSequence::~KGameSequence
virtual ~KGameSequence()
Definition: kgamesequence.cpp:46
KPlayer::id
quint32 id() const
Returns the id of the player.
Definition: kplayer.cpp:247
KGameSequence::setGame
void setGame(KGame *game)
Set the KGame object for this sequence.
Definition: kgamesequence.cpp:51
kgame.h
KGameSequence::game
KGame * game() const
Definition: kgamesequence.cpp:56
KPlayer::setTurn
bool setTurn(bool b, bool exclusive=true)
Sets whether this player is the next to turn.
Definition: kplayer.cpp:342
KGameSequence::KGameSequence
KGameSequence()
Definition: kgamesequence.cpp:41
KGameSequence::checkGameOver
virtual int checkGameOver(KPlayer *player)
Check whether the game is over.
Definition: kgamesequence.cpp:141
QList::count
int count(const T &value) const
QObject
KGameSequence::nextPlayer
virtual KPlayer * nextPlayer(KPlayer *last, bool exclusive=true)
Select the next player in a turn based game.
Definition: kgamesequence.cpp:71
KGameSequence::setCurrentPlayer
virtual void setCurrentPlayer(KPlayer *p)
Definition: kgamesequence.cpp:66
kgamesequence.h
QList
KPlayer
Base class for a game player.
Definition: kplayer.h:69
QList::end
iterator end()
KGame
The main KDE game object.
Definition: kgame.h:60
kplayer.h
KGame::playerList
KGamePlayerList * playerList()
Returns a list of all active players.
Definition: kgame.cpp:711
QList::begin
iterator begin()
KGameSequence::currentPlayer
KPlayer * currentPlayer() const
Definition: kgamesequence.cpp:61
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:54 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdegames/libkdegamesprivate/kgame

Skip menu "libkdegames/libkdegamesprivate/kgame"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal