mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2025-01-18 10:26:15 +01:00
The TurnCmd class does not inherit from Command anymore
This commit is contained in:
parent
59fac223f4
commit
de2d2777e2
5 changed files with 19 additions and 16 deletions
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include "navigation.h"
|
||||
#include "turn_cmd.h"
|
||||
#include "command.h"
|
||||
#include "game_exception.h"
|
||||
#include "debug.h"
|
||||
#include "encoding.h"
|
||||
|
@ -38,7 +39,7 @@ Navigation::Navigation()
|
|||
|
||||
Navigation::~Navigation()
|
||||
{
|
||||
BOOST_FOREACH(Command *c, m_turnCommands)
|
||||
BOOST_FOREACH(TurnCmd *c, m_turnCommands)
|
||||
{
|
||||
delete c;
|
||||
}
|
||||
|
@ -180,7 +181,7 @@ void Navigation::clearFuture()
|
|||
}
|
||||
|
||||
|
||||
const vector<TurnCmd *> & Navigation::getCommands() const
|
||||
const vector<TurnCmd *> & Navigation::getTurns() const
|
||||
{
|
||||
return m_turnCommands;
|
||||
}
|
||||
|
@ -191,7 +192,7 @@ void Navigation::print() const
|
|||
LOG_DEBUG("=== Commands history ===");
|
||||
LOG_DEBUG("Current position right after turn " << m_currTurn - 1);
|
||||
int index = 0;
|
||||
BOOST_FOREACH(const Command *c, m_turnCommands)
|
||||
BOOST_FOREACH(const TurnCmd *c, m_turnCommands)
|
||||
{
|
||||
LOG_DEBUG(index << " " << lfw(c->toString()));
|
||||
++index;
|
||||
|
|
|
@ -55,7 +55,7 @@ class Navigation
|
|||
*/
|
||||
void clearFuture();
|
||||
|
||||
const vector<TurnCmd *> & getCommands() const;
|
||||
const vector<TurnCmd *> & getTurns() const;
|
||||
|
||||
/**
|
||||
* Print the contents of the commands history, to ease debugging
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <sstream>
|
||||
|
||||
#include "turn_cmd.h"
|
||||
#include "command.h"
|
||||
#include "player.h"
|
||||
|
||||
|
||||
|
@ -30,8 +31,6 @@ INIT_LOGGER(game, TurnCmd);
|
|||
|
||||
TurnCmd::TurnCmd()
|
||||
{
|
||||
// Fake execution
|
||||
execute();
|
||||
}
|
||||
|
||||
|
||||
|
@ -51,7 +50,7 @@ void TurnCmd::addAndExecute(Command *iCmd)
|
|||
}
|
||||
|
||||
|
||||
void TurnCmd::doExecute()
|
||||
void TurnCmd::execute()
|
||||
{
|
||||
BOOST_FOREACH(Command *cmd, m_commands)
|
||||
{
|
||||
|
@ -61,7 +60,7 @@ void TurnCmd::doExecute()
|
|||
}
|
||||
|
||||
|
||||
void TurnCmd::doUndo()
|
||||
void TurnCmd::undo()
|
||||
{
|
||||
// Undo commands in the reverse order of execution
|
||||
vector<Command*>::reverse_iterator it;
|
||||
|
|
|
@ -23,17 +23,21 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
#include "command.h"
|
||||
#include "logging.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Command;
|
||||
|
||||
|
||||
/**
|
||||
* This class implements both the Command and Composite design patterns.
|
||||
* It encapsulates commands, while still behaving like one.
|
||||
* This class encapsulates commands, and almost behaves as one itself.
|
||||
* The main difference with a normal command (and thus with the composite pattern)
|
||||
* is that a TurnCmd provides partial execution: some of the commands it contains
|
||||
* (the first ones) can be executed, whereas others not.
|
||||
* The ones which can be executed are the ones flagged "auto-executable".
|
||||
*/
|
||||
class TurnCmd: public Command
|
||||
class TurnCmd
|
||||
{
|
||||
DEFINE_LOGGER();
|
||||
|
||||
|
@ -55,9 +59,8 @@ class TurnCmd: public Command
|
|||
|
||||
virtual wstring toString() const;
|
||||
|
||||
protected:
|
||||
virtual void doExecute();
|
||||
virtual void doUndo();
|
||||
void execute();
|
||||
void undo();
|
||||
|
||||
private:
|
||||
vector<Command *> m_commands;
|
||||
|
|
|
@ -156,7 +156,7 @@ void XmlWriter::write(const Game &iGame, const string &iFileName)
|
|||
#if 0
|
||||
iGame.getNavigation().print();
|
||||
#endif
|
||||
const vector<TurnCmd *> &turnCmdVect = iGame.getNavigation().getCommands();
|
||||
const vector<TurnCmd *> &turnCmdVect = iGame.getNavigation().getTurns();
|
||||
BOOST_FOREACH(const TurnCmd *turn, turnCmdVect)
|
||||
{
|
||||
if (turn->getCommands().empty() && turn == turnCmdVect.back())
|
||||
|
|
Loading…
Reference in a new issue