Wt examples  3.7.1
WordWidget.C
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 Emweb bv, Herent, Belgium
3  *
4  * See the LICENSE file for terms of use.
5  */
6 
7 #include "WordWidget.h"
8 
9 #include <Wt/WText>
10 
11 using namespace Wt;
12 
14  WContainerWidget(parent)
15 {
16  addStyleClass("wordcontainer");
17 }
18 
19 void WordWidget::init(const std::wstring &word)
20 {
21  word_ = word;
23 
24  clear();
25  wordLetters_.clear();
26  for(unsigned int i = 0; i < word_.size(); ++i) {
27  WText *c = new WText("-", this);
28  wordLetters_.push_back(c);
29  }
30 }
31 
32 bool WordWidget::guess(wchar_t c)
33 {
34  bool correct = false;
35 
36  for(unsigned int i = 0; i < word_.size(); ++i) {
37  if(word_[i] == c) {
39  wordLetters_[i]->setText(std::wstring(1, c));
40  correct = true;
41  }
42  }
43 
44  return correct;
45 }
46 
48 {
49  return displayedLetters_ == word_.size();
50 }
std::vector< Wt::WText * > wordLetters_
Definition: WordWidget.h:26
std::wstring word() const
Definition: WordWidget.h:18
std::wstring word_
Definition: WordWidget.h:27
void init(const std::wstring &word)
Definition: WordWidget.C:19
virtual void addStyleClass(const WString &styleClass, bool force=false) override
virtual void clear()
bool guess(wchar_t c)
Definition: WordWidget.C:32
bool won()
Definition: WordWidget.C:47
unsigned displayedLetters_
Definition: WordWidget.h:29
WordWidget(Wt::WContainerWidget *parent=0)
Definition: WordWidget.C:13

Generated on Tue Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13