D:/Development/Projects/X-Clone/X-Clone/trunk/Direction.cpp

Go to the documentation of this file.
00001 #include "Direction.h"
00002 
00003 Direction Direction::N(-1, -1, Direction::S, true);
00004 Direction Direction::NE(-1, 0, Direction::SW, false);
00005 Direction Direction::E(-1, 1, Direction::W, true);
00006 Direction Direction::SE(0, 1, Direction::NW, false);
00007 Direction Direction::S(1, 1, Direction::N, true);
00008 Direction Direction::SW(1, 0, Direction::NE, false);
00009 Direction Direction::W(1, -1, Direction::E, true);
00010 Direction Direction::NW(0, -1, Direction::SE, false);
00011 
00012 Direction::Direction(int x, int y, Direction& opposite, bool cardinal) :
00013    _offset(x, y),
00014    _opposite(&opposite),
00015    _cardinal(cardinal)
00016 {
00017 
00018 }
00019 
00020 
00021 Direction::~Direction()
00022 {
00023 }
00024 
00025 vector<const Direction*> Direction::getAllDirections()
00026 {
00027    static vector<const Direction*> directions;
00028    if (directions.empty())
00029    {
00030       directions.push_back(&N);
00031       directions.push_back(&NE);
00032       directions.push_back(&E);
00033       directions.push_back(&SE);
00034       directions.push_back(&S);
00035       directions.push_back(&SW);
00036       directions.push_back(&W);
00037       directions.push_back(&NW);
00038    }
00039 
00040    return directions;
00041 }
00042 
00043 const Point& Direction::offset() const
00044 {
00045    return _offset;
00046 }
00047 
00048 const Direction& Direction::opposite() const
00049 {
00050    return *_opposite;
00051 }
00052 
00053 bool Direction::isCardinal() const
00054 {
00055    return _cardinal;
00056 }
00057 
00058 bool Direction::operator < (const Direction& dir) const
00059 {
00060    if (offset().x < dir.offset().x)
00061    {
00062       return true;
00063    }
00064    else if (offset().x > dir.offset().x)
00065    {
00066       return false;
00067    }
00068    else
00069    {
00070       return (offset().y < dir.offset().y);
00071    }
00072 }
00073 
00074 bool Direction::operator == (const Direction& dir) const
00075 {
00076    return (_offset == dir._offset);
00077 }

Generated on Fri Sep 22 06:00:26 2006 for X-CLONE by  doxygen 1.4.7