Wt examples 3.3.12
WordWidget.C
Go to the documentation of this file.
1/*
2 * Copyright (C) 2011 Emweb bvba, Heverlee, Belgium
3 *
4 * See the LICENSE file for terms of use.
5 */
6
7#include "WordWidget.h"
8
9#include <Wt/WText>
10
11using namespace Wt;
12
14 WContainerWidget(parent)
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 = new WText("-", this);
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:18
bool guess(wchar_t c)
Definition WordWidget.C:32
void init(const std::wstring &word)
Definition WordWidget.C:19
unsigned displayedLetters_
Definition WordWidget.h:29
WordWidget(Wt::WContainerWidget *parent=0)
Definition WordWidget.C:13
std::vector< Wt::WText * > wordLetters_
Definition WordWidget.h:26
bool won()
Definition WordWidget.C:47
std::wstring word_
Definition WordWidget.h:27
virtual void clear()
virtual void addStyleClass(const WString &styleClass, bool force=false)

Generated on Fri May 17 2024 for the C++ Web Toolkit (Wt) by doxygen 1.9.8