20 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
21 |
*****************************************************************************/ |
*****************************************************************************/ |
22 |
|
|
23 |
|
#include <string> |
24 |
|
|
25 |
#include "tile.h" |
#include "tile.h" |
26 |
|
#include "coord.h" |
27 |
#include "round.h" |
#include "round.h" |
28 |
|
|
29 |
|
|
42 |
{ |
{ |
43 |
m_word.clear(); |
m_word.clear(); |
44 |
m_tileOrigin.clear(); |
m_tileOrigin.clear(); |
45 |
m_row = 1; |
m_coord = Coord(); |
|
m_col = 1; |
|
|
m_dir = HORIZONTAL; |
|
46 |
m_points = 0; |
m_points = 0; |
47 |
m_bonus = 0; |
m_bonus = 0; |
48 |
} |
} |
49 |
|
|
50 |
|
void Round::setWord(const std::string &iWord) |
51 |
|
{ |
52 |
|
unsigned int i; |
53 |
|
std::vector<Tile> tiles; |
54 |
|
|
55 |
void Round::setWord(const vector<Tile> &iTiles) |
for (i = 0; i < iWord.size(); i++) |
56 |
|
{ |
57 |
|
tiles.push_back(Tile(iWord[i])); |
58 |
|
} |
59 |
|
setWord(tiles); |
60 |
|
for (i = 0; i < iWord.size(); i++) |
61 |
|
{ |
62 |
|
if (islower(iWord[i])) |
63 |
|
setJoker(i); |
64 |
|
} |
65 |
|
} |
66 |
|
|
67 |
|
void Round::setWord(const std::vector<Tile> &iTiles) |
68 |
{ |
{ |
69 |
m_word.clear(); |
m_word.clear(); |
70 |
|
std::vector<Tile>::const_iterator it; |
|
vector<Tile>::const_iterator it; |
|
71 |
for (it = iTiles.begin(); it != iTiles.end(); it++) |
for (it = iTiles.begin(); it != iTiles.end(); it++) |
72 |
{ |
{ |
73 |
m_word.push_back(*it); |
m_word.push_back(*it); |
112 |
} |
} |
113 |
|
|
114 |
|
|
115 |
|
std::string Round::getWord() const |
116 |
|
{ |
117 |
|
char c; |
118 |
|
std::string s; |
119 |
|
|
120 |
|
for (int i = 0; i < getWordLen(); i++) |
121 |
|
{ |
122 |
|
c = getTile(i).toChar(); |
123 |
|
if (isJoker(i)) |
124 |
|
c = tolower(c); |
125 |
|
s += c; |
126 |
|
} |
127 |
|
return s; |
128 |
|
} |
129 |
|
|
130 |
int Round::getWordLen() const |
int Round::getWordLen() const |
131 |
{ |
{ |
132 |
return m_word.size(); |
return m_word.size(); |
173 |
m_tileOrigin.pop_back(); |
m_tileOrigin.pop_back(); |
174 |
} |
} |
175 |
|
|
176 |
|
|
177 |
|
void Round::operator=(const Round &iOther) |
178 |
|
{ |
179 |
|
m_word = iOther.m_word; |
180 |
|
m_tileOrigin = iOther.m_tileOrigin; |
181 |
|
m_coord = iOther.m_coord; |
182 |
|
m_points = iOther.m_points; |
183 |
|
m_bonus = iOther.m_bonus; |
184 |
|
} |
185 |
|
|
186 |
|
|
187 |
|
std::string Round::toString() const |
188 |
|
{ |
189 |
|
char buff[5]; |
190 |
|
std::string rs(" "); |
191 |
|
|
192 |
|
if (getWord().size() > 0) |
193 |
|
{ |
194 |
|
rs = getWord(); |
195 |
|
rs += std::string(16 - getWord().size(), ' '); |
196 |
|
rs += getBonus() ? '*' : ' '; |
197 |
|
sprintf(buff,"%4d",getPoints()); |
198 |
|
rs += buff; |
199 |
|
rs += " " + getCoord().toString(); |
200 |
|
} |
201 |
|
|
202 |
|
return rs; |
203 |
|
} |
204 |
|
|
205 |
|
|
206 |
|
/// Local Variables: |
207 |
|
/// mode: hs-minor |
208 |
|
/// c-basic-offset: 4 |
209 |
|
/// End: |