|
Wt examples
3.2.0
|
#include <HangmanWidget.h>

Public Member Functions | |
| HangmanWidget (const std::string &name, Wt::WContainerWidget *parent=0) | |
| Wt::Signal< int > & | updateScore () |
Private Member Functions | |
| void | registerGuess (char c) |
| void | newGame () |
Private Attributes | |
| Wt::WText * | title_ |
| WordWidget * | word_ |
| ImagesWidget * | images_ |
| LettersWidget * | letters_ |
| Wt::WText * | statusText_ |
| Wt::WComboBox * | language_ |
| Wt::WPushButton * | newGameButton_ |
| Wt::Signal< int > | updateScore_ |
| std::string | name_ |
| Dictionary | dictionary_ |
Definition at line 22 of file HangmanWidget.h.
| HangmanWidget::HangmanWidget | ( | const std::string & | name, |
| Wt::WContainerWidget * | parent = 0 |
||
| ) |
Definition at line 22 of file HangmanWidget.C.
: WContainerWidget(parent), name_(name) { WVBoxLayout *layout = new WVBoxLayout(); layout->setContentsMargins(0, 0, 0, 0); this->setLayout(layout); title_ = new WText("<h2>Ready to play ?</h2>"); layout->addWidget(title_, 0, AlignCenter | AlignMiddle); word_ = new WordWidget(); layout->addWidget(word_, 0, AlignCenter | AlignMiddle); statusText_ = new WText(); layout->addWidget(statusText_, 0, AlignCenter | AlignMiddle); images_ = new ImagesWidget(); layout->addWidget(images_, 1, AlignCenter | AlignMiddle); letters_ = new LettersWidget(); layout->addWidget(letters_, 0, AlignCenter | AlignMiddle); letters_->letterPushed().connect(this, &HangmanWidget::registerGuess); language_ = new WComboBox(); language_->addItem("English words (18957 words)"); language_->addItem("Nederlandse woordjes (1688 woorden)"); layout->addWidget(language_, 0, AlignCenter | AlignMiddle); newGameButton_ = new WPushButton("New Game", this); newGameButton_->clicked().connect(this, &HangmanWidget::newGame); layout->addWidget(newGameButton_, 0, AlignCenter | AlignMiddle); letters_->hide(); }
| void HangmanWidget::newGame | ( | ) | [private] |
Definition at line 59 of file HangmanWidget.C.
{
WString title("<h2>Guess the word, {1}!</h2>");
title_->setText(title.arg(name_));
language_->hide();
newGameButton_->hide();
// Bring widget to initial state
Dictionary dictionary = (Dictionary) language_->currentIndex();
word_->init(RandomWord(dictionary));
images_->reset();
letters_->init();
statusText_->setText("");
}
| void HangmanWidget::registerGuess | ( | char | c | ) | [private] |
Definition at line 76 of file HangmanWidget.C.
{
bool correct = word_->guess(c);
if (!correct)
images_->badGuess();
if (images_->gameOver()) {
WString status("You hang... <br />The correct answer was: {1} ");
statusText_->setText(status.arg(word_->word()));
letters_->hide();
language_->show();
newGameButton_->show();
updateScore_.emit(-10);
} else if (word_->won()) {
statusText_->setText("You win!");
images_->hurray();
letters_->hide();
language_->show();
newGameButton_->show();
updateScore_.emit(20 - images_->badGuesses());
}
}
| Wt::Signal<int>& HangmanWidget::updateScore | ( | ) | [inline] |
Definition at line 28 of file HangmanWidget.h.
{ return updateScore_; }
Dictionary HangmanWidget::dictionary_ [private] |
Definition at line 44 of file HangmanWidget.h.
ImagesWidget* HangmanWidget::images_ [private] |
Definition at line 34 of file HangmanWidget.h.
Wt::WComboBox* HangmanWidget::language_ [private] |
Definition at line 38 of file HangmanWidget.h.
LettersWidget* HangmanWidget::letters_ [private] |
Definition at line 35 of file HangmanWidget.h.
std::string HangmanWidget::name_ [private] |
Definition at line 43 of file HangmanWidget.h.
Wt::WPushButton* HangmanWidget::newGameButton_ [private] |
Definition at line 39 of file HangmanWidget.h.
Wt::WText* HangmanWidget::statusText_ [private] |
Definition at line 37 of file HangmanWidget.h.
Wt::WText* HangmanWidget::title_ [private] |
Definition at line 31 of file HangmanWidget.h.
Wt::Signal<int> HangmanWidget::updateScore_ [private] |
Definition at line 41 of file HangmanWidget.h.
WordWidget* HangmanWidget::word_ [private] |
Definition at line 33 of file HangmanWidget.h.
1.7.5.1