Wt examples  3.2.0
Public Member Functions | Private Member Functions | Private Attributes
HangmanWidget Class Reference

#include <HangmanWidget.h>

Inheritance diagram for HangmanWidget:
Inheritance graph
[legend]

List of all members.

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::WTexttitle_
WordWidgetword_
ImagesWidgetimages_
LettersWidgetletters_
Wt::WTextstatusText_
Wt::WComboBoxlanguage_
Wt::WPushButtonnewGameButton_
Wt::Signal< int > updateScore_
std::string name_
Dictionary dictionary_

Detailed Description

Definition at line 22 of file HangmanWidget.h.


Constructor & Destructor Documentation

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();
}

Member Function Documentation

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_; }

Member Data Documentation

Definition at line 44 of file HangmanWidget.h.

Definition at line 34 of file HangmanWidget.h.

Definition at line 38 of file HangmanWidget.h.

Definition at line 35 of file HangmanWidget.h.

std::string HangmanWidget::name_ [private]

Definition at line 43 of file HangmanWidget.h.

Definition at line 39 of file HangmanWidget.h.

Definition at line 37 of file HangmanWidget.h.

Definition at line 31 of file HangmanWidget.h.

Definition at line 41 of file HangmanWidget.h.

Definition at line 33 of file HangmanWidget.h.


The documentation for this class was generated from the following files:

Generated on Tue Nov 29 2011 for the C++ Web Toolkit (Wt) by doxygen 1.7.5.1