mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2025-01-29 20:34:56 +01:00
- adding getWord and toString methods
This commit is contained in:
parent
3c31b8a2e2
commit
ce001c7aa2
2 changed files with 42 additions and 0 deletions
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue