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, Dictionary dictionary, 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::WPushButtonnewGameButton_
Wt::Signal< int > updateScore_
std::string name_
Dictionary dictionary_

Detailed Description

Definition at line 27 of file HangmanWidget.h.


Constructor & Destructor Documentation

HangmanWidget::HangmanWidget ( const std::string &  name,
Dictionary  dictionary,
Wt::WContainerWidget parent = 0 
)

Definition at line 21 of file HangmanWidget.C.

                                                      :
  WContainerWidget(parent),
  name_(name),
  dictionary_(dictionary)
{
  WVBoxLayout *layout = new WVBoxLayout();
  layout->setContentsMargins(0, 0, 0, 0);
  this->setLayout(layout);
  
  title_ = new WText("<h2>Guess the word!</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);

  newGameButton_ = new WPushButton("New Game", this);
  newGameButton_->clicked().connect(this, &HangmanWidget::newGame);
  layout->addWidget(newGameButton_, 0, AlignCenter | AlignMiddle);

  // prepare for first game
  newGame();
}

Member Function Documentation

void HangmanWidget::newGame (  ) [private]

Definition at line 56 of file HangmanWidget.C.

{
  WString title("<h2>Guess the word, {1}!</h2>");
  title_->setText(title.arg(name_));

  newGameButton_->hide(); // don't let the player chicken out

  // Bring widget to initial state
  word_->init(RandomWord(dictionary_));
  images_->init();
  letters_->init();

  statusText_->setText("");
}
void HangmanWidget::registerGuess ( char  c ) [private]

Definition at line 71 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();
    newGameButton_->show();

    updateScore_.emit(-10);
  } else if (word_->won()) {
    statusText_->setText("You win!");
    images_->hurray();

    letters_->hide();
    newGameButton_->show();

    updateScore_.emit(20 - images_->badGuesses());
  }
}
Wt::Signal<int>& HangmanWidget::updateScore (  ) [inline]

Definition at line 34 of file HangmanWidget.h.

{ return updateScore_; }

Member Data Documentation

Definition at line 49 of file HangmanWidget.h.

Definition at line 40 of file HangmanWidget.h.

Definition at line 41 of file HangmanWidget.h.

std::string HangmanWidget::name_ [private]

Definition at line 48 of file HangmanWidget.h.

Definition at line 44 of file HangmanWidget.h.

Definition at line 43 of file HangmanWidget.h.

Definition at line 37 of file HangmanWidget.h.

Definition at line 46 of file HangmanWidget.h.

Definition at line 39 of file HangmanWidget.h.


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

Generated on Fri Sep 23 2011 for the C++ Web Toolkit (Wt) by doxygen 1.7.2