2005-02-05 12:14:56 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* Copyright (C) 1999-2005 Eliot
|
|
|
|
* Authors: Antoine Fraboulet <antoine.fraboulet@free.fr>
|
|
|
|
* Olivier Teuliere <ipkiss@via.ecp.fr>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-23 16:53:42 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2005-02-05 12:14:56 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "tile.h"
|
|
|
|
#include "round.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define FROMBOARD 0x1
|
|
|
|
#define FROMRACK 0x2
|
|
|
|
#define JOKER 0x4
|
|
|
|
|
|
|
|
|
|
|
|
Round::Round()
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Round::init()
|
|
|
|
{
|
|
|
|
m_word.clear();
|
|
|
|
m_tileOrigin.clear();
|
2005-11-05 14:56:59 +01:00
|
|
|
m_coord.setRow(-1);
|
|
|
|
m_coord.setCol(-1);
|
2005-11-05 12:01:58 +01:00
|
|
|
m_coord.setDir(Coord::HORIZONTAL);
|
2005-02-05 12:14:56 +01:00
|
|
|
m_points = 0;
|
|
|
|
m_bonus = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Round::setWord(const vector<Tile> &iTiles)
|
|
|
|
{
|
|
|
|
m_word.clear();
|
|
|
|
|
|
|
|
vector<Tile>::const_iterator it;
|
|
|
|
for (it = iTiles.begin(); it != iTiles.end(); it++)
|
|
|
|
{
|
|
|
|
m_word.push_back(*it);
|
|
|
|
// XXX: always from rack?
|
|
|
|
m_tileOrigin.push_back(FROMRACK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Round::setFromRack(int iIndex)
|
|
|
|
{
|
|
|
|
m_tileOrigin[iIndex] &= ~FROMBOARD;
|
|
|
|
m_tileOrigin[iIndex] |= FROMRACK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Round::setFromBoard(int iIndex)
|
|
|
|
{
|
|
|
|
m_tileOrigin[iIndex] &= ~FROMRACK;
|
|
|
|
m_tileOrigin[iIndex] |= FROMBOARD;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-29 00:07:22 +02:00
|
|
|
void Round::setJoker(int iIndex, bool value)
|
2005-02-05 12:14:56 +01:00
|
|
|
{
|
2005-03-29 00:07:22 +02:00
|
|
|
if (value)
|
|
|
|
m_tileOrigin[iIndex] |= JOKER;
|
|
|
|
else
|
|
|
|
m_tileOrigin[iIndex] &= ~JOKER;
|
2005-02-05 12:14:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Round::isJoker(int iIndex) const
|
|
|
|
{
|
|
|
|
return m_tileOrigin[iIndex] & JOKER;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const Tile& Round::getTile(int iIndex) const
|
|
|
|
{
|
|
|
|
return m_word[iIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Round::getWordLen() const
|
|
|
|
{
|
|
|
|
return m_word.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Round::isPlayedFromRack(int iIndex) const
|
|
|
|
{
|
|
|
|
return m_tileOrigin[iIndex] & FROMRACK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Round::addRightFromBoard(Tile c)
|
|
|
|
{
|
|
|
|
m_word.push_back(c);
|
|
|
|
m_tileOrigin.push_back(FROMBOARD);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Round::removeRightToBoard(Tile c)
|
|
|
|
{
|
|
|
|
// c is unused.
|
|
|
|
m_word.pop_back();
|
|
|
|
m_tileOrigin.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Round::addRightFromRack(Tile c, bool iJoker)
|
|
|
|
{
|
|
|
|
m_word.push_back(c);
|
|
|
|
char origin = FROMRACK;
|
|
|
|
if (iJoker)
|
|
|
|
{
|
|
|
|
origin |= JOKER;
|
|
|
|
}
|
|
|
|
m_tileOrigin.push_back(origin);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Round::removeRightToRack(Tile c, bool iJoker)
|
|
|
|
{
|
|
|
|
// c is unused.
|
|
|
|
m_word.pop_back();
|
|
|
|
m_tileOrigin.pop_back();
|
|
|
|
}
|
|
|
|
|