mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2025-02-02 07:57:46 +01:00
PlayModel: new signal to indicate that a move is played.
This allows moving the logic out of PlayWordMediator (it will make it easier to have a different behaviour for different mode types).
This commit is contained in:
parent
6a553bf2f5
commit
686b896396
5 changed files with 85 additions and 56 deletions
|
@ -405,6 +405,8 @@ void MainWindow::updateForGame(PublicGame *iGame)
|
|||
statusBar()->removeWidget(m_lettersLabel);
|
||||
statusBar()->removeWidget(m_turnLabel);
|
||||
|
||||
m_playModel.disconnect(this);
|
||||
|
||||
// Destroy the players widget
|
||||
QtCommon::DestroyObject(m_playersWidget, this);
|
||||
m_playersWidget = NULL;
|
||||
|
@ -435,6 +437,9 @@ void MainWindow::updateForGame(PublicGame *iGame)
|
|||
statusBar()->addWidget(m_turnLabel);
|
||||
m_turnLabel->show();
|
||||
|
||||
QObject::connect(&m_playModel, SIGNAL(movePlayed(const wstring&, const wstring&)),
|
||||
this, SLOT(playWord(const wstring&, const wstring&)));
|
||||
|
||||
if (iGame->getMode() == PublicGame::kTRAINING)
|
||||
{
|
||||
setWindowTitle(_q("Training mode") + " - Eliot");
|
||||
|
@ -711,6 +716,69 @@ void MainWindow::changeDictionary(QString iFileName)
|
|||
}
|
||||
|
||||
|
||||
void MainWindow::playWord(const wstring &iWord, const wstring &iCoord)
|
||||
{
|
||||
ASSERT(m_game != NULL, "No game in progress");
|
||||
|
||||
int res = m_game->play(iWord, iCoord);
|
||||
if (res == 0)
|
||||
{
|
||||
emit gameUpdated();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Try to be as explicit as possible concerning the error
|
||||
QString msg = _q("Cannot play '%1' at position '%2':\n%3")
|
||||
.arg(qfw(iWord)).arg(qfw(iCoord));
|
||||
switch (res)
|
||||
{
|
||||
case 1:
|
||||
msg = msg.arg(_q("Some letters are not valid for the current dictionary"));
|
||||
break;
|
||||
case 2:
|
||||
msg = msg.arg(_q("Invalid coordinates"));
|
||||
break;
|
||||
case 3:
|
||||
msg = msg.arg(_q("The word does not exist"));
|
||||
break;
|
||||
case 4:
|
||||
msg = msg.arg(_q("The rack doesn't contain the letters needed to play this word"));
|
||||
break;
|
||||
case 5:
|
||||
msg = msg.arg(_q("The word is part of a longer one"));
|
||||
break;
|
||||
case 6:
|
||||
msg = msg.arg(_q("The word tries to replace an existing letter"));
|
||||
break;
|
||||
case 7:
|
||||
msg = msg.arg(_q("An orthogonal word is not valid"));
|
||||
break;
|
||||
case 8:
|
||||
msg = msg.arg(_q("The word is already present on the board at these coordinates"));
|
||||
break;
|
||||
case 9:
|
||||
msg = msg.arg(_q("A word cannot be isolated (not connected to the placed words)"));
|
||||
break;
|
||||
case 10:
|
||||
msg = msg.arg(_q("The first word of the game must be horizontal"));
|
||||
break;
|
||||
case 11:
|
||||
msg = msg.arg(_q("The first word of the game must cover the H8 square"));
|
||||
break;
|
||||
case 12:
|
||||
msg = msg.arg(_q("The word is going out of the board"));
|
||||
break;
|
||||
case 13:
|
||||
msg = msg.arg(_q("The word contains too many letters from the rack"));
|
||||
break;
|
||||
default:
|
||||
msg = msg.arg(_q("Incorrect or misplaced word"));
|
||||
}
|
||||
displayErrorMsg(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QAction * MainWindow::addMenuAction(QMenu *menu, QString iText,
|
||||
const QKeySequence &iShortcut,
|
||||
QString iStatusTip, const char *iMember,
|
||||
|
|
|
@ -110,6 +110,9 @@ private slots:
|
|||
/** Load a new dictionary */
|
||||
void changeDictionary(QString);
|
||||
|
||||
/// Play the given word
|
||||
void playWord(const wstring &iWord, const wstring &iCoord);
|
||||
|
||||
/** Perform some updates when the game is updated */
|
||||
void refresh();
|
||||
|
||||
|
|
|
@ -67,3 +67,11 @@ void PlayModel::setMove(const Move &iMove)
|
|||
emit moveChanged(iMove, m_prevMove);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PlayModel::playWord(const wstring &iWord, const wstring &iCoord)
|
||||
{
|
||||
emit movePlayed(iWord, iCoord);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -62,9 +62,14 @@ public:
|
|||
void setMove(const Move &iMove);
|
||||
const Move &getMove() const { return m_currMove; }
|
||||
|
||||
// FIXME: should probably take no argument, and use the current move instead
|
||||
void playWord(const wstring &iWord, const wstring &iCoord);
|
||||
|
||||
signals:
|
||||
void coordChanged(const Coord &iNewCoord, const Coord &iOldCoord);
|
||||
void moveChanged(const Move &iMove, const Move &iOldMove);
|
||||
// FIXME: should probably use a Move object instead
|
||||
void movePlayed(const wstring &iWord, const wstring &iCoord);
|
||||
|
||||
private:
|
||||
Coord m_currCoord;
|
||||
|
|
|
@ -156,62 +156,7 @@ void PlayWordMediator::playWord()
|
|||
|
||||
const wstring &word = getWord();
|
||||
QString coords = m_lineEditCoord.text();
|
||||
int res = m_game->play(word, wfq(coords));
|
||||
if (res == 0)
|
||||
{
|
||||
emit gameUpdated();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Try to be as explicit as possible concerning the error
|
||||
QString msg = _q("Cannot play '%1' at position '%2':\n%3")
|
||||
.arg(m_lineEditPlay.text()).arg(coords);
|
||||
switch (res)
|
||||
{
|
||||
case 1:
|
||||
msg = msg.arg(_q("Some letters are not valid for the current dictionary"));
|
||||
break;
|
||||
case 2:
|
||||
msg = msg.arg(_q("Invalid coordinates"));
|
||||
break;
|
||||
case 3:
|
||||
msg = msg.arg(_q("The word does not exist"));
|
||||
break;
|
||||
case 4:
|
||||
msg = msg.arg(_q("The rack doesn't contain the letters needed to play this word"));
|
||||
break;
|
||||
case 5:
|
||||
msg = msg.arg(_q("The word is part of a longer one"));
|
||||
break;
|
||||
case 6:
|
||||
msg = msg.arg(_q("The word tries to replace an existing letter"));
|
||||
break;
|
||||
case 7:
|
||||
msg = msg.arg(_q("An orthogonal word is not valid"));
|
||||
break;
|
||||
case 8:
|
||||
msg = msg.arg(_q("The word is already present on the board at these coordinates"));
|
||||
break;
|
||||
case 9:
|
||||
msg = msg.arg(_q("A word cannot be isolated (not connected to the placed words)"));
|
||||
break;
|
||||
case 10:
|
||||
msg = msg.arg(_q("The first word of the game must be horizontal"));
|
||||
break;
|
||||
case 11:
|
||||
msg = msg.arg(_q("The first word of the game must cover the H8 square"));
|
||||
break;
|
||||
case 12:
|
||||
msg = msg.arg(_q("The word is going out of the board"));
|
||||
break;
|
||||
case 13:
|
||||
msg = msg.arg(_q("The word contains too many letters from the rack"));
|
||||
break;
|
||||
default:
|
||||
msg = msg.arg(_q("Incorrect or misplaced word"));
|
||||
}
|
||||
emit notifyProblem(msg);
|
||||
}
|
||||
m_playModel.playWord(word, wfq(coords));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue