#include <Move.h>
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 |
Definition at line 37 of file Move.h.
Move::Move | ( | Move * | next | ) | [protected] |
virtual move_command Move::getHandledMovement | ( | ) | const [pure virtual] |
Return the handled movement.
Implemented in EastMove, NoMove, NorthEastMove, NorthMove, NorthWestMove, SouthEastMove, SouthMove, SouthWestMove, and WestMove.
Referenced by getAbsCoords(), MoveIterator::operator *(), and opposite().
virtual std::pair<int,int> Move::getHandledRelCoords | ( | ) | const [pure virtual] |
Transform a move_command into a pair of relative coordinates.
Implemented in EastMove, NoMove, NorthEastMove, NorthMove, NorthWestMove, SouthEastMove, SouthMove, SouthWestMove, and WestMove.
Referenced by getAbsCoords().
virtual move_command Move::getHandledOpposite | ( | ) | const [pure virtual] |
Give the opposite movement.
Implemented in EastMove, NoMove, NorthEastMove, NorthMove, NorthWestMove, SouthEastMove, SouthMove, SouthWestMove, and WestMove.
Referenced by opposite().
unsigned int Move::size | ( | ) |
Get the size 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 }
MoveIterator Move::begin | ( | ) |
Return an iterator in order to get the possible movements.
Definition at line 49 of file Move.cpp.
Referenced by VisualContext::beginMove().
00049 { 00050 MoveIterator m(this); 00051 return m; 00052 }
MoveIterator Move::end | ( | ) |
Return an iterator in order to get the possible movements.
Definition at line 54 of file Move.cpp.
Referenced by VisualContext::endMove().
00054 { 00055 MoveIterator m(NULL); 00056 return m; 00057 }
std::pair< int, int > Move::getAbsCoords | ( | move_command | cmd, | |
int | i, | |||
int | j | |||
) | const |
Transform a move_command into a pair of coordinates.
cmd | mode command | |
i | the vertical current coordinate | |
j | the horizontal current coordinate |
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 }
std::pair< int, int > Move::getAbsCoords | ( | int | i, | |
int | j | |||
) | const |
Get the pair of coordinates corresponding to the current movement.
i | the vertical current coordinate | |
j | the horizontal current coordinate |
Definition at line 77 of file Move.cpp.
References getAbsCoords(), and getHandledMovement().
00077 { 00078 return getAbsCoords(getHandledMovement(), i, j); 00079 }
move_command Move::opposite | ( | move_command | cmd | ) | const |
Give the opposite movement.
cmd | the command |
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 }