Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

LevelNode Class Reference

Inheritance diagram for LevelNode:

Inheritance graph
[legend]
Collaboration diagram for LevelNode:

Collaboration graph
[legend]

Detailed Description

Node on the map.

Definition at line 17 of file LevelNode.h.

Public Types

enum  eState { STATE_HIDDEN, STATE_FAR, STATE_OPEN, STATE_SOLVED }

Public Member Functions

 LevelNode (const std::string &codename, const Path &datafile, const V2 &loc, const std::string &poster="")
 Default state is STATE_FAR.
virtual ~LevelNode ()
 Free self and all children.
void setState (eState state)
 Set state for this node and open his followers.
eState getState () const
void setDepth (int depth)
int getDepth () const
void bestSolution (int moves, const std::string &author)
int getBestMoves () const
std::string getBestAuthor () const
std::string getCodename () const
V2 getLoc () const
std::string getPoster () const
LevelcreateLevel () const
void addChild (LevelNode *new_node)
 Add child node.
LevelNodefindSelected (const V2 &cursor)
 Find selected node under cursor.
LevelNodefindNamed (const std::string &codename)
 Find named node in whole tree.
bool areAllSolved () const
 Returns true when all nodes are solved.
bool isLeaf () const
void drawPath (const NodeDrawer *drawer) const
 Draws self and path to all children.


Member Enumeration Documentation

enum LevelNode::eState
 

Enumeration values:
STATE_HIDDEN 
STATE_FAR 
STATE_OPEN 
STATE_SOLVED 

Definition at line 19 of file LevelNode.h.

00019                     {
00020             STATE_HIDDEN,
00021             STATE_FAR,
00022             STATE_OPEN,
00023             STATE_SOLVED
00024         };


Constructor & Destructor Documentation

LevelNode::LevelNode const std::string &  codename,
const Path datafile,
const V2 loc,
const std::string &  poster = ""
 

Default state is STATE_FAR.

Definition at line 21 of file LevelNode.cpp.

00023 : m_codename(codename), m_poster(poster), m_datafile(datafile), m_loc(loc)
00024 {
00025     m_state = STATE_FAR;
00026     m_depth = 1;
00027     m_bestMoves = -1;
00028 }

LevelNode::~LevelNode  )  [virtual]
 

Free self and all children.

Definition at line 33 of file LevelNode.cpp.

00034 {
00035     t_children::iterator end = m_children.end();
00036     for (t_children::iterator i = m_children.begin(); i != end; ++i) {
00037         delete *i;
00038     }
00039 }


Member Function Documentation

void LevelNode::addChild LevelNode new_node  ) 
 

Add child node.

NOTE: cycles in graph are not supported.

Definition at line 168 of file LevelNode.cpp.

00169 {
00170     m_children.push_back(new_node);
00171 
00172     new_node->setDepth(m_depth + 1);
00173     if (m_state == STATE_SOLVED && new_node->getState() < STATE_OPEN) {
00174         new_node->setState(STATE_OPEN);
00175     }
00176 }

bool LevelNode::areAllSolved  )  const
 

Returns true when all nodes are solved.

Definition at line 143 of file LevelNode.cpp.

00144 {
00145     if (m_state != STATE_SOLVED) {
00146         return false;
00147     }
00148     t_children::const_iterator end = m_children.end();
00149     for (t_children::const_iterator i = m_children.begin(); i != end; ++i) {
00150         if (!(*i)->areAllSolved()) {
00151             return false;
00152         }
00153     }
00154     return true;
00155 }

void LevelNode::bestSolution int  moves,
const std::string &  author
 

Definition at line 70 of file LevelNode.cpp.

00071 {
00072     m_bestMoves = moves;
00073     m_bestAuthor = author;
00074 }

Level * LevelNode::createLevel  )  const
 

Definition at line 158 of file LevelNode.cpp.

00159 {
00160     return new Level(m_codename, m_datafile, m_depth);
00161 }

void LevelNode::drawPath const NodeDrawer drawer  )  const
 

Draws self and path to all children.

Children are drawed recursive.

Definition at line 183 of file LevelNode.cpp.

00184 {
00185     if (m_state > STATE_HIDDEN) {
00186         t_children::const_iterator end = m_children.end();
00187         for (t_children::const_iterator i = m_children.begin();
00188                 i != end; ++i)
00189         {
00190             if ((*i)->getState() > STATE_HIDDEN) {
00191                 drawer->drawEdge(this, *i);
00192                 (*i)->drawPath(drawer);
00193             }
00194         }
00195         drawer->drawNode(this);
00196     }
00197 }

LevelNode * LevelNode::findNamed const std::string &  codename  ) 
 

Find named node in whole tree.

Returns:
named node or NULL

Definition at line 120 of file LevelNode.cpp.

00121 {
00122     if (m_codename == codename) {
00123         return this;
00124     }
00125     else {
00126         t_children::const_iterator end = m_children.end();
00127         for (t_children::const_iterator i = m_children.begin();
00128                 i != end; ++i)
00129         {
00130             LevelNode *named = (*i)->findNamed(codename);
00131             if (named) {
00132                 return named;
00133             }
00134         }
00135     }
00136     return NULL;
00137 }

LevelNode * LevelNode::findSelected const V2 cursor  ) 
 

Find selected node under cursor.

Only solved and open nodes are traversed.

Returns:
selected node or NULL

Definition at line 94 of file LevelNode.cpp.

00095 {
00096     if (m_state >= STATE_OPEN) {
00097         if (isUnder(cursor)) {
00098             return this;
00099         }
00100         else {
00101             t_children::const_iterator end = m_children.end();
00102             for (t_children::const_iterator i = m_children.begin();
00103                     i != end; ++i)
00104             {
00105                 LevelNode *selected = (*i)->findSelected(cursor);
00106                 if (selected) {
00107                     return selected;
00108                 }
00109             }
00110         }
00111     }
00112     return NULL;
00113 }

std::string LevelNode::getBestAuthor  )  const [inline]
 

Definition at line 50 of file LevelNode.h.

00050 { return m_bestAuthor; }

int LevelNode::getBestMoves  )  const [inline]
 

Definition at line 49 of file LevelNode.h.

00049 { return m_bestMoves; }

std::string LevelNode::getCodename  )  const [inline]
 

Definition at line 52 of file LevelNode.h.

00052 { return m_codename; }

int LevelNode::getDepth  )  const [inline]
 

Definition at line 46 of file LevelNode.h.

00046 { return m_depth; }

V2 LevelNode::getLoc  )  const [inline]
 

Definition at line 53 of file LevelNode.h.

00053 { return m_loc; }

std::string LevelNode::getPoster  )  const [inline]
 

Definition at line 54 of file LevelNode.h.

00054 { return m_poster; }

eState LevelNode::getState  )  const [inline]
 

Definition at line 44 of file LevelNode.h.

00044 { return m_state; }

bool LevelNode::isLeaf  )  const [inline]
 

Definition at line 62 of file LevelNode.h.

00062 { return m_children.empty(); }

void LevelNode::setDepth int  depth  )  [inline]
 

Definition at line 45 of file LevelNode.h.

00045 { m_depth = depth; }

void LevelNode::setState eState  state  ) 
 

Set state for this node and open his followers.

Definition at line 45 of file LevelNode.cpp.

00046 {
00047     t_children::iterator end = m_children.end();
00048     switch (state) {
00049         case STATE_HIDDEN:
00050         case STATE_FAR:
00051         case STATE_OPEN:
00052             break;
00053         case STATE_SOLVED:
00054             for (t_children::iterator i = m_children.begin();
00055                     i != end; ++i)
00056             {
00057                 if ((*i)->getState() < STATE_OPEN) {
00058                     (*i)->setState(STATE_OPEN);
00059                 }
00060             }
00061             break;
00062         default:
00063             assert(!"unknown level node state");
00064             break;
00065     }
00066     m_state = state;
00067 }


The documentation for this class was generated from the following files:
Generated on Wed Jun 1 09:55:44 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2