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

Diff of /eliot/game/history.cpp

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

revision 1.2.2.1 by afrab, Sun Oct 23 17:16:24 2005 UTC revision 1.2.2.2 by ipkiss, Sun Oct 23 20:58:20 2005 UTC
# Line 17  Line 17 
17  /* along with this program; if not, write to the Free Software               */  /* along with this program; if not, write to the Free Software               */
18  /* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */  /* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
19    
 /* $Id$ */  
   
20  /**  /**
21   *  \file   history.cpp   *  \file   history.cpp
22   *  \brief  Game history  system   *  \brief  Game history  system
# Line 29  Line 27 
27  #include <string>  #include <string>
28  #include "rack.h"  #include "rack.h"
29  #include "history.h"  #include "history.h"
30    #include "turn.h"
31  #include "debug.h"  #include "debug.h"
32    
33  /* ******************************************************** */  /* ******************************************************** */
# Line 39  Line 38 
38  History::History()  History::History()
39  {  {
40      Turn* t = new Turn ();      Turn* t = new Turn ();
41      history.push_back(t);      m_history.push_back(t);
42  }  }
43    
44    
45  History::~History()  History::~History()
46  {  {
47      for (unsigned int i = 0; i < history.size(); i++)      for (unsigned int i = 0; i < m_history.size(); i++)
48          {      {
49              if (history[i] != NULL)          if (m_history[i] != NULL)
50                  {          {
51                      delete history[i];              delete m_history[i];
52                      history[i] = NULL;              m_history[i] = NULL;
53                  }          }
54          }      }
55  }  }
56    
57    
58  int History::getSize() const  int History::getSize() const
59  {  {
60      return history.size();      return m_history.size();
61  }  }
62    
63    
64  const PlayedRack History::getCurrentRack() const  const PlayedRack& History::getCurrentRack() const
65  {  {
66      return history.back()->getPlayedRack();      return m_history.back()->getPlayedRack();
67  }  }
68    
69    
70  void History::setCurrentRack(const PlayedRack &iPld)  void History::setCurrentRack(const PlayedRack &iPld)
71  {  {
72      history.back()->setPlayedRack(iPld);      m_history.back()->setPlayedRack(iPld);
73  }  }
74    
75    
76  const Turn History::getPreviousTurn() const  const Turn& History::getPreviousTurn() const
77  {  {
78      int idx = history.size() - 2;      int idx = m_history.size() - 2;
79      ASSERT(0 <= idx , "Wrong turn number");      ASSERT(0 <= idx , "Wrong turn number");
80      return *(history[ idx ]);      return *(m_history[idx]);
81  }  }
82    
83    
84  const Turn History::getTurn(unsigned int n) const  const Turn& History::getTurn(unsigned int n) const
85  {  {
86      ASSERT(0 <= n && n < history.size(), "Wrong turn number");      ASSERT(0 <= n && n < m_history.size(), "Wrong turn number");
87      return *(history[ n ]);      return *(m_history[n]);
88  }  }
89    
90    
# Line 93  void History::playRound(int player, int Line 92  void History::playRound(int player, int
92  {  {
93      Rack rack;      Rack rack;
94      Turn * current_turn;      Turn * current_turn;
95        
96      current_turn = history.back();      current_turn = m_history.back();
97    
98      /* set the number and the round */      /* set the number and the round */
99      current_turn->setNum(turn);      current_turn->setNum(turn);
# Line 121  void History::playRound(int player, int Line 120  void History::playRound(int player, int
120      PlayedRack pldrack;      PlayedRack pldrack;
121      pldrack.setOld(rack);      pldrack.setOld(rack);
122      next_turn->setPlayedRack(pldrack);      next_turn->setPlayedRack(pldrack);
123      history.push_back ( next_turn );      m_history.push_back(next_turn);
124  }  }
125    
126    
127  void History::removeLastTurn()  void History::removeLastTurn()
128  {  {
129      int idx = history.size();      int idx = m_history.size();
130      ASSERT(0 < idx , "Wrong turn number");      ASSERT(0 < idx , "Wrong turn number");
131        
132      if (idx > 1)      if (idx > 1)
133          {      {
134              Turn *t = history.back();          Turn *t = m_history.back();
135              history.pop_back();          m_history.pop_back();
136              delete t;          delete t;
137          }      }
138    
139      // now we have the previous played round in back()      // now we have the previous played round in back()
140      Turn* t = history.back();      Turn* t = m_history.back();
141      t->setNum(0);      t->setNum(0);
142      t->setPlayer(0);      t->setPlayer(0);
143      t->setRound(Round());      t->setRound(Round());
# Line 148  void History::removeLastTurn() Line 147  void History::removeLastTurn()
147  }  }
148    
149    
150  std::string  std::string History::toString() const
 History::toString() const  
151  {  {
     char buff[20];  
152      unsigned int i;      unsigned int i;
153      std::string rs("");      std::string rs = "";
154  #ifdef DEBUG  #ifdef DEBUG
155      sprintf(buff,"%d",history.size());      char buff[20];
156      rs = "hitory size = " + std::string(buff) + "\n\n";      sprintf(buff,"%d",m_history.size());
157        rs = "history size = " + std::string(buff) + "\n\n";
158  #endif  #endif
159      for ( i = 0; i < history.size(); i++)      for (i = 0; i < m_history.size(); i++)
160          {      {
161              Turn *t = history[i];          Turn *t = m_history[i];
162              rs += t->toString() + std::string("\n");          rs += t->toString() + std::string("\n");
163          }      }
164      return rs;      return rs;
165  }  }
166    
# Line 170  History::toString() const Line 168  History::toString() const
168  /* ******************************************************** */  /* ******************************************************** */
169  /* ******************************************************** */  /* ******************************************************** */
170    
171    
172  /// Local Variables:  /// Local Variables:
173  /// mode: hs-minor  /// mode: hs-minor
174  /// c-basic-offset: 4  /// c-basic-offset: 4

Legend:
Removed from v.1.2.2.1  
changed lines
  Added in v.1.2.2.2

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