Wt examples
3.3.0
Main Page
Modules
Namespaces
Classes
Files
File List
File Members
build
buildd
witty-3.3.0
examples
hangman
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
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
}
Generated on Fri May 31 2013 for
the C++ Web Toolkit (Wt)
by
1.8.3.1