From ce001c7aa211d5f51dbab89f2144f041d001193a Mon Sep 17 00:00:00 2001 From: Antoine Fraboulet Date: Mon, 26 Dec 2005 15:52:48 +0000 Subject: [PATCH] - adding getWord and toString methods --- game/round.cpp | 38 ++++++++++++++++++++++++++++++++++++++ game/round.h | 4 ++++ 2 files changed, 42 insertions(+) diff --git a/game/round.cpp b/game/round.cpp index bfda3fd..334cbcf 100644 --- a/game/round.cpp +++ b/game/round.cpp @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *****************************************************************************/ +#include #include "tile.h" #include "round.h" @@ -140,3 +141,40 @@ void Round::removeRightToRack(Tile c, bool iJoker) m_tileOrigin.pop_back(); } +string Round::getWord() const +{ + char c; + std::string s; + + for (int i = 0; i < getWordLen(); i++) + { + c = getTile(i).toChar(); + if (isJoker(i)) + c = tolower(c); + s += c; + } + return s; +} + +string Round::toString() const +{ + char buff[5]; + string rs(" "); + + if (getWord().size() > 0) + { + rs = getWord(); + rs += string(16 - getWord().size(), ' '); + rs += getBonus() ? '*' : ' '; + sprintf(buff,"%4d",getPoints()); + rs += buff; + rs += " " + getCoord().toString(); + } + + return rs; +} + +/// Local Variables: +/// mode: hs-minor +/// c-basic-offset: 4 +/// End: diff --git a/game/round.h b/game/round.h index 96fc3fc..de6e495 100644 --- a/game/round.h +++ b/game/round.h @@ -70,6 +70,8 @@ public: bool isJoker (int iIndex) const; bool isPlayedFromRack(int iIndex) const; const Tile& getTile (int iIndex) const; + + string getWord() const; int getWordLen() const; int getPoints() const { return m_points; } int getBonus() const { return m_bonus; } @@ -80,6 +82,8 @@ public: const Coord& getCoord() const { return m_coord; } Coord& accessCoord() { return m_coord; } + std::string toString() const; + private: vector m_word; vector m_tileOrigin;