Wt examples
3.7.1
public-git
wt
examples
hangman
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
13
WordWidget::WordWidget
(
WContainerWidget
*parent) :
14
WContainerWidget
(parent)
15
{
16
addStyleClass
(
"wordcontainer"
);
17
}
18
19
void
WordWidget::init
(
const
std::wstring &
word
)
20
{
21
word_
=
word
;
22
displayedLetters_
= 0;
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) {
38
displayedLetters_
++;
39
wordLetters_
[i]->setText(std::wstring(1, c));
40
correct =
true
;
41
}
42
}
43
44
return
correct;
45
}
46
47
bool
WordWidget::won
()
48
{
49
return
displayedLetters_
==
word_
.size();
50
}
WordWidget::wordLetters_
std::vector< Wt::WText * > wordLetters_
Definition:
WordWidget.h:26
WordWidget::word
std::wstring word() const
Definition:
WordWidget.h:18
WordWidget::word_
std::wstring word_
Definition:
WordWidget.h:27
Wt::WText
WordWidget::init
void init(const std::wstring &word)
Definition:
WordWidget.C:19
Wt::WWebWidget::addStyleClass
virtual void addStyleClass(const WString &styleClass, bool force=false) override
Wt::WContainerWidget::clear
virtual void clear()
WordWidget.h
WordWidget::guess
bool guess(wchar_t c)
Definition:
WordWidget.C:32
WordWidget::won
bool won()
Definition:
WordWidget.C:47
WordWidget::displayedLetters_
unsigned displayedLetters_
Definition:
WordWidget.h:29
Wt
Wt::WContainerWidget
WordWidget::WordWidget
WordWidget(Wt::WContainerWidget *parent=0)
Definition:
WordWidget.C:13
Generated on Tue Dec 15 2020 for
the C++ Web Toolkit (Wt)
by
1.8.13