1 #include "game_container.h"
4 GameContainer::GameContainer (Game
* game
, IGameRules
* rules
) :
6 players(new std::list
<Player
*>),
13 GameContainer::~GameContainer ()
15 for (std::list
<Player
*>::iterator iter
= players
->begin();
16 iter
!= players
->end(); ++iter
) { delete(*iter
); }
20 bool GameContainer::gameEnded () const
25 int GameContainer::addPlayer (Player
* player
)
27 if (!started
&& player
!= NULL
) {
28 players
->push_back(player
);
34 void GameContainer::start ()
39 std::list
<Player
*>::iterator iter
;
42 while (result
!= END_GAME
&& players
->size() > 0) {
43 if (rules
->gameEnded(*game
)) {
47 for (iter
= players
->begin();
48 iter
!= players
->end() && result
!= END_GAME
; ++iter
) {
49 result
= onTurnBegin(*iter
);
50 result
= doPlayerTurn(*iter
);
51 result
= onTurnEnd(*iter
);
53 game
->setTurn(game
->getTurn()+1);
59 int GameContainer::doPlayerTurn (Player
* player
)
63 while ((cmd
= player
->nextCommand()) != NULL
) {
64 if (cmd
->execute(game
) != 0) {
71 int GameContainer::onTurnBegin (Player
* player
)
76 int GameContainer::onTurnEnd (Player
* player
)