- adding getWord and toString methods

This commit is contained in:
Antoine Fraboulet 2005-12-26 15:52:48 +00:00
parent 3c31b8a2e2
commit ce001c7aa2
2 changed files with 42 additions and 0 deletions

View file

@ -18,6 +18,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
#include <string>
#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:

View file

@ -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<Tile> m_word;
vector<char> m_tileOrigin;