Previewing a Round is now possible in all the game types.

It was only possible in Training mode. This change will be useful for
the future arbitration mdoe.
This commit is contained in:
Olivier Teulière 2012-01-12 17:43:57 +01:00
parent 90ce7e1111
commit 482b5d674f
7 changed files with 54 additions and 59 deletions

View file

@ -436,6 +436,18 @@ PlayedRack Game::helperSetRackManual(bool iCheck, const wstring &iLetters) const
return pld;
}
void Game::setTestRound(const Round &iRound)
{
m_board.testRound(iRound);
}
void Game::removeTestRound()
{
m_board.removeTestRound();
}
/*********************************************************
*********************************************************/

View file

@ -194,6 +194,15 @@ public:
Round &oRound,
bool checkRack = true) const;
/**
* Preview the given round on the board.
* It is up to the caller to provide a Round
* which makes sense for the current game.
*/
void setTestRound(const Round &iRound);
/** Remove the round set with setTestRound */
void removeTestRound();
private:
/// Game characteristics
GameParams m_params;

View file

@ -150,6 +150,18 @@ void PublicGame::shuffleRack()
m_game.shuffleRack();
}
void PublicGame::setTestRound(const Round &iRound)
{
m_game.setTestRound(iRound);
}
void PublicGame::removeTestRound()
{
m_game.removeTestRound();
}
/***************************/
static Training & getTrainingGame(Game &iGame)
@ -194,18 +206,6 @@ void PublicGame::trainingSetRackManual(bool iCheck, const wstring &iLetters)
getTrainingGame(m_game).setRackManual(iCheck, iLetters);
}
void PublicGame::trainingTestPlay(unsigned int iResultIndex)
{
getTrainingGame(m_game).testPlay(iResultIndex);
}
void PublicGame::trainingRemoveTestPlay()
{
getTrainingGame(m_game).removeTestPlay();
}
/***************************/
static Duplicate & getDuplicateGame(Game &iGame)

View file

@ -31,6 +31,7 @@ class Board;
class History;
class Player;
class Navigation;
class Round;
class Results;
using namespace std;
@ -155,18 +156,14 @@ public:
*/
int computePoints(const wstring &iWord, const wstring &iCoord) const;
/**
* Go back to turn iTurn.
* We must have: iTurn < getHistory().getSize()
* Possible return values:
* 0: everything went fine
* 1: iTurn is invalid
*/
//int back(unsigned int iTurn);
/// Shuffle the rack of the current player
void shuffleRack();
/// Place a temporary word on the board for preview purposes
void setTestRound(const Round &iRound);
/// Remove the temporary word
void removeTestRound();
/***************
* Training games
* These methods throw an exception if the current game is not in
@ -192,11 +189,6 @@ public:
void trainingSetRackManual(bool iCheck, const wstring &iLetters);
/// Place a temporary word on the board for preview purposes
void trainingTestPlay(unsigned int iResultIndex);
/// Remove the temporary word
void trainingRemoveTestPlay();
/***************
* Duplicate games
* These methods throw an exception if the current game is not in

View file

@ -90,7 +90,7 @@ int Training::play(const wstring &iCoord, const wstring &iWord)
// Perform all the validity checks, and fill a round
Round round;
removeTestPlay();
m_board.removeTestRound();
int res = checkPlayedWord(iCoord, iWord, round);
if (res != 0)
@ -188,16 +188,3 @@ void Training::addPlayer(Player *iPlayer)
Game::addPlayer(iPlayer);
}
void Training::testPlay(unsigned int num)
{
ASSERT(num < m_results.size(), "Wrong result number");
m_board.testRound(m_results.get(num));
}
void Training::removeTestPlay()
{
m_board.removeTestRound();
}

View file

@ -77,22 +77,12 @@ public:
*/
void setRackManual(bool iCheck, const wstring &iLetters);
/*************************
/**
* Override the default behaviour of addPlayer(), because in training
* mode we only want a human player
*************************/
*/
virtual void addPlayer(Player *iPlayer);
/*************************
* Functions to access the current search results
* The int parameter should be 0 <= int < getNResults
*************************/
/// Place a temporary word on the board for preview purposes
void testPlay(unsigned int iResultIndex);
/// Remove the temporary word
void removeTestPlay();
private:
/// Private constructor and destructor to force using the GameFactory class
Training(const GameParams &iParams);

View file

@ -33,6 +33,7 @@
#include "game_exception.h"
#include "player.h"
#include "results.h"
#include "debug.h"
using namespace std;
@ -240,13 +241,17 @@ void TrainingWidget::enablePlayButton(const QItemSelection &iSelected,
void TrainingWidget::showPreview(const QItemSelection &iSelected,
const QItemSelection &)
{
m_game->trainingRemoveTestPlay();
m_game->removeTestRound();
if (!iSelected.indexes().empty())
{
// Use the hidden column to get the result number
const QModelIndex &index =
m_model->index(iSelected.indexes().first().row(), HIDDEN_COLUMN);
m_game->trainingTestPlay(m_model->data(index).toUInt());
unsigned int resNb = m_model->data(index).toUInt();
const Results &results = m_game->trainingGetResults();
ASSERT(resNb < results.size(), "Wrong result number");
m_game->setTestRound(results.get(resNb));
emit gameUpdated();
}
}
@ -275,7 +280,7 @@ void TrainingWidget::lockSizesChanged(bool checked)
void TrainingWidget::on_lineEditRack_textEdited(const QString &iText)
{
// FIXME: first parameter is hardcoded
m_game->trainingRemoveTestPlay();
m_game->removeTestRound();
if (!lineEditRack->hasAcceptableInput())
{
lineEditRack->setPalette(redPalette);
@ -300,7 +305,7 @@ void TrainingWidget::on_lineEditRack_textEdited(const QString &iText)
void TrainingWidget::on_pushButtonRack_clicked()
{
m_game->trainingRemoveTestPlay();
m_game->removeTestRound();
try
{
// FIXME: first parameter is hardcoded
@ -316,7 +321,7 @@ void TrainingWidget::on_pushButtonRack_clicked()
void TrainingWidget::on_pushButtonComplement_clicked()
{
m_game->trainingRemoveTestPlay();
m_game->removeTestRound();
try
{
// FIXME: first parameter is hardcoded
@ -332,7 +337,7 @@ void TrainingWidget::on_pushButtonComplement_clicked()
void TrainingWidget::on_pushButtonSearch_clicked()
{
m_game->trainingRemoveTestPlay();
m_game->removeTestRound();
emit notifyInfo(_q("Searching with rack '%1'...").arg(lineEditRack->text()));
m_game->trainingSearch();
emit notifyInfo(_q("Search done"));
@ -354,7 +359,7 @@ void TrainingWidget::on_treeViewResults_doubleClicked(const QModelIndex &iIndex)
{
if (!iIndex.isValid())
return;
m_game->trainingRemoveTestPlay();
m_game->removeTestRound();
// Use the hidden column to get the result number
const QModelIndex &index = m_model->index(iIndex.row(), HIDDEN_COLUMN);
m_game->trainingPlayResult(m_model->data(index).toUInt());