Wt examples
3.2.3
|
#include <WordWidget.h>
Public Member Functions | |
WordWidget (Wt::WContainerWidget *parent=0) | |
std::wstring | word () const |
void | init (const std::wstring &word) |
bool | guess (wchar_t c) |
bool | won () |
Private Attributes | |
std::vector< Wt::WText * > | wordLetters_ |
std::wstring | word_ |
unsigned | displayedLetters_ |
Definition at line 13 of file WordWidget.h.
WordWidget::WordWidget | ( | Wt::WContainerWidget * | parent = 0 | ) |
Definition at line 13 of file WordWidget.C.
: WContainerWidget(parent) { addStyleClass("wordcontainer"); }
bool WordWidget::guess | ( | wchar_t | c | ) |
Definition at line 32 of file WordWidget.C.
{ bool correct = false; for(unsigned int i = 0; i < word_.size(); ++i) { if(word_[i] == c) { displayedLetters_++; wordLetters_[i]->setText(std::wstring(1, c)); correct = true; } } return correct; }
void WordWidget::init | ( | const std::wstring & | word | ) |
Definition at line 19 of file WordWidget.C.
{ word_ = word; displayedLetters_ = 0; clear(); wordLetters_.clear(); for(unsigned int i = 0; i < word_.size(); ++i) { WText *c = new WText("-", this); wordLetters_.push_back(c); } }
bool WordWidget::won | ( | ) |
Definition at line 47 of file WordWidget.C.
{ return displayedLetters_ == word_.size(); }
std::wstring WordWidget::word | ( | ) | const [inline] |
Definition at line 18 of file WordWidget.h.
{ return word_; }
unsigned WordWidget::displayedLetters_ [private] |
Definition at line 29 of file WordWidget.h.
std::wstring WordWidget::word_ [private] |
Definition at line 27 of file WordWidget.h.
std::vector<Wt::WText *> WordWidget::wordLetters_ [private] |
Definition at line 26 of file WordWidget.h.