Wt examples 4.7.2
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.h>
10
11using namespace Wt;
12
14 WContainerWidget()
15{
16 addStyleClass("wordcontainer");
17}
18
19void 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 = this->addWidget(std::make_unique<WText>("-"));
28 wordLetters_.push_back(c);
29 }
30}
31
32bool 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::wstring word() const
Definition: WordWidget.h:20
bool guess(wchar_t c)
Definition: WordWidget.C:32
void init(const std::wstring &word)
Definition: WordWidget.C:19
unsigned displayedLetters_
Definition: WordWidget.h:31
bool won()
Definition: WordWidget.C:47
std::vector< WText * > wordLetters_
Definition: WordWidget.h:28
std::wstring word_
Definition: WordWidget.h:29

Generated on Fri May 13 2022 for the C++ Web Toolkit (Wt) by doxygen 1.9.4