/[eliot]/eliot/game/coord.cpp
ViewVC logotype

Diff of /eliot/game/coord.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by ipkiss, Sat Nov 5 11:01:58 2005 UTC revision 1.6 by ipkiss, Sat Nov 5 13:56:59 2005 UTC
# Line 26  Line 26 
26    
27  #include <string>  #include <string>
28  #include "coord.h"  #include "coord.h"
29    #include "board.h" // for BOARD_MIN and BOARD_MAX (TODO: remove this include)
30    
31    
32  Coord::Coord()  Coord::Coord(int iRow, int iCol, Direction iDir)
33  {  {
34      m_row = 1;      m_row = iRow;
35      m_col = 1;      m_col = iCol;
36      m_dir = HORIZONTAL;      m_dir = iDir;
37  }  }
38    
39  Coord::Coord(const string &iStr)  Coord::Coord(const string &iStr)
40  {  {
     m_row = 1;  
     m_col = 1;  
41      setFromString(iStr);      setFromString(iStr);
42  }  }
43    
44  Coord::~Coord()  bool Coord::isValid() const
 {  
 }  
   
 Coord::Direction Coord::getDir() const  
 {  
     return m_dir;  
 }  
   
 int Coord::getRow() const  
 {  
     return m_row;  
 }  
   
 int Coord::getCol() const  
 {  
     return m_col;  
 }  
   
 void Coord::setRow(int iRow)  
 {  
     m_row = iRow;  
 }  
   
 void Coord::setCol(int iCol)  
 {  
     m_col = iCol;  
 }  
   
 void Coord::setDir(Direction iDir)  
45  {  {
46      m_dir = iDir;      return (m_row >= BOARD_MIN && m_row <= BOARD_MAX &&
47                m_col >= BOARD_MIN && m_col <= BOARD_MAX);
48  }  }
49    
50  void Coord::operator=(const Coord &iOther)  void Coord::operator=(const Coord &iOther)
# Line 83  void Coord::operator=(const Coord &iOthe Line 54  void Coord::operator=(const Coord &iOthe
54      m_col = iOther.m_col;      m_col = iOther.m_col;
55  }  }
56    
57    void Coord::swap()
58    {
59        int tmp = m_col;
60        m_col = m_row;
61        m_row = tmp;
62    }
63    
64  void Coord::setFromString(const string &iStr)  void Coord::setFromString(const string &iStr)
65  {  {
66      char l[4];      char l[4];
# Line 98  void Coord::setFromString(const string & Line 76  void Coord::setFromString(const string &
76      }      }
77      else      else
78      {      {
79          col = 1;          col = -1;
80          l[0] = 'A';          l[0] = 'A' - 1;
81      }      }
82      int row = toupper(*l) - 'A' + 1;      int row = toupper(*l) - 'A' + 1;
83      setCol(col);      setCol(col);
# Line 109  void Coord::setFromString(const string & Line 87  void Coord::setFromString(const string &
87  string Coord::toString() const  string Coord::toString() const
88  {  {
89      string rs;      string rs;
90    
91        char s[5];
92        sprintf(s, "%d", m_col);
93      if (getDir() == HORIZONTAL)      if (getDir() == HORIZONTAL)
94      {      {
         char s[5];  
         sprintf(s, "%d", m_col);  
95          rs = string(1, m_row + 'A' - 1) + s;          rs = string(1, m_row + 'A' - 1) + s;
96      }      }
97      else      else
98      {      {
         char s[5];  
         sprintf(s, "%d", m_col);  
99          rs = s + string(1, m_row + 'A' - 1);          rs = s + string(1, m_row + 'A' - 1);
100      }      }
101      return rs;      return rs;

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26