[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Eliot-dev] eliot/game history.h history.cpp
From: |
eliot-dev |
Subject: |
[Eliot-dev] eliot/game history.h history.cpp |
Date: |
Mon, 26 Dec 2005 15:33:15 +0000 |
CVSROOT: /cvsroot/eliot
Module name: eliot
Branch:
Changes by: Antoine Fraboulet <address@hidden> 05/12/26 15:33:15
Modified files:
game : history.h history.cpp
Log message:
- backport modifications from branch
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/eliot/game/history.h.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/eliot/eliot/game/history.cpp.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
Patches:
Index: eliot/game/history.cpp
diff -u eliot/game/history.cpp:1.3 eliot/game/history.cpp:1.4
--- eliot/game/history.cpp:1.3 Fri Nov 4 20:00:06 2005
+++ eliot/game/history.cpp Mon Dec 26 15:33:15 2005
@@ -27,6 +27,7 @@
#include <string>
#include "rack.h"
#include "history.h"
+#include "turn.h"
#include "debug.h"
/* ******************************************************** */
@@ -37,51 +38,53 @@
History::History()
{
Turn* t = new Turn ();
- history.push_back(t);
+ m_history.push_back(t);
}
History::~History()
{
- for (unsigned int i = 0; i < history.size(); i++)
- {
- if (history[i] != NULL)
- {
- delete history[i];
- history[i] = NULL;
- }
- }
+ for (unsigned int i = 0; i < m_history.size(); i++)
+ {
+ if (m_history[i] != NULL)
+ {
+ delete m_history[i];
+ m_history[i] = NULL;
+ }
+ }
}
int History::getSize() const
{
- return history.size();
+ return m_history.size();
}
-const PlayedRack History::getCurrentRack() const
+const PlayedRack& History::getCurrentRack() const
{
- return history.back()->getPlayedRack();
+ return m_history.back()->getPlayedRack();
}
void History::setCurrentRack(const PlayedRack &iPld)
{
- history.back()->setPlayedRack(iPld);
+ m_history.back()->setPlayedRack(iPld);
}
-// vector
-// size : number of elements
-// back : last element
-// pop_back : remove at the end
-// push_back : add at the end
-const Turn History::getPreviousTurn() const
+const Turn& History::getPreviousTurn() const
{
- int idx = history.size() - 2;
+ int idx = m_history.size() - 2;
ASSERT(0 <= idx , "Wrong turn number");
- return *(history[ idx ]);
+ return *(m_history[idx]);
+}
+
+
+const Turn& History::getTurn(unsigned int n) const
+{
+ ASSERT(0 <= n && n < m_history.size(), "Wrong turn number");
+ return *(m_history[n]);
}
@@ -89,9 +92,8 @@
{
Rack rack;
Turn * current_turn;
- Turn * next_turn;
- current_turn = history.back();
+ current_turn = m_history.back();
/* set the number and the round */
current_turn->setNum(turn);
@@ -114,26 +116,28 @@
}
/* create a new turn */
- next_turn = new Turn();
- next_turn->getPlayedRack().setOld(rack);
- history.push_back ( next_turn );
+ Turn * next_turn = new Turn();
+ PlayedRack pldrack;
+ pldrack.setOld(rack);
+ next_turn->setPlayedRack(pldrack);
+ m_history.push_back(next_turn);
}
void History::removeLastTurn()
{
- int idx = history.size();
+ int idx = m_history.size();
ASSERT(0 < idx , "Wrong turn number");
if (idx > 1)
- {
- Turn *t = history.back();
- history.pop_back();
- delete t;
- }
+ {
+ Turn *t = m_history.back();
+ m_history.pop_back();
+ delete t;
+ }
// now we have the previous played round in back()
- Turn* t = history.back();
+ Turn* t = m_history.back();
t->setNum(0);
t->setPlayer(0);
t->setRound(Round());
@@ -143,18 +147,20 @@
}
-std::string
-History::toString() const
+std::string History::toString() const
{
- std::string rs = "";
unsigned int i;
- for ( i = 0; i < history.size(); i++)
- {
- string pr,ro;
- pr = history[i]->getPlayedRack().toString();
- ro = history[i]->getRound().toString();
- rs += string(" ") + pr + string(" ") + ro + string("\n");
- }
+ std::string rs = "";
+#ifdef DEBUG
+ char buff[20];
+ sprintf(buff,"%d",m_history.size());
+ rs = "history size = " + std::string(buff) + "\n\n";
+#endif
+ for (i = 0; i < m_history.size(); i++)
+ {
+ Turn *t = m_history[i];
+ rs += t->toString() + std::string("\n");
+ }
return rs;
}
@@ -162,7 +168,7 @@
/* ******************************************************** */
/* ******************************************************** */
-
+
/// Local Variables:
/// mode: hs-minor
/// c-basic-offset: 4
Index: eliot/game/history.h
diff -u eliot/game/history.h:1.3 eliot/game/history.h:1.4
--- eliot/game/history.h:1.3 Fri Nov 4 20:00:06 2005
+++ eliot/game/history.h Mon Dec 26 15:33:15 2005
@@ -28,42 +28,49 @@
#define _HISTORY_H
#include <vector>
-#include "turn.h"
+
+class Turn;
+class PlayedRack;
+class Round;
class History
{
public:
History();
- ~History();
+ virtual ~History();
/// get the size of the history
- int getSize() const;
+ int getSize() const;
/// Get the (possibly incomplete) rack
- const PlayedRack getCurrentRack() const;
+ const PlayedRack& getCurrentRack() const;
/// Set the current rack
- void setCurrentRack(const PlayedRack &iPld);
+ void setCurrentRack(const PlayedRack &iPld);
/// Get the previous turn
- const Turn getPreviousTurn() const;
+ const Turn& getPreviousTurn() const;
+
+ /// Get turn 'n'
+ const Turn& getTurn(unsigned int) const;
- /// Update the "history" with the given round and, complete the turn.
- /// a new turn is created with the remaining letters in the rack
+ /// Update the "history" with the given round and complete the turn.
+ /// A new turn is created with the remaining letters in the rack
void playRound(int player, int turn, const Round& round);
/// Remove last turn
void removeLastTurn();
+ /// String handling
std::string toString() const;
private:
- vector < Turn* > history;
+ std::vector < Turn* > m_history;
};
#endif
-
+
/// Local Variables:
/// mode: hs-minor
/// c-basic-offset: 4
- [Eliot-dev] eliot/game history.h history.cpp,
eliot-dev <=