Rack: rename a member variable

This commit is contained in:
Olivier Teulière 2013-01-17 17:52:42 +01:00
parent a13f7d2968
commit ac3cc02be4
2 changed files with 13 additions and 13 deletions

View file

@ -29,7 +29,7 @@ INIT_LOGGER(game, Rack);
Rack::Rack()
: m_tiles(Dictionary::GetDic().getTileNumber() + 1, 0), m_ntiles(0)
: m_tiles(Dictionary::GetDic().getTileNumber() + 1, 0), m_nbTiles(0)
{
}
@ -39,24 +39,24 @@ void Rack::remove(const Tile &t)
ASSERT(in(t),
"The rack does not contain the letter " + lfw(t.getDisplayStr()));
m_tiles[t.toCode()]--;
m_ntiles--;
m_nbTiles--;
}
void Rack::clear()
{
for (unsigned int i = 0; i < m_tiles.size(); i++)
for (unsigned i = 0; i < m_tiles.size(); i++)
{
m_tiles[i] = 0;
}
m_ntiles = 0;
m_nbTiles = 0;
}
void Rack::getTiles(vector<Tile> &oTiles) const
{
oTiles.reserve(m_ntiles);
for (unsigned int i = 1; i < m_tiles.size(); i++)
oTiles.reserve(m_nbTiles);
for (unsigned i = 1; i < m_tiles.size(); i++)
{
// Add m_tiles[i] copies of the tile at the end of the vector
oTiles.insert(oTiles.end(), m_tiles[i], Dictionary::GetDic().getTileFromCode(i));
@ -67,11 +67,11 @@ void Rack::getTiles(vector<Tile> &oTiles) const
wstring Rack::toString() const
{
wstring rs;
for (unsigned int i = 1; i < m_tiles.size(); i++)
for (unsigned i = 1; i < m_tiles.size(); i++)
{
// Append m_tiles[i] copies of the char
const wstring &chr = Dictionary::GetDic().getTileFromCode(i).getDisplayStr();
for (unsigned int j = 0; j < m_tiles[i]; ++j)
for (unsigned j = 0; j < m_tiles[i]; ++j)
{
rs += chr;
}
@ -83,7 +83,7 @@ wstring Rack::toString() const
bool Rack::operator==(const Rack &iOther) const
{
return m_tiles == iOther.m_tiles
&& m_ntiles == iOther.m_ntiles;
&& m_nbTiles == iOther.m_nbTiles;
}

View file

@ -41,11 +41,11 @@ class Rack
public:
Rack();
unsigned int getNbTiles() const { return m_ntiles; }
unsigned getNbTiles() const { return m_nbTiles; }
bool isEmpty() const { return getNbTiles() == 0; }
unsigned int in(const Tile &t) const { return m_tiles[t.toCode()]; }
void add(const Tile &t) { m_tiles[t.toCode()]++; m_ntiles++; }
unsigned in(const Tile &t) const { return m_tiles[t.toCode()]; }
void add(const Tile &t) { m_tiles[t.toCode()]++; m_nbTiles++; }
void remove(const Tile &t);
void clear();
void getTiles(vector<Tile> &oTiles) const;
@ -57,7 +57,7 @@ public:
private:
/// Vector indexed by tile codes, containing the number of tiles
vector<unsigned int> m_tiles;
unsigned int m_ntiles;
unsigned m_nbTiles;
};
#endif