Move Class Reference

#include <Move.h>

Inheritance diagram for Move:

Inheritance graph
[legend]
Collaboration diagram for Move:

Collaboration graph
[legend]

Public Member Functions

virtual ~Move ()
 Destructor.
virtual move_command getHandledMovement () const =0
 Return the handled movement.
virtual std::pair< int, int > getHandledRelCoords () const =0
 Transform a move_command into a pair of relative coordinates.
virtual move_command getHandledOpposite () const =0
 Give the opposite movement.
unsigned int size ()
 Get the size of the chain.
MoveIterator begin ()
 Return an iterator in order to get the possible movements.
MoveIterator end ()
 Return an iterator in order to get the possible movements.
std::pair< int, int > getAbsCoords (move_command cmd, int i, int j) const
 Transform a move_command into a pair of coordinates.
std::pair< int, int > getAbsCoords (int i, int j) const
 Get the pair of coordinates corresponding to the current movement.
move_command opposite (move_command cmd) const
 Give the opposite movement.

Protected Member Functions

 Move (Move *next)
 Protected constructor.

Private Attributes

Move_next
 The next handled move.

Friends

class MoveIterator

Detailed Description

< A movement

Definition at line 37 of file Move.h.


Constructor & Destructor Documentation

Move::Move ( Move next  )  [protected]

Protected constructor.

Parameters:
next the next handled move

Definition at line 31 of file Move.cpp.

00031                       : _next(next) {
00032 
00033 }


Member Function Documentation

virtual move_command Move::getHandledMovement (  )  const [pure virtual]

Return the handled movement.

Returns:
handled movement

Implemented in EastMove, NoMove, NorthEastMove, NorthMove, NorthWestMove, SouthEastMove, SouthMove, SouthWestMove, and WestMove.

Referenced by getAbsCoords(), MoveIterator::operator *(), and opposite().

Here is the caller graph for this function:

virtual std::pair<int,int> Move::getHandledRelCoords (  )  const [pure virtual]

Transform a move_command into a pair of relative coordinates.

Returns:
the pair of the future coordinate (after the move)

Implemented in EastMove, NoMove, NorthEastMove, NorthMove, NorthWestMove, SouthEastMove, SouthMove, SouthWestMove, and WestMove.

Referenced by getAbsCoords().

Here is the caller graph for this function:

virtual move_command Move::getHandledOpposite (  )  const [pure virtual]

Give the opposite movement.

Returns:
the opposite movement

Implemented in EastMove, NoMove, NorthEastMove, NorthMove, NorthWestMove, SouthEastMove, SouthMove, SouthWestMove, and WestMove.

Referenced by opposite().

Here is the caller graph for this function:

unsigned int Move::size (  ) 

Get the size of the chain.

Returns:
the dize of the chain

Definition at line 39 of file Move.cpp.

References _next.

Referenced by VisualContext::nbMovements().

00039                         {
00040   Move * ptr = _next;
00041   unsigned int n = 1;
00042   while(ptr){
00043     ptr = ptr->_next;
00044     n++;
00045   }
00046   return n;
00047 }

Here is the caller graph for this function:

MoveIterator Move::begin (  ) 

Return an iterator in order to get the possible movements.

Returns:
iterator at the beginning of the list of movements

Definition at line 49 of file Move.cpp.

Referenced by VisualContext::beginMove().

00049                          {
00050   MoveIterator m(this);
00051   return m;
00052 }

Here is the caller graph for this function:

MoveIterator Move::end (  ) 

Return an iterator in order to get the possible movements.

Returns:
iterator at the end of the list of movements

Definition at line 54 of file Move.cpp.

Referenced by VisualContext::endMove().

00054                        {
00055   MoveIterator m(NULL);
00056   return m;
00057 }

Here is the caller graph for this function:

std::pair< int, int > Move::getAbsCoords ( move_command  cmd,
int  i,
int  j 
) const

Transform a move_command into a pair of coordinates.

Parameters:
cmd mode command
i the vertical current coordinate
j the horizontal current coordinate
Returns:
the pair of the future coordinate (after the move)

Definition at line 59 of file Move.cpp.

References _next, getAbsCoords(), getHandledMovement(), and getHandledRelCoords().

Referenced by World::addCommand(), getAbsCoords(), and VisualContext::getCell().

00059                                                                         {
00060   std::pair<int,int> result;
00061 
00062   if(cmd == getHandledMovement()){
00063 
00064     std::pair<int,int> relatives;
00065     relatives = getHandledRelCoords();
00066     result.first = i + relatives.first;
00067     result.second = j + relatives.second;
00068 
00069   } else if(_next){
00070     result = _next->getAbsCoords(cmd, i, j);
00071   } else {
00072     throw "Illegal move !";
00073   }
00074   return result;
00075 }

Here is the call graph for this function:

Here is the caller graph for this function:

std::pair< int, int > Move::getAbsCoords ( int  i,
int  j 
) const

Get the pair of coordinates corresponding to the current movement.

Parameters:
i the vertical current coordinate
j the horizontal current coordinate
Returns:
the pair of the future coordinate (after the move)

Definition at line 77 of file Move.cpp.

References getAbsCoords(), and getHandledMovement().

00077                                                       {
00078   return getAbsCoords(getHandledMovement(), i, j);
00079 }

Here is the call graph for this function:

move_command Move::opposite ( move_command  cmd  )  const

Give the opposite movement.

Parameters:
cmd the command
Returns:
the opposite movement

Definition at line 81 of file Move.cpp.

References _next, getHandledMovement(), getHandledOpposite(), and opposite().

Referenced by VisualContext::opposite(), and opposite().

00081                                                   {
00082   move_command res;
00083 
00084   //Can we handle it ?
00085   if(cmd == getHandledMovement()){
00086     res = getHandledOpposite();
00087   } else if(_next){ //We can't, so we ask the next... if any
00088     res = _next->opposite(cmd);
00089   } else {
00090     throw "Illegal move !";
00091   }
00092   return res;
00093 }

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files:
Generated on Sat Feb 2 22:23:17 2008 for Teapot Colony Wars by  doxygen 1.5.4