• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • libtdegames
 

libtdegames

  • libtdegames
  • kgame
kgamesequence.cpp
1 /*
2  This file is part of the TDE games library
3  Copyright (C) 2003 Andreas Beckermann (b_mann@gmx.de)
4  Copyright (C) 2003 Martin Heni (martin@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  $Id$
22 */
23 
24 #include "kgamesequence.h"
25 #include "kgamesequence.moc"
26 
27 #include "kplayer.h"
28 #include "kgame.h"
29 
30 KGameSequence::KGameSequence() : TQObject()
31 {
32  mGame = 0;
33  mCurrentPlayer = 0;
34 }
35 
36 KGameSequence::~KGameSequence()
37 {
38 }
39 
40 void KGameSequence::setGame(KGame* game)
41 {
42  mGame = game;
43 }
44 
45 void KGameSequence::setCurrentPlayer(KPlayer* player)
46 {
47  mCurrentPlayer = player;
48 }
49 
50 KPlayer *KGameSequence::nextPlayer(KPlayer *last,bool exclusive)
51 {
52  kdDebug(11001) << "=================== NEXT PLAYER =========================="<<endl;
53  if (!game())
54  {
55  kdError() << k_funcinfo << "NULL game object" << endl;
56  return 0;
57  }
58  unsigned int minId,nextId,lastId;
59  KPlayer *nextplayer, *minplayer;
60  if (last)
61  {
62  lastId = last->id();
63  }
64  else
65  {
66  lastId = 0;
67  }
68 
69  kdDebug(11001) << "nextPlayer: lastId="<<lastId<<endl;
70 
71  // remove when this has been checked
72  minId = 0x7fff; // we just need a very large number...properly MAX_UINT or so would be ok...
73  nextId = minId;
74  nextplayer = 0;
75  minplayer = 0;
76 
77  KPlayer *player;
78  for (player = game()->playerList()->first(); player != 0; player=game()->playerList()->next() )
79  {
80  // Find the first player for a cycle
81  if (player->id() < minId)
82  {
83  minId=player->id();
84  minplayer=player;
85  }
86  if (player==last)
87  {
88  continue;
89  }
90  // Find the next player which is bigger than the current one
91  if (player->id() > lastId && player->id() < nextId)
92  {
93  nextId=player->id();
94  nextplayer=player;
95  }
96  }
97 
98  // Cycle to the beginning
99  if (!nextplayer)
100  {
101  nextplayer=minplayer;
102  }
103 
104  kdDebug(11001) << k_funcinfo << " ##### lastId=" << lastId << " exclusive="
105  << exclusive << " minId=" << minId << " nextid=" << nextId
106  << " count=" << game()->playerList()->count() << endl;
107  if (nextplayer)
108  {
109  nextplayer->setTurn(true,exclusive);
110  }
111  else
112  {
113  return 0;
114  }
115  return nextplayer;
116 }
117 
118 // Per default we do not do anything
119 int KGameSequence::checkGameOver(KPlayer*)
120 {
121  return 0;
122 }
KGameSequence::game
KGame * game() const
Definition: kgamesequence.h:62
KGameSequence::setGame
void setGame(KGame *game)
Set the KGame object for this sequence.
Definition: kgamesequence.cpp:40
KGameSequence::nextPlayer
virtual KPlayer * nextPlayer(KPlayer *last, bool exclusive=true)
Select the next player in a turn based game.
Definition: kgamesequence.cpp:50
KGameSequence::checkGameOver
virtual int checkGameOver(KPlayer *player)
Check whether the game is over.
Definition: kgamesequence.cpp:119
KGame
The main KDE game object.
Definition: kgame.h:63
KGame::playerList
KGamePlayerList * playerList()
Returns a list of all active players.
Definition: kgame.cpp:699
KPlayer
Base class for a game player.
Definition: kplayer.h:70
KPlayer::id
TQ_UINT32 id() const
Returns the id of the player.
Definition: kplayer.cpp:195
KPlayer::setTurn
bool setTurn(bool b, bool exclusive=true)
Sets whether this player is the next to turn.
Definition: kplayer.cpp:285

libtdegames

Skip menu "libtdegames"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

libtdegames

Skip menu "libtdegames"
  • libtdegames
Generated for libtdegames by doxygen 1.9.1
This website is maintained by Timothy Pearson.